Annotation of GNUtools/cc/bi-parser.y, revision 1.1.1.1

1.1       root        1: /* Bytecode definition file parser.
                      2:    Copyright (C) 1993 Free Software Foundation, Inc.
                      3: 
                      4: This file is part of GNU CC.
                      5: 
                      6: GNU CC is free software; you can redistribute it and/or modify
                      7: it under the terms of the GNU General Public License as published by
                      8: the Free Software Foundation; either version 2, or (at your option)
                      9: any later version.
                     10: 
                     11: GNU CC is distributed in the hope that it will be useful,
                     12: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     14: GNU General Public License for more details.
                     15: 
                     16: You should have received a copy of the GNU General Public License
                     17: along with GNU CC; see the file COPYING.  If not, write to
                     18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
                     19: 
                     20: 
                     21: %{
                     22: 
                     23: #include <stdio.h>
                     24: #include "hconfig.h"
                     25: #include "bi-defs.h"
                     26: 
                     27: extern char yytext[];
                     28: extern int yyleng;
                     29: 
                     30: 
                     31: /* Chain of all defs built by the parser. */
                     32: struct def *defs;
                     33: int ndefs;
                     34: 
                     35: static struct node *makenode ();
                     36: static struct variation *makevar ();
                     37: static struct def *makedef ();
                     38: 
                     39: void yyerror ();
                     40: 
                     41: %}
                     42: 
                     43: %union
                     44: {
                     45:   char *string;
                     46:   struct def *def;
                     47:   struct variation *variation;
                     48:   struct node *node;
                     49: }
                     50: 
                     51: %token <string> DEFOP STRING
                     52: %type <string> opt_string
                     53: %type <def> defs def
                     54: %type <variation> variations variation
                     55: %type <node> list items item
                     56: 
                     57: %%
                     58: 
                     59: top: 
                     60:   defs
                     61:     { defs = $1; }
                     62:   ;
                     63: 
                     64: defs:
                     65:   def
                     66:   | defs def
                     67:     { $2->next = $1; $$ = $2; }
                     68:   ;
                     69: 
                     70: def:
                     71:   DEFOP '(' STRING ',' opt_string ',' '(' variations ')' ')'
                     72:     { $$ = makedef ($3, $5, $8); }
                     73:   ;
                     74: 
                     75: variations:
                     76:   variation
                     77:   | variations ',' variation
                     78:     { $3->next = $1; $$ = $3; }
                     79:   ;
                     80: 
                     81: variation:
                     82:   '(' opt_string ')'
                     83:     { $$ = makevar ($2, (struct node *) NULL, (struct node *) NULL, (struct node *) NULL); }
                     84:   | '(' opt_string ',' list ')'
                     85:     { $$ = makevar ($2, $4, (struct node *) NULL, (struct node *) NULL); }
                     86:   | '(' opt_string ',' list ',' list ')'
                     87:     { $$ = makevar ($2, $4, $6, (struct node *) NULL); }
                     88:   | '(' opt_string ',' list ',' list ',' list ')'
                     89:     { $$ = makevar ($2, $4, $6, $8); }
                     90:   ;
                     91: 
                     92: opt_string:
                     93:   /* empty */ { $$ = ""; }
                     94:   | STRING { $$ = $1; }
                     95:   ;
                     96: 
                     97: list:
                     98:   '(' items ')'
                     99:     { $$ = $2; }
                    100:   | /* empty */
                    101:     { $$ = NULL; }
                    102:   ;
                    103: 
                    104: items:
                    105:   item
                    106:   /* Note right recursion. */
                    107:   | item ',' items
                    108:     { $1->next = $3; $$ = $1; }
                    109:   ;
                    110: 
                    111: item:
                    112:   STRING
                    113:     { $$ = makenode ($1); }
                    114:   ;
                    115: 
                    116: %%
                    117: 
                    118: static struct node *
                    119: makenode (s)
                    120:      char *s;
                    121: {
                    122:   struct node *n;
                    123: 
                    124:   n = (struct node *) malloc (sizeof (struct node));
                    125:   n->text = s;
                    126:   n->next = NULL;
                    127:   return n;
                    128: }
                    129: 
                    130: static struct variation *
                    131: makevar (name, inputs, outputs, literals)
                    132:      char *name;
                    133:      struct node *inputs, *outputs, *literals;
                    134: {
                    135:   struct variation *v;
                    136: 
                    137:   v = (struct variation *) malloc (sizeof (struct variation));
                    138:   v->name = name;
                    139:   v->code = ndefs++;
                    140:   v->inputs = inputs;
                    141:   v->outputs = outputs;
                    142:   v->literals = literals;
                    143:   v->next = NULL;
                    144:   return v;
                    145: }
                    146: 
                    147: static struct def *
                    148: makedef (name, template, vars)
                    149:      char *name, *template;
                    150:      struct variation *vars;
                    151: {
                    152:   struct def *d;
                    153: 
                    154:   d = (struct def *) malloc (sizeof (struct def));
                    155:   d->basename = name;
                    156:   d->template = template;
                    157:   d->variations = vars;
                    158:   d->next = NULL;
                    159:   return d;
                    160: }
                    161: 
                    162: void
                    163: yyerror (s)
                    164:      char *s;
                    165: {
                    166:   fprintf (stderr, "syntax error in input\n");
                    167:   exit (FATAL_EXIT_CODE);
                    168: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.