3 * monoburg.y: yacc input grammer
6 * Dietmar Maurer (dietmar@ximian.com)
8 * (C) 2001 Ximian, Inc.
21 static int yylineno = 0;
22 static int yylinepos = 0;
38 %token <ivalue> INTEGER
48 | START IDENT { start_nonterm ($2); } decls
50 | IDENT ':' tree optcost optcode optcfunc { create_rule ($1, $3, $5, $4, $6); } decls
53 optcode : /* empty */ { $$ = NULL }
58 | tlist IDENT { create_term ($2, -1);}
59 | tlist IDENT '=' INTEGER { create_term ($2, $4); }
62 tree : IDENT { $$ = create_tree ($1, NULL, NULL); }
63 | IDENT '(' tree ')' { $$ = create_tree ($1, $3, NULL); }
64 | IDENT '(' tree ',' tree ')' { $$ = create_tree ($1, $3, $5); }
67 optcost : /* empty */ {$$ = NULL; }
69 | INTEGER { $$ = g_strdup_printf ("%d", $1); }
72 optcfunc : /*empty */ { $$ = NULL; }
73 | COST CODE { $$ = $2; }
77 static char input[2048];
78 static char *next = input;
81 yyerror (char *fmt, ...)
87 fprintf (stderr, "line %d(%d): ", yylineno, yylinepos);
88 vfprintf (stderr, fmt, ap);
89 fprintf(stderr, "\n");
107 if (!fgets (input, sizeof (input), inputfd))
110 ll = (input [0] == '%' && input [1] == '%');
118 fputs (input, outputfd);
129 ll = state != 1 || input[0] == '#';
132 } while (next_state == 2 || ll);
141 fputs (input, outputfd);
142 while (fgets (input, sizeof (input), inputfd))
143 fputs (input, outputfd);
153 if (!(c = nextchar ()))
156 yylinepos = next - input + 1;
162 if (!strncmp (next, "start", 5) && isspace (next[5])) {
167 if (!strncmp (next, "term", 4) && isspace (next[4])) {
178 num = 10*num + (c - '0');
179 } while ((c = isdigit (*next++)));
189 if (!strncmp (next - 1, "cost", 4) && isspace (next[3])) {
194 while (isalpha (*n) || isdigit (*n) || *n == '_')
198 yylval.text = g_strndup (next - 1, l);
205 static char buf [100000];
207 while ((c = *next++) != '"' && c)
211 yylval.text = g_strdup (buf);
218 static char buf [100000];
220 while (d && (c = nextchar ())) {
222 assert (i < sizeof (buf));
225 case '{': d++; break;
226 case '}': d--; break;
232 yylval.text = g_strdup (buf);