123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- #define YYFLAG -1000
- #define YYERROR goto yyerrlab
- #define YYACCEPT return(0)
- #define YYABORT return(1)
- #define yyclearin yychar = -1
- #define yyerrok yyerrflag = 0
- #ifdef yydebug
- #include "y.debug"
- #else
- #define yydebug 0
- char* yytoknames[1]; /* for debugging */
- char* yystates[1]; /* for debugging */
- #endif
- /* parser for yacc output */
- int yynerrs = 0; /* number of errors */
- int yyerrflag = 0; /* error recovery flag */
- extern int fprint(int, char*, ...);
- extern int sprint(char*, char*, ...);
- char*
- yytokname(int yyc)
- {
- static char x[10];
- if(yyc > 0 && yyc <= sizeof(yytoknames)/sizeof(yytoknames[0]))
- if(yytoknames[yyc-1])
- return yytoknames[yyc-1];
- sprintf(x, "<%d>", yyc);
- return x;
- }
- char*
- yystatname(int yys)
- {
- static char x[10];
- if(yys >= 0 && yys < sizeof(yystates)/sizeof(yystates[0]))
- if(yystates[yys])
- return yystates[yys];
- sprintf(x, "<%d>\n", yys);
- return x;
- }
- long
- yylex1(void)
- {
- long yychar;
- long *t3p;
- int c;
- yychar = yylex();
- if(yychar <= 0) {
- c = yytok1[0];
- goto out;
- }
- if(yychar < sizeof(yytok1)/sizeof(yytok1[0])) {
- c = yytok1[yychar];
- goto out;
- }
- if(yychar >= YYPRIVATE)
- if(yychar < YYPRIVATE+sizeof(yytok2)/sizeof(yytok2[0])) {
- c = yytok2[yychar-YYPRIVATE];
- goto out;
- }
- for(t3p=yytok3;; t3p+=2) {
- c = t3p[0];
- if(c == yychar) {
- c = t3p[1];
- goto out;
- }
- if(c == 0)
- break;
- }
- c = 0;
- out:
- if(c == 0)
- c = yytok2[1]; /* unknown char */
- if(yydebug >= 3)
- printf("lex %.4X %s\n", yychar, yytokname(c));
- return c;
- }
- int
- yyparse(void)
- {
- struct
- {
- YYSTYPE yyv;
- int yys;
- } yys[YYMAXDEPTH], *yyp, *yypt;
- short *yyxi;
- int yyj, yym, yystate, yyn, yyg;
- YYSTYPE save1, save2;
- int save3, save4;
- long yychar;
- save1 = yylval;
- save2 = yyval;
- save3 = yynerrs;
- save4 = yyerrflag;
- yystate = 0;
- yychar = -1;
- yynerrs = 0;
- yyerrflag = 0;
- yyp = &yys[-1];
- goto yystack;
- ret0:
- yyn = 0;
- goto ret;
- ret1:
- yyn = 1;
- goto ret;
- ret:
- yylval = save1;
- yyval = save2;
- yynerrs = save3;
- yyerrflag = save4;
- return yyn;
- yystack:
- /* put a state and value onto the stack */
- if(yydebug >= 4)
- printf("char %s in %s", yytokname(yychar), yystatname(yystate));
- yyp++;
- if(yyp >= &yys[YYMAXDEPTH]) {
- yyerror("yacc stack overflow");
- goto ret1;
- }
- yyp->yys = yystate;
- yyp->yyv = yyval;
- yynewstate:
- yyn = yypact[yystate];
- if(yyn <= YYFLAG)
- goto yydefault; /* simple state */
- if(yychar < 0)
- yychar = yylex1();
- yyn += yychar;
- if(yyn < 0 || yyn >= YYLAST)
- goto yydefault;
- yyn = yyact[yyn];
- if(yychk[yyn] == yychar) { /* valid shift */
- yychar = -1;
- yyval = yylval;
- yystate = yyn;
- if(yyerrflag > 0)
- yyerrflag--;
- goto yystack;
- }
- yydefault:
- /* default state action */
- yyn = yydef[yystate];
- if(yyn == -2) {
- if(yychar < 0)
- yychar = yylex1();
- /* look through exception table */
- for(yyxi=yyexca;; yyxi+=2)
- if(yyxi[0] == -1 && yyxi[1] == yystate)
- break;
- for(yyxi += 2;; yyxi += 2) {
- yyn = yyxi[0];
- if(yyn < 0 || yyn == yychar)
- break;
- }
- yyn = yyxi[1];
- if(yyn < 0)
- goto ret0;
- }
- if(yyn == 0) {
- /* error ... attempt to resume parsing */
- switch(yyerrflag) {
- case 0: /* brand new error */
- yyerror("syntax error");
- if(yydebug >= 1) {
- printf("%s", yystatname(yystate));
- printf("saw %s\n", yytokname(yychar));
- }
- yyerrlab:
- yynerrs++;
- case 1:
- case 2: /* incompletely recovered error ... try again */
- yyerrflag = 3;
- /* find a state where "error" is a legal shift action */
- while(yyp >= yys) {
- yyn = yypact[yyp->yys] + YYERRCODE;
- if(yyn >= 0 && yyn < YYLAST) {
- yystate = yyact[yyn]; /* simulate a shift of "error" */
- if(yychk[yystate] == YYERRCODE)
- goto yystack;
- }
- /* the current yyp has no shift onn "error", pop stack */
- if(yydebug >= 2)
- printf("error recovery pops state %d, uncovers %d\n",
- yyp->yys, (yyp-1)->yys );
- yyp--;
- }
- /* there is no state on the stack with an error shift ... abort */
- goto ret1;
- case 3: /* no shift yet; clobber input char */
- if(yydebug >= YYEOFCODE)
- printf("error recovery discards %s\n", yytokname(yychar));
- if(yychar == YYEOFCODE)
- goto ret1;
- yychar = -1;
- goto yynewstate; /* try again in the same state */
- }
- }
- /* reduction by production yyn */
- if(yydebug >= 2)
- printf("reduce %d in:\n\t%s", yyn, yystatname(yystate));
- yypt = yyp;
- yyp -= yyr2[yyn];
- yyval = (yyp+1)->yyv;
- yym = yyn;
- /* consult goto table to find next state */
- yyn = yyr1[yyn];
- yyg = yypgo[yyn];
- yyj = yyg + yyp->yys + 1;
- if(yyj >= YYLAST || yychk[yystate=yyact[yyj]] != -yyn)
- yystate = yyact[yyg];
- switch(yym) {
- $A
- }
- goto yystack; /* stack new state and value */
- }
|