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;
36 %token <ivalue> INTEGER
45 | START IDENT { start_nonterm ($2); } decls
47 | IDENT ':' tree optcost optcode { create_rule ($1, $3, $5, $4); } decls
50 optcode : /* empty */ { $$ = NULL }
55 | tlist IDENT { create_term ($2, -1);}
56 | tlist IDENT '=' INTEGER { create_term ($2, $4); }
59 tree : IDENT { $$ = create_tree ($1, NULL, NULL); }
60 | IDENT '(' tree ')' { $$ = create_tree ($1, $3, NULL); }
61 | IDENT '(' tree ',' tree ')' { $$ = create_tree ($1, $3, $5); }
64 optcost : /* empty */ {$$ = "0"; }
66 | INTEGER { $$ = g_strdup_printf ("%d", $1); }
72 strndup (const char *s, int n)
74 char *ns = malloc (n + 1);
80 static char input[2048];
81 static char *next = input;
84 yyerror (char *fmt, ...)
90 fprintf (stderr, "line %d(%d): ", yylineno, yylinepos);
91 vfprintf (stderr, fmt, ap);
92 fprintf(stderr, "\n");
102 static int state = 0;
110 if (!fgets (input, sizeof (input), inputfd))
113 ll = (input [0] == '%' && input [1] == '%' && isspace (input [2]));
121 fputs (input, stdout);
130 ll = state != 1 || input[0] == '#';
133 } while (next_state == 2 || ll);
142 fputs (input, stdout);
143 while (fgets (input, sizeof (input), inputfd))
144 fputs (input, stdout);
154 if (!(c = nextchar ()))
157 yylinepos = next - input + 1;
163 if (!strncmp (next, "start", 5) && isspace (next[5])) {
168 if (!strncmp (next, "term", 4) && isspace (next[4])) {
179 num = 10*num + (c - '0');
180 } while ((c = isdigit (*next++)));
190 //if (!strncmp (next - 1, "cost", 4) && isspace (next[3])) {
195 while (isalpha (*n) || isdigit (*n) || (*n == '_'))
199 yylval.text = strndup (next - 1, l);
207 static char buf [100000];
209 while ((c = *next++) != '"' && c)
213 yylval.text = strdup (buf);
220 static char buf [100000];
222 while (d && (c = nextchar ())) {
224 assert (i < sizeof (buf));
227 case '{': d++; break;
228 case '}': d--; break;
233 yylval.text = strdup (buf);