1
#if defined(__STDC__) || defined(__cplusplus)
4
#define YYDEFUN(name, arglist, args) name(args)
10
#define YYDEFUN(name, arglist, args) name arglist args;
15
YYCONST static char yysccsid[] = "@(#)yaccpar 1.8 (Berkeley +Cygnus.28) 01/20/91";
18
#ifndef YYDONT_INCLUDE_STDIO
21
//#ifdef __cplusplus TA <tim@ngus.net> stdlib.h applies to C too
22
#include <stdlib.h> /* for malloc/realloc/free */
24
#line 2 "lburg/gram.y"
27
/*lint -e616 -e527 -e652 -esym(552,yynerrs) -esym(563,yynewstate,yyerrlab) */
28
static int yylineno = 0;
29
#line 8 "lburg/gram.y"
44
static YYCONST short yylhs[] = { -1,
45
0, 0, 4, 4, 6, 6, 6, 6, 7, 7,
46
5, 5, 5, 5, 1, 3, 3, 3, 2,
48
static YYCONST short yylen[] = { 2,
49
3, 1, 0, 2, 3, 3, 1, 2, 0, 4,
50
0, 7, 2, 3, 1, 1, 4, 6, 1,
52
static YYCONST short yydefred[] = { 3,
53
0, 0, 0, 9, 0, 11, 7, 4, 8, 0,
54
15, 0, 0, 0, 5, 6, 0, 13, 0, 0,
55
14, 0, 10, 0, 0, 0, 0, 0, 19, 0,
58
static YYCONST short yydgoto[] = { 1,
59
12, 30, 25, 2, 13, 8, 10,
61
static YYCONST short yysindex[] = { 0,
62
0, -4, -2, 0, -250, 0, 0, 0, 0, -9,
63
0, 1, -10, -49, 0, 0, 3, 0, -44, -248,
64
0, -244, 0, -22, -242, -244, -245, -37, 0, 10,
67
static YYCONST short yyrindex[] = { 0,
68
0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
69
0, 0, 23, 0, 0, 0, 0, 0, 0, 0,
70
0, 0, 0, -39, 0, 0, 0, 0, 0, 0,
73
static YYCONST short yygindex[] = { 0,
74
11, 0, -23, 0, 0, 0, 0,
76
#define YYTABLESIZE 255
77
static YYCONST short yytable[] = { 18,
78
15, 16, 28, 31, 16, 7, 32, 9, 34, 11,
79
16, 20, 21, 22, 23, 24, 29, 26, 27, 33,
80
35, 2, 1, 19, 0, 0, 0, 0, 0, 0,
81
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
82
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
83
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
84
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
89
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100
0, 16, 0, 0, 0, 0, 0, 0, 0, 0,
101
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102
0, 0, 0, 0, 0, 17, 0, 0, 0, 11,
105
static YYCONST short yycheck[] = { 10,
106
10, 41, 26, 41, 44, 10, 44, 10, 32, 260,
107
10, 61, 10, 58, 263, 260, 262, 40, 261, 10,
108
41, 0, 0, 13, -1, -1, -1, -1, -1, -1,
109
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
110
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
111
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
112
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
113
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
114
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
115
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
116
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
117
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
118
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
119
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
120
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
121
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
122
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
123
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
124
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
125
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
126
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
127
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
128
-1, 261, -1, -1, -1, -1, -1, -1, -1, -1,
129
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
130
-1, -1, -1, -1, -1, 256, -1, -1, -1, 260,
131
260, 256, 257, 258, 259,
137
#define YYMAXTOKEN 263
139
static YYCONST char *YYCONST yyname[] = {
140
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
141
0,0,0,0,0,0,0,0,0,"'('","')'",0,0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,"':'",0,0,
142
"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
143
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
144
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
145
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
146
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
147
"TERMINAL","START","PPERCENT","ID","TEMPLATE","CODE","INT",
149
static YYCONST char *YYCONST yyrule[] = {
151
"spec : decls PPERCENT rules",
154
"decls : decls decl",
155
"decl : TERMINAL blist '\\n'",
156
"decl : START nonterm '\\n'",
158
"decl : error '\\n'",
160
"blist : blist ID '=' INT",
162
"rules : rules nonterm ':' tree TEMPLATE cost '\\n'",
163
"rules : rules '\\n'",
164
"rules : rules error '\\n'",
167
"tree : ID '(' tree ')'",
168
"tree : ID '(' tree ',' tree ')'",
172
#define YYLEX yylex()
174
#define yyclearin (yychar=(YYEMPTY))
175
#define yyerrok (yyerrflag=0)
177
#define YYINITDEPTH 200
181
#define YYMAXDEPTH YYSTACKSIZE
185
#define YYSTACKSIZE YYMAXDEPTH
187
#define YYSTACKSIZE 500
188
#define YYMAXDEPTH 500
191
#ifndef YYMAXSTACKSIZE
192
#define YYMAXSTACKSIZE 10000
201
static YYSTYPE *yyvs;
202
static int yystacksize;
203
#define yyfree(x) free(x)
207
YYDEFUN (yymalloc, (bytes), unsigned bytes)
209
YYPTR ptr = (YYPTR) malloc (bytes);
210
if (ptr != 0) return (ptr);
211
yyerror ("yyparse: memory exhausted");
216
YYDEFUN (yyrealloc, (old, bytes), YYPTR old YYAND unsigned bytes)
218
YYPTR ptr = (YYPTR) realloc (old, bytes);
219
if (ptr != 0) return (ptr);
220
yyerror ("yyparse: memory exhausted");
231
int old_stacksize = yystacksize;
236
if (yystacksize == YYMAXSTACKSIZE)
238
yystacksize += (yystacksize + 1 ) / 2;
239
if (yystacksize > YYMAXSTACKSIZE)
240
yystacksize = YYMAXSTACKSIZE;
243
printf("yydebug: growing stack size from %d to %d\n",
244
old_stacksize, yystacksize);
246
new_yyss = (short *) yyrealloc ((char *)yyss, yystacksize * sizeof (short));
249
new_yyvs = (YYSTYPE *) yyrealloc ((char *)yyvs, yystacksize * sizeof (YYSTYPE));
259
#line 60 "lburg/gram.y"
269
static char buf[BUFSIZ], *bp = buf;
270
static int ppercent = 0;
273
static int get(void) {
277
if (fgets(buf, sizeof buf, infp) == NULL)
280
while (buf[0] == '%' && buf[1] == '{' && buf[2] == '\n') {
282
if (fgets(buf, sizeof buf, infp) == NULL) {
283
yywarn("unterminated %{...%}\n");
287
if (strcmp(buf, "%}\n") == 0)
291
if (fgets(buf, sizeof buf, infp) == NULL)
299
void yyerror(char *fmt, ...) {
304
fprintf(stderr, "line %d: ", yylineno);
305
vfprintf(stderr, fmt, ap);
306
if (fmt[strlen(fmt)-1] != '\n')
307
fprintf(stderr, "\n");
317
bp += strspn(bp, " \t\f");
318
p = strchr(bp, '\n');
320
p = strchr(bp, '\n');
321
while (p > bp && isspace(p[-1]))
323
yylval.string = alloc(p - bp + 1);
324
strncpy(yylval.string, bp, p - bp);
325
yylval.string[p - bp] = 0;
330
while ((c = get()) != EOF) {
332
case ' ': case '\f': case '\t':
335
case '(': case ')': case ',':
339
if (c == '%' && *bp == '%') {
341
return ppercent++ ? 0 : PPERCENT;
342
} else if (c == '%' && strncmp(bp, "term", 4) == 0
346
} else if (c == '%' && strncmp(bp, "start", 5) == 0
350
} else if (c == '"') {
351
char *p = strchr(bp, '"');
353
yyerror("missing \" in assembler template\n");
354
p = strchr(bp, '\n');
356
p = strchr(bp, '\0');
359
yylval.string = alloc(p - bp + 1);
360
strncpy(yylval.string, bp, p - bp);
361
yylval.string[p - bp] = 0;
362
bp = *p == '"' ? p + 1 : p;
365
} else if (isdigit(c)) {
369
if (n > (INT_MAX - d)/10)
370
yyerror("integer greater than %d\n", INT_MAX);
374
} while (c != EOF && isdigit(c));
378
} else if (isalpha(c)) {
380
while (isalpha(*bp) || isdigit(*bp) || *bp == '_')
382
yylval.string = alloc(bp - p + 1);
383
strncpy(yylval.string, p, bp - p);
384
yylval.string[bp - p] = 0;
386
} else if (isprint(c))
387
yyerror("invalid character `%c'\n", c);
389
yyerror("invalid character `\\%03o'\n", (unsigned char)c);
394
void yywarn(char *fmt, ...) {
399
fprintf(stderr, "line %d: ", yylineno);
400
fprintf(stderr, "warning: ");
401
vfprintf(stderr, fmt, ap);
404
#define YYABORT goto yyabort
405
#define YYACCEPT goto yyaccept
406
#define YYERROR goto yyerrlab
410
extern "C" char *getenv();
412
extern char *getenv();
419
register int yym, yyn, yystate;
420
register YYSTYPE *yyvsp;
421
register short *yyssp;
424
register YYCONST char *yys;
426
if (yys = getenv("YYDEBUG"))
429
if (yyn >= '0' && yyn <= '9')
440
yyss = (short *) yymalloc (YYSTACKSIZE * sizeof (short));
443
yyvs = (YYSTYPE *) yymalloc (YYSTACKSIZE * sizeof (YYSTYPE));
449
yystacksize = YYSTACKSIZE;
451
yysse = yyss + yystacksize - 1;
454
*yyssp = yystate = 0;
459
yystate = yytable[yyn];
463
int depth = yyssp - yyss;
466
yysse = yyss + yystacksize -1;
467
yyssp = depth + yyss;
468
yyvsp = depth + yyvs;
474
if ((yyn = yydefred[yystate])) goto yyreduce;
475
yyn = yysindex[yystate];
478
if ((yychar = yylex()) < 0) yychar = 0;
483
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
484
if (!yys) yys = "illegal-symbol";
485
printf("yydebug: state %d, reading %d (%s)\n", yystate,
491
&& ((yyn += yychar), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
492
&& yycheck[yyn] == yychar)
496
printf("yydebug: state %d, shifting to state %d\n",
497
yystate, yytable[yyn]);
499
if (yyerrflag > 0) --yyerrflag;
503
yyn = yyrindex[yystate];
505
&& ((yyn += yychar), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
506
&& yycheck[yyn] == yychar)
511
if (yyerrflag) goto yyinrecovery;
516
yyerror("syntax error");
528
yyn = yysindex[*yyssp];
530
&& ((yyn += YYERRCODE), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
531
&& yycheck[yyn] == YYERRCODE)
535
printf("yydebug: state %d, error recovery shifting\
536
to state %d\n", *yyssp, yytable[yyn]);
544
printf("yydebug: error recovery discarding state %d\n",
547
if (yyssp <= yyss) goto yyabort;
555
if (yychar == 0) goto yyabort;
560
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
561
if (!yys) yys = "illegal-symbol";
562
printf("yydebug: state %d, error recovery discards token %d (%s)\n",
563
yystate, yychar, yys);
572
printf("yydebug: state %d, reducing by rule %d (%s)\n",
573
yystate, yyn, yyrule[yyn]);
576
yyval = yyvsp[1-yym];
580
#line 22 "lburg/gram.y"
584
#line 23 "lburg/gram.y"
588
#line 31 "lburg/gram.y"
590
if (nonterm(yyvsp[-1].string)->number != 1)
591
yyerror("redeclaration of the start symbol\n");
595
#line 36 "lburg/gram.y"
599
#line 40 "lburg/gram.y"
600
{ term(yyvsp[-2].string, yyvsp[0].n); }
603
#line 44 "lburg/gram.y"
604
{ rule(yyvsp[-5].string, yyvsp[-3].tree, yyvsp[-2].string, yyvsp[-1].string); }
607
#line 46 "lburg/gram.y"
611
#line 49 "lburg/gram.y"
612
{ nonterm(yyval.string = yyvsp[0].string); }
615
#line 52 "lburg/gram.y"
616
{ yyval.tree = tree(yyvsp[0].string, 0, 0); }
619
#line 53 "lburg/gram.y"
620
{ yyval.tree = tree(yyvsp[-3].string, yyvsp[-1].tree, 0); }
623
#line 54 "lburg/gram.y"
624
{ yyval.tree = tree(yyvsp[-5].string, yyvsp[-3].tree, yyvsp[-1].tree); }
627
#line 57 "lburg/gram.y"
628
{ if (*yyvsp[0].string == 0) yyval.string = "0"; }
636
if (yystate == 0 && yym == 0)
640
printf("yydebug: after reduction, shifting from state 0 to\
641
state %d\n", YYFINAL);
648
if ((yychar = yylex()) < 0) yychar = 0;
653
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
654
if (!yys) yys = "illegal-symbol";
655
printf("yydebug: state %d, reading %d (%s)\n",
656
YYFINAL, yychar, yys);
660
if (yychar == 0) goto yyaccept;
665
&& ((yyn += yystate), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
666
&& yycheck[yyn] == yystate)
667
yystate = yytable[yyn];
669
yystate = yydgoto[yym];
672
printf("yydebug: after reduction, shifting from state %d \
673
to state %d\n", *yyssp, yystate);
677
yyerror("yacc stack overflow");