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;
115 static struct pplist *pp = NULL;
118 getvar (const char *input)
120 char *var = g_strchug (g_strdup (input));
123 for (ptr = var; *ptr && *ptr != '\n'; ++ptr) {
124 if (g_ascii_isspace (*ptr)) {
134 push_if (char *input, gboolean flip)
136 struct pplist *new_pp = g_new (struct pplist, 1);
137 char *var = getvar (input);
139 new_pp->ignore = (g_hash_table_lookup (definedvars, var) == NULL) ^ flip;
142 new_pp->ignore |= (pp ? pp->ignore : 0);
151 yyerror ("%%else without %%if");
153 pp->ignore = !pp->ignore | (pp->next ? pp->next->ignore : 0);
159 struct pplist *prev_pp = pp;
162 yyerror ("%%endif without %%if");
178 if (!fgets (input, sizeof (input), inputfd))
181 ll = (input [0] == '%' && input [1] == '%');
185 if (!ll && input [0] == '%') {
186 if (!strncmp (&input [1], "ifdef", 5)) {
187 push_if (&input [6], FALSE);
191 else if (!strncmp (&input [1], "ifndef", 6)) {
192 push_if (&input [7], TRUE);
196 else if (!strncmp (&input [1], "else", 4)) {
201 else if (!strncmp (&input [1], "endif", 5)) {
207 if (pp && pp->ignore) {
218 fputs (input, outputfd);
229 ll = state != 1 || input[0] == '#';
232 } while (next_state == 2 || ll);
241 fputs (input, outputfd);
242 while (fgets (input, sizeof (input), inputfd))
243 fputs (input, outputfd);
253 if (!(c = nextchar ()))
256 yylinepos = next - input + 1;
262 if (!strncmp (next, "start", 5) && isspace (next[5])) {
267 if (!strncmp (next, "termprefix", 10) && isspace (next[10])) {
272 if (!strncmp (next, "term", 4) && isspace (next[4])) {
283 num = 10*num + (c - '0');
284 } while (isdigit (c = (*next++)));
294 if (!strncmp (next - 1, "cost", 4) && isspace (next[3])) {
299 while (isalpha (*n) || isdigit (*n) || *n == '_')
303 yylval.text = g_strndup (next - 1, l);
310 static char buf [100000];
312 while ((c = *next++) != '"' && c)
316 yylval.text = g_strdup (buf);
323 static char buf [100000];
325 while (d && (c = nextchar ())) {
327 assert (i < sizeof (buf));
330 case '{': d++; break;
331 case '}': d--; break;
337 yylval.text = g_strdup (buf);