3 * monoburg.y: yacc input grammer
6 * Dietmar Maurer (dietmar@ximian.com)
8 * (C) 2001 Ximian, Inc.
20 static int yylineno = 0;
21 static int yylinepos = 0;
37 %token <ivalue> INTEGER
47 | START IDENT { start_nonterm ($2); } decls
49 | IDENT ':' tree optcost optcode optcfunc { create_rule ($1, $3, $5, $4, $6); } decls
52 optcode : /* empty */ { $$ = NULL }
57 | tlist IDENT { create_term ($2, -1);}
58 | tlist IDENT '=' INTEGER { create_term ($2, $4); }
61 tree : IDENT { $$ = create_tree ($1, NULL, NULL); }
62 | IDENT '(' tree ')' { $$ = create_tree ($1, $3, NULL); }
63 | IDENT '(' tree ',' tree ')' { $$ = create_tree ($1, $3, $5); }
66 optcost : /* empty */ {$$ = NULL; }
68 | INTEGER { $$ = g_strdup_printf ("%d", $1); }
71 optcfunc : /*empty */ { $$ = NULL; }
72 | COST CODE { $$ = $2; }
77 strndup (const char *s, int n)
79 char *ns = malloc (n + 1);
85 static char input[2048];
86 static char *next = input;
89 yyerror (char *fmt, ...)
95 fprintf (stderr, "line %d(%d): ", yylineno, yylinepos);
96 vfprintf (stderr, fmt, ap);
97 fprintf(stderr, "\n");
107 static int state = 0;
115 if (!fgets (input, sizeof (input), inputfd))
118 ll = (input [0] == '%' && input [1] == '%');
126 fputs (input, outputfd);
137 ll = state != 1 || input[0] == '#';
140 } while (next_state == 2 || ll);
149 fputs (input, outputfd);
150 while (fgets (input, sizeof (input), inputfd))
151 fputs (input, outputfd);
161 if (!(c = nextchar ()))
164 yylinepos = next - input + 1;
170 if (!strncmp (next, "start", 5) && isspace (next[5])) {
175 if (!strncmp (next, "term", 4) && isspace (next[4])) {
186 num = 10*num + (c - '0');
187 } while ((c = isdigit (*next++)));
197 if (!strncmp (next - 1, "cost", 4) && isspace (next[3])) {
202 while (isalpha (*n) || isdigit (*n) || (*n == '_'))
206 yylval.text = strndup (next - 1, l);
214 static char buf [100000];
216 while ((c = *next++) != '"' && c)
220 yylval.text = strdup (buf);
227 static char buf [100000];
229 while (d && (c = nextchar ())) {
231 assert (i < sizeof (buf));
234 case '{': d++; break;
235 case '}': d--; break;
241 yylval.text = strdup (buf);