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;
39 %token <ivalue> INTEGER
49 | START IDENT { start_nonterm ($2); } decls
51 | TERMPREFIX plist decls
52 | IDENT ':' tree optcost optcode optcfunc { create_rule ($1, $3, $5, $4, $6); } decls
55 optcode : /* empty */ { $$ = NULL; }
60 | plist IDENT { create_term_prefix ($2);}
64 | tlist IDENT { create_term ($2, -1);}
65 | tlist IDENT '=' INTEGER { create_term ($2, $4); }
68 tree : IDENT { $$ = create_tree ($1, NULL, NULL); }
69 | IDENT '(' tree ')' { $$ = create_tree ($1, $3, NULL); }
70 | IDENT '(' tree ',' tree ')' { $$ = create_tree ($1, $3, $5); }
73 optcost : /* empty */ {$$ = NULL; }
75 | INTEGER { $$ = g_strdup_printf ("%d", $1); }
78 optcfunc : /*empty */ { $$ = NULL; }
79 | COST CODE { $$ = $2; }
83 static char input[2048];
84 static char *next = input;
87 yyerror (char *fmt, ...)
93 fprintf (stderr, "line %d(%d): ", yylineno, yylinepos);
94 vfprintf (stderr, fmt, ap);
95 fprintf(stderr, "\n");
102 static int state = 0;
120 if (!fgets (input, sizeof (input), inputfd))
123 ll = (input [0] == '%' && input [1] == '%');
131 fputs (input, outputfd);
142 ll = state != 1 || input[0] == '#';
145 } while (next_state == 2 || ll);
154 fputs (input, outputfd);
155 while (fgets (input, sizeof (input), inputfd))
156 fputs (input, outputfd);
166 if (!(c = nextchar ()))
169 yylinepos = next - input + 1;
175 if (!strncmp (next, "start", 5) && isspace (next[5])) {
180 if (!strncmp (next, "termprefix", 10) && isspace (next[10])) {
185 if (!strncmp (next, "term", 4) && isspace (next[4])) {
196 num = 10*num + (c - '0');
197 } while (isdigit (c = (*next++)));
207 if (!strncmp (next - 1, "cost", 4) && isspace (next[3])) {
212 while (isalpha (*n) || isdigit (*n) || *n == '_')
216 yylval.text = g_strndup (next - 1, l);
223 static char buf [100000];
225 while ((c = *next++) != '"' && c)
229 yylval.text = g_strdup (buf);
236 static char buf [100000];
238 while (d && (c = nextchar ())) {
240 assert (i < sizeof (buf));
243 case '{': d++; break;
244 case '}': d--; break;
250 yylval.text = g_strdup (buf);