3 * monoburg.y: yacc input grammer
6 * Dietmar Maurer (dietmar@ximian.com)
8 * (C) 2001 Ximian, Inc.
24 static int yylineno = 0;
25 static int yylinepos = 0;
44 %token <ivalue> INTEGER
51 %type <rule_list> rule_list
56 | START IDENT { start_nonterm ($2); } decls
58 | TERMPREFIX plist decls
59 | rule_list optcost optcode optcfunc {
61 for (tmp = $1; tmp; tmp = tmp->next) {
62 rule_add (tmp->data, $3, $2, $4);
68 rule : IDENT ':' tree { $$ = make_rule ($1, $3); }
71 rule_list : rule { $$ = g_list_append (NULL, $1); }
72 | rule ',' rule_list { $$ = g_list_prepend ($3, $1); }
75 optcode : /* empty */ { $$ = NULL; }
80 | plist IDENT { create_term_prefix ($2);}
84 | tlist IDENT { create_term ($2, -1);}
85 | tlist IDENT '=' INTEGER { create_term ($2, $4); }
88 tree : IDENT { $$ = create_tree ($1, NULL, NULL); }
89 | IDENT '(' tree ')' { $$ = create_tree ($1, $3, NULL); }
90 | IDENT '(' tree ',' tree ')' { $$ = create_tree ($1, $3, $5); }
93 optcost : /* empty */ {$$ = NULL; }
95 | INTEGER { $$ = g_strdup_printf ("%d", $1); }
98 optcfunc : /*empty */ { $$ = NULL; }
99 | COST CODE { $$ = $2; }
103 static char input[2048];
104 static char *next = input;
107 yyerror (char *fmt, ...)
113 fprintf (stderr, "line %d(%d): ", yylineno, yylinepos);
114 vfprintf (stderr, fmt, ap);
115 fprintf(stderr, "\n");
122 static int state = 0;
135 static struct pplist *pp = NULL;
138 getvar (const char *input)
140 char *var = g_strchug (g_strdup (input));
143 for (ptr = var; *ptr && *ptr != '\n'; ++ptr) {
144 if (g_ascii_isspace (*ptr)) {
154 push_if (char *input, gboolean flip)
156 struct pplist *new_pp = g_new (struct pplist, 1);
157 char *var = getvar (input);
159 new_pp->ignore = (g_hash_table_lookup (definedvars, var) == NULL) ^ flip;
162 new_pp->ignore |= (pp ? pp->ignore : 0);
171 yyerror ("%%else without %%if");
173 pp->ignore = !pp->ignore | (pp->next ? pp->next->ignore : 0);
179 struct pplist *prev_pp = pp;
182 yyerror ("%%endif without %%if");
198 if (!fgets (input, sizeof (input), inputfd))
201 ll = (input [0] == '%' && input [1] == '%');
205 if (!ll && input [0] == '%') {
206 if (!strncmp (&input [1], "ifdef", 5)) {
207 push_if (&input [6], FALSE);
211 else if (!strncmp (&input [1], "ifndef", 6)) {
212 push_if (&input [7], TRUE);
216 else if (!strncmp (&input [1], "else", 4)) {
221 else if (!strncmp (&input [1], "endif", 5)) {
227 if (pp && pp->ignore) {
238 fputs (input, outputfd);
249 ll = state != 1 || input[0] == '#';
252 } while (next_state == 2 || ll);
261 fputs (input, outputfd);
262 while (fgets (input, sizeof (input), inputfd))
263 fputs (input, outputfd);
274 if (!(c = nextchar ()))
277 yylinepos = next - input + 1;
283 if (!strncmp (next, "start", 5) && isspace (next[5])) {
288 if (!strncmp (next, "termprefix", 10) && isspace (next[10])) {
293 if (!strncmp (next, "term", 4) && isspace (next[4])) {
304 num = 10*num + (c - '0');
305 } while (isdigit (c = (*next++)));
315 if (!strncmp (next - 1, "cost", 4) && isspace (next[3])) {
320 while (isalpha (*n) || isdigit (*n) || *n == '_')
324 yylval.text = g_strndup (next - 1, l);
331 static char buf [100000];
333 while ((c = *next++) != '"' && c)
337 yylval.text = g_strdup (buf);
344 static char buf [100000];
346 while (d && (c = nextchar ())) {
348 assert (i < sizeof (buf));
351 case '{': d++; break;
352 case '}': d--; break;
358 yylval.text = g_strdup (buf);