2 /* A Bison parser, made from bi-parser.y with Bison version GNU Bison version 1.24
5 #define YYBISON 1 /* Identify Bison output. */
10 #line 22 "bi-parser.y"
21 /* Chain of all defs built by the parser. */
25 static struct node
*makenode ();
26 static struct variation
*makevar ();
27 static struct def
*makedef ();
32 #line 44 "bi-parser.y"
37 struct variation
*variation
;
54 #define YYLTYPE yyltype
71 #define YYTRANSLATE(x) ((unsigned)(x) <= 259 ? yytranslate[x] : 17)
73 static const char yytranslate
[] = { 0,
74 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
75 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
76 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
77 2, 2, 2, 2, 2, 2, 2, 2, 2, 5,
78 7, 2, 2, 6, 2, 2, 2, 2, 2, 2,
79 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
80 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
81 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
82 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
83 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
84 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
85 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
86 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
87 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
88 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
89 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
90 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
91 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
92 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
93 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
94 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
95 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
96 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
97 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
98 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
99 2, 2, 2, 2, 2, 1, 2, 3, 4
103 static const short yyprhs
[] = { 0,
104 0, 2, 4, 7, 18, 20, 24, 28, 34, 42,
105 52, 53, 55, 59, 60, 62, 66
108 static const short yyrhs
[] = { 9,
109 0, 10, 0, 9, 10, 0, 3, 5, 4, 6,
110 13, 6, 5, 11, 7, 7, 0, 12, 0, 11,
111 6, 12, 0, 5, 13, 7, 0, 5, 13, 6,
112 14, 7, 0, 5, 13, 6, 14, 6, 14, 7,
113 0, 5, 13, 6, 14, 6, 14, 6, 14, 7,
114 0, 0, 4, 0, 5, 15, 7, 0, 0, 16,
115 0, 16, 6, 15, 0, 4, 0
121 static const short yyrline
[] = { 0,
122 60, 65, 67, 71, 76, 78, 82, 85, 87, 89,
123 93, 95, 98, 101, 105, 108, 112
126 static const char * const yytname
[] = { "$","error","$undefined.","DEFOP",
127 "STRING","'('","','","')'","top","defs","def","variations","variation","opt_string",
128 "list","items","item",""
132 static const short yyr1
[] = { 0,
133 8, 9, 9, 10, 11, 11, 12, 12, 12, 12,
134 13, 13, 14, 14, 15, 15, 16
137 static const short yyr2
[] = { 0,
138 1, 1, 2, 10, 1, 3, 3, 5, 7, 9,
142 static const short yydefact
[] = { 0,
143 0, 1, 2, 0, 3, 0, 11, 12, 0, 0,
144 0, 11, 0, 5, 0, 0, 0, 14, 7, 6,
145 4, 0, 0, 17, 0, 15, 14, 8, 13, 0,
146 0, 16, 14, 9, 0, 10, 0, 0, 0
149 static const short yydefgoto
[] = { 37,
150 2, 3, 13, 14, 9, 23, 25, 26
153 static const short yypact
[] = { 2,
154 6, 2,-32768, 8,-32768, 7, 10,-32768, 9, 11,
155 12, 10, -5,-32768, -3, 12, 13, 14,-32768,-32768,
156 -32768, 17, 1,-32768, 15, 18, 14,-32768,-32768, 17,
157 3,-32768, 14,-32768, 16,-32768, 25, 26,-32768
160 static const short yypgoto
[] = {-32768,
161 -32768, 27,-32768, 19, 20, -27, -12,-32768
168 static const short yytable
[] = { 31,
169 16, 17, 18, 19, 1, 35, 27, 28, 33, 34,
170 4, 6, 7, 8, 10, 11, 12, 32, 22, 21,
171 24, 29, 36, 30, 38, 39, 0, 0, 5, 0,
175 static const short yycheck
[] = { 27,
176 6, 7, 6, 7, 3, 33, 6, 7, 6, 7,
177 5, 4, 6, 4, 6, 5, 5, 30, 5, 7,
178 4, 7, 7, 6, 0, 0, -1, -1, 2, -1,
181 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
182 #line 3 "/usr/local/share/bison.simple"
184 /* Skeleton output parser for bison,
185 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
187 This program is free software; you can redistribute it and/or modify
188 it under the terms of the GNU General Public License as published by
189 the Free Software Foundation; either version 2, or (at your option)
192 This program is distributed in the hope that it will be useful,
193 but WITHOUT ANY WARRANTY; without even the implied warranty of
194 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
195 GNU General Public License for more details.
197 You should have received a copy of the GNU General Public License
198 along with this program; if not, write to the Free Software
199 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
201 /* As a special exception, when this file is copied by Bison into a
202 Bison output file, you may use that output file without restriction.
203 This special exception was added by the Free Software Foundation
204 in version 1.24 of Bison. */
208 #define alloca __builtin_alloca
209 #else /* not GNU C. */
210 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
212 #else /* not sparc */
213 #if defined (MSDOS) && !defined (__TURBOC__)
215 #else /* not MSDOS, or __TURBOC__ */
219 #else /* not MSDOS, __TURBOC__, or _AIX */
223 void *alloca (unsigned int);
225 #else /* not __cplusplus */
227 #endif /* not __cplusplus */
229 #endif /* not _AIX */
230 #endif /* not MSDOS, or __TURBOC__ */
231 #endif /* not sparc. */
232 #endif /* not GNU C. */
233 #endif /* alloca not defined. */
235 /* This is the parser code that is written into each bison parser
236 when the %semantic_parser declaration is not specified in the grammar.
237 It was written by Richard Stallman by simplifying the hairy parser
238 used when %semantic_parser is specified. */
240 /* Note: there must be only one dollar sign in this file.
241 It is replaced by the list of actions, each action
242 as one case of the switch. */
244 #define yyerrok (yyerrstatus = 0)
245 #define yyclearin (yychar = YYEMPTY)
248 #define YYACCEPT return(0)
249 #define YYABORT return(1)
250 #define YYERROR goto yyerrlab1
251 /* Like YYERROR except do call yyerror.
252 This remains here temporarily to ease the
253 transition to the new meaning of YYERROR, for GCC.
254 Once GCC version 2 has supplanted version 1, this can go. */
255 #define YYFAIL goto yyerrlab
256 #define YYRECOVERING() (!!yyerrstatus)
257 #define YYBACKUP(token, value) \
259 if (yychar == YYEMPTY && yylen == 1) \
260 { yychar = (token), yylval = (value); \
261 yychar1 = YYTRANSLATE (yychar); \
266 { yyerror ("syntax error: cannot back up"); YYERROR; } \
270 #define YYERRCODE 256
273 #define YYLEX yylex()
279 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
281 #define YYLEX yylex(&yylval, &yylloc)
283 #else /* not YYLSP_NEEDED */
285 #define YYLEX yylex(&yylval, YYLEX_PARAM)
287 #define YYLEX yylex(&yylval)
289 #endif /* not YYLSP_NEEDED */
292 /* If nonreentrant, generate the variables here */
296 int yychar
; /* the lookahead symbol */
297 YYSTYPE yylval
; /* the semantic value of the */
298 /* lookahead symbol */
301 YYLTYPE yylloc
; /* location data for the lookahead */
305 int yynerrs
; /* number of parse errors so far */
306 #endif /* not YYPURE */
309 int yydebug
; /* nonzero means print parse trace */
310 /* Since this is uninitialized, it does not stop multiple parsers
314 /* YYINITDEPTH indicates the initial size of the parser's stacks */
317 #define YYINITDEPTH 200
320 /* YYMAXDEPTH is the maximum size the stacks can grow to
321 (effective only if the built-in stack extension method is used). */
328 #define YYMAXDEPTH 10000
331 /* Prevent warning if -Wstrict-prototypes. */
336 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
337 #define __yy_memcpy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
338 #else /* not GNU C or C++ */
341 /* This is the most reliable way to avoid incompatibilities
342 in available built-in functions on various systems. */
344 __yy_memcpy (from
, to
, count
)
349 register char *f
= from
;
350 register char *t
= to
;
351 register int i
= count
;
357 #else /* __cplusplus */
359 /* This is the most reliable way to avoid incompatibilities
360 in available built-in functions on various systems. */
362 __yy_memcpy (char *from
, char *to
, int count
)
364 register char *f
= from
;
365 register char *t
= to
;
366 register int i
= count
;
375 #line 192 "/usr/local/share/bison.simple"
377 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
378 into yyparse. The argument should have type void *.
379 It should actually point to an object.
380 Grammar actions can access the variable by casting it
381 to the proper pointer type. */
384 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
386 #define YYPARSE_PARAM
387 #define YYPARSE_PARAM_DECL
391 yyparse(YYPARSE_PARAM
)
394 register int yystate
;
396 register short *yyssp
;
397 register YYSTYPE
*yyvsp
;
398 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
399 int yychar1
= 0; /* lookahead token as an internal (translated) token number */
401 short yyssa
[YYINITDEPTH
]; /* the state stack */
402 YYSTYPE yyvsa
[YYINITDEPTH
]; /* the semantic value stack */
404 short *yyss
= yyssa
; /* refer to the stacks thru separate pointers */
405 YYSTYPE
*yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
408 YYLTYPE yylsa
[YYINITDEPTH
]; /* the location stack */
409 YYLTYPE
*yyls
= yylsa
;
412 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
414 #define YYPOPSTACK (yyvsp--, yyssp--)
417 int yystacksize
= YYINITDEPTH
;
428 YYSTYPE yyval
; /* the variable used to return */
429 /* semantic values from the action */
436 fprintf(stderr
, "Starting parse\n");
442 yychar
= YYEMPTY
; /* Cause a token to be read. */
444 /* Initialize stack pointers.
445 Waste one element of value and location stack
446 so that they stay on the same level as the state stack.
447 The wasted elements are never initialized. */
455 /* Push a new state, which is found in yystate . */
456 /* In all cases, when you get here, the value and location stacks
457 have just been pushed. so pushing a state here evens the stacks. */
462 if (yyssp
>= yyss
+ yystacksize
- 1)
464 /* Give user a chance to reallocate the stack */
465 /* Use copies of these so that the &'s don't force the real ones into memory. */
466 YYSTYPE
*yyvs1
= yyvs
;
469 YYLTYPE
*yyls1
= yyls
;
472 /* Get the current used size of the three stacks, in elements. */
473 int size
= yyssp
- yyss
+ 1;
476 /* Each stack pointer address is followed by the size of
477 the data in use in that stack, in bytes. */
479 /* This used to be a conditional around just the two extra args,
480 but that might be undefined if yyoverflow is a macro. */
481 yyoverflow("parser stack overflow",
482 &yyss1
, size
* sizeof (*yyssp
),
483 &yyvs1
, size
* sizeof (*yyvsp
),
484 &yyls1
, size
* sizeof (*yylsp
),
487 yyoverflow("parser stack overflow",
488 &yyss1
, size
* sizeof (*yyssp
),
489 &yyvs1
, size
* sizeof (*yyvsp
),
493 yyss
= yyss1
; yyvs
= yyvs1
;
497 #else /* no yyoverflow */
498 /* Extend the stack our own way. */
499 if (yystacksize
>= YYMAXDEPTH
)
501 yyerror("parser stack overflow");
505 if (yystacksize
> YYMAXDEPTH
)
506 yystacksize
= YYMAXDEPTH
;
507 yyss
= (short *) alloca (yystacksize
* sizeof (*yyssp
));
508 __yy_memcpy ((char *)yyss1
, (char *)yyss
, size
* sizeof (*yyssp
));
509 yyvs
= (YYSTYPE
*) alloca (yystacksize
* sizeof (*yyvsp
));
510 __yy_memcpy ((char *)yyvs1
, (char *)yyvs
, size
* sizeof (*yyvsp
));
512 yyls
= (YYLTYPE
*) alloca (yystacksize
* sizeof (*yylsp
));
513 __yy_memcpy ((char *)yyls1
, (char *)yyls
, size
* sizeof (*yylsp
));
515 #endif /* no yyoverflow */
517 yyssp
= yyss
+ size
- 1;
518 yyvsp
= yyvs
+ size
- 1;
520 yylsp
= yyls
+ size
- 1;
525 fprintf(stderr
, "Stack size increased to %d\n", yystacksize
);
528 if (yyssp
>= yyss
+ yystacksize
- 1)
534 fprintf(stderr
, "Entering state %d\n", yystate
);
540 /* Do appropriate processing given the current state. */
541 /* Read a lookahead token if we need one and don't already have one. */
544 /* First try to decide what to do without reference to lookahead token. */
546 yyn
= yypact
[yystate
];
550 /* Not known => get a lookahead token if don't already have one. */
552 /* yychar is either YYEMPTY or YYEOF
553 or a valid token in external form. */
555 if (yychar
== YYEMPTY
)
559 fprintf(stderr
, "Reading a token: ");
564 /* Convert token to internal form (in yychar1) for indexing tables with */
566 if (yychar
<= 0) /* This means end of input. */
569 yychar
= YYEOF
; /* Don't call YYLEX any more */
573 fprintf(stderr
, "Now at end of input.\n");
578 yychar1
= YYTRANSLATE(yychar
);
583 fprintf (stderr
, "Next token is %d (%s", yychar
, yytname
[yychar1
]);
584 /* Give the individual parser a way to print the precise meaning
585 of a token, for further debugging info. */
587 YYPRINT (stderr
, yychar
, yylval
);
589 fprintf (stderr
, ")\n");
595 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != yychar1
)
600 /* yyn is what to do for this token type in this state.
601 Negative => reduce, -yyn is rule number.
602 Positive => shift, yyn is new state.
603 New state is final state => don't bother to shift,
605 0, or most negative number => error. */
620 /* Shift the lookahead token. */
624 fprintf(stderr
, "Shifting token %d (%s), ", yychar
, yytname
[yychar1
]);
627 /* Discard the token being shifted unless it is eof. */
636 /* count tokens shifted since error; after three, turn off error status. */
637 if (yyerrstatus
) yyerrstatus
--;
642 /* Do the default action for the current state. */
645 yyn
= yydefact
[yystate
];
649 /* Do a reduction. yyn is the number of a rule to reduce with. */
653 yyval
= yyvsp
[1-yylen
]; /* implement default value of the action */
660 fprintf (stderr
, "Reducing via rule %d (line %d), ",
663 /* Print the symbols being reduced, and their result. */
664 for (i
= yyprhs
[yyn
]; yyrhs
[i
] > 0; i
++)
665 fprintf (stderr
, "%s ", yytname
[yyrhs
[i
]]);
666 fprintf (stderr
, " -> %s\n", yytname
[yyr1
[yyn
]]);
674 #line 62 "bi-parser.y"
675 { defs
= yyvsp
[0].def
; ;
678 #line 68 "bi-parser.y"
679 { yyvsp
[0].def
->next
= yyvsp
[-1].def
; yyval
.def
= yyvsp
[0].def
; ;
682 #line 73 "bi-parser.y"
683 { yyval
.def
= makedef (yyvsp
[-7].string
, yyvsp
[-5].string
, yyvsp
[-2].variation
); ;
686 #line 79 "bi-parser.y"
687 { yyvsp
[0].variation
->next
= yyvsp
[-2].variation
; yyval
.variation
= yyvsp
[0].variation
; ;
690 #line 84 "bi-parser.y"
691 { yyval
.variation
= makevar (yyvsp
[-1].string
, (struct node
*) NULL
, (struct node
*) NULL
, (struct node
*) NULL
); ;
694 #line 86 "bi-parser.y"
695 { yyval
.variation
= makevar (yyvsp
[-3].string
, yyvsp
[-1].node
, (struct node
*) NULL
, (struct node
*) NULL
); ;
698 #line 88 "bi-parser.y"
699 { yyval
.variation
= makevar (yyvsp
[-5].string
, yyvsp
[-3].node
, yyvsp
[-1].node
, (struct node
*) NULL
); ;
702 #line 90 "bi-parser.y"
703 { yyval
.variation
= makevar (yyvsp
[-7].string
, yyvsp
[-5].node
, yyvsp
[-3].node
, yyvsp
[-1].node
); ;
706 #line 94 "bi-parser.y"
707 { yyval
.string
= ""; ;
710 #line 95 "bi-parser.y"
711 { yyval
.string
= yyvsp
[0].string
; ;
714 #line 100 "bi-parser.y"
715 { yyval
.node
= yyvsp
[-1].node
; ;
718 #line 102 "bi-parser.y"
719 { yyval
.node
= NULL
; ;
722 #line 109 "bi-parser.y"
723 { yyvsp
[-2].node
->next
= yyvsp
[0].node
; yyval
.node
= yyvsp
[-2].node
; ;
726 #line 114 "bi-parser.y"
727 { yyval
.node
= makenode (yyvsp
[0].string
); ;
730 /* the action file gets copied in in place of this dollarsign */
731 #line 487 "/usr/local/share/bison.simple"
742 short *ssp1
= yyss
- 1;
743 fprintf (stderr
, "state stack now");
744 while (ssp1
!= yyssp
)
745 fprintf (stderr
, " %d", *++ssp1
);
746 fprintf (stderr
, "\n");
756 yylsp
->first_line
= yylloc
.first_line
;
757 yylsp
->first_column
= yylloc
.first_column
;
758 yylsp
->last_line
= (yylsp
-1)->last_line
;
759 yylsp
->last_column
= (yylsp
-1)->last_column
;
764 yylsp
->last_line
= (yylsp
+yylen
-1)->last_line
;
765 yylsp
->last_column
= (yylsp
+yylen
-1)->last_column
;
769 /* Now "shift" the result of the reduction.
770 Determine what state that goes to,
771 based on the state we popped back to
772 and the rule number reduced by. */
776 yystate
= yypgoto
[yyn
- YYNTBASE
] + *yyssp
;
777 if (yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
778 yystate
= yytable
[yystate
];
780 yystate
= yydefgoto
[yyn
- YYNTBASE
];
784 yyerrlab
: /* here on detecting error */
787 /* If not already recovering from an error, report this error. */
791 #ifdef YYERROR_VERBOSE
792 yyn
= yypact
[yystate
];
794 if (yyn
> YYFLAG
&& yyn
< YYLAST
)
801 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
802 for (x
= (yyn
< 0 ? -yyn
: 0);
803 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
804 if (yycheck
[x
+ yyn
] == x
)
805 size
+= strlen(yytname
[x
]) + 15, count
++;
806 msg
= (char *) malloc(size
+ 15);
809 strcpy(msg
, "parse error");
814 for (x
= (yyn
< 0 ? -yyn
: 0);
815 x
< (sizeof(yytname
) / sizeof(char *)); x
++)
816 if (yycheck
[x
+ yyn
] == x
)
818 strcat(msg
, count
== 0 ? ", expecting `" : " or `");
819 strcat(msg
, yytname
[x
]);
828 yyerror ("parse error; also virtual memory exceeded");
831 #endif /* YYERROR_VERBOSE */
832 yyerror("parse error");
836 yyerrlab1
: /* here on error raised explicitly by an action */
838 if (yyerrstatus
== 3)
840 /* if just tried and failed to reuse lookahead token after an error, discard it. */
842 /* return failure if at end of input */
848 fprintf(stderr
, "Discarding token %d (%s).\n", yychar
, yytname
[yychar1
]);
854 /* Else will try to reuse lookahead token
855 after shifting the error token. */
857 yyerrstatus
= 3; /* Each real token shifted decrements this */
861 yyerrdefault
: /* current state does not do anything special for the error token. */
864 /* This is wrong; only states that explicitly want error tokens
865 should shift them. */
866 yyn
= yydefact
[yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
867 if (yyn
) goto yydefault
;
870 yyerrpop
: /* pop the current state because it cannot handle the error token */
872 if (yyssp
== yyss
) YYABORT
;
882 short *ssp1
= yyss
- 1;
883 fprintf (stderr
, "Error: state stack now");
884 while (ssp1
!= yyssp
)
885 fprintf (stderr
, " %d", *++ssp1
);
886 fprintf (stderr
, "\n");
892 yyn
= yypact
[yystate
];
897 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != YYTERROR
)
916 fprintf(stderr
, "Shifting error token, ");
927 #line 117 "bi-parser.y"
936 n
= (struct node
*) malloc (sizeof (struct node
));
942 static struct variation
*
943 makevar (name
, inputs
, outputs
, literals
)
945 struct node
*inputs
, *outputs
, *literals
;
949 v
= (struct variation
*) malloc (sizeof (struct variation
));
953 v
->outputs
= outputs
;
954 v
->literals
= literals
;
960 makedef (name
, template, vars
)
961 char *name
, *template;
962 struct variation
*vars
;
966 d
= (struct def
*) malloc (sizeof (struct def
));
968 d
->template = template;
969 d
->variations
= vars
;
978 fprintf (stderr
, "syntax error in input\n");
979 exit (FATAL_EXIT_CODE
);