Fri, 4 Sep 92 00:09:25 CDT Subject: yacc parser /*** This is the yypars.c that comes with yacc F85 RSX SIG ***/ /* * This file has been altered to accommodate a rebuild of * lex's ytab.c from an updated lex.y. The updated lex.y * requires no direct edits to ytab.c. If not processing * lex.y, yypars.c operates normally in the yacc environment. * * Made reference to yys[YYMAXDEPTH] static, so stack not used. (04) */ #define YYFLAG -1000 /*|| Let STD I/O library process errors and exit ||*/ /*|| #define YYERROR error ||*/ /*|| Yet another way of fielding errors ||*/ /*|| #define YYERROR goto yyerrlab; ||*/ /*|| Let YACC programmer write the yyerror() function ||*/ #define YYERROR yyerror #define YYACCEPT return(0) #define YYABORT return(1) #ifndef LEXBLD int yydebug = 0; /* 1 for debugging */ YYSTYPE yyv[YYMAXDEPTH]; /* Where the values are stored */ int yychar = -1; /* Current input token number */ int yynerrs = 0; /* Number of errors */ short yyerrflag = 0; /* Error recovery flag */ #endif /* * Parser for yacc output. */ yyparse() { static short yys[YYMAXDEPTH]; /* 04 */ short yyj, yym; #ifndef LEXBLD register YYSTYPE *yypv; /*|| Hand edit for union ||*/ register YYSTYPE *yypvt; #endif register short yystate, *yyps, yyn; register short *yyxi; #ifdef LEXBLD struct nfa *np, *nbase; char *cp; struct des *dp; struct trans *tp; struct nlist *nl; int i, c; # ifdef DEBUG /* Let lldebug turn on yydebug when -d -d -d specified */ if (lldebug > 2) { yydebug = 1; } # endif #endif yystate = 0; yychar = -1; yynerrs = 0; yyerrflag = 0; yyps = &yys[-1]; yypv = &yyv[-1]; yystack: /* Put a state and value onto the stack */ if (yydebug) { #ifdef LEXBLD fprintf(LOGOUT, "state %3d, value %7d, char %4d\n", yystate, yyval, yychar); #else printf("state %d, char 0%o\n", yystate, yychar); #endif } if (++yyps > &yys[YYMAXDEPTH]) { YYERROR("yacc stack overflow"); return(1); } *yyps = yystate; ++yypv; *yypv = yyval; /*|| Hand edit for union ||*/ yynewstate: yyn = yypact[yystate]; if (yyn <= YYFLAG) { /* Simple state */ goto yydefault; } if (yychar < 0) { if ((yychar = yylex()) < 0) { yychar = 0; } } if ((yyn += yychar) < 0 || yyn >= YYLAST) { goto yydefault; } if (yychk[yyn = yyact[yyn]] == yychar) { /* * Valid shift. */ yychar = -1; yyval = yylval; /*|| Hand edit for union ||*/ yystate = yyn; if (yyerrflag > 0) { --yyerrflag; } goto yystack; } yydefault: /* * Default state action. */ if ((yyn = yydef[yystate]) == -2) { if (yychar < 0) { if ((yychar = yylex()) < 0) { yychar = 0; } } /* * Look through exception table. */ for (yyxi = yyexca; (*yyxi != (-1)) || (yyxi[1] != yystate); yyxi += 2) { ; /* VOID */ } /*|| while (*(yyxi += 2) >= 0) ||*/ /*|| Decus C can't handle this ||*/ while (*(yyxi = yyxi + 2) >= 0) { /*|| Do this instead ||*/ if (*yyxi == yychar) { break; } } if ((yyn = yyxi[1]) < 0) { /* Accept */ return(0); } } if (yyn == 0) { /* Error */ /* Error ... attempt to resume parsing */ switch(yyerrflag) { case 0: /* Brand new error */ YYERROR("Syntax error"); yyerrlab: ++yynerrs; case 1: case 2: /* Incompletely recovered error ... try again */ yyerrflag = 3; /* * Find a state where "error" is a legal shift action. */ while (yyps >= yys) { yyn = yypact[*yyps] + YYERRCODE; if (yyn >= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE) { yystate = yyact[yyn]; /* Simulate a shift of "error" */ goto yystack; } yyn = yypact[*yyps]; /* * The current yyps has no shift on "error", pop stack. */ if (yydebug) { #ifdef LEXBLD fprintf(LOGOUT, "Error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1]); #else printf("Error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1]); #endif } --yyps; --yypv; } /* * There is no state on the stack with an error shift ... abort. */ yyabort: return(1); case 3: /* No shift yet; clobber input char */ if (yydebug) { #ifdef LEXBLD fprintf(LOGOUT, "Error recovery discards char %d\n", yychar); #else printf("Error recovery discards char %d\n", yychar); #endif } if (yychar == 0) { goto yyabort; /* Don't discard EOF, quit */ } yychar = -1; goto yynewstate; /* Try again in the same state */ } } /* * Reduction by production yyn. */ if (yydebug) { #ifdef LEXBLD fprintf(LOGOUT, "Reduce %d\n", yyn); #else printf("Reduce %d\n", yyn); #endif } yyps -= yyr2[yyn]; yypvt = yypv; yypv -= yyr2[yyn]; yyval = yypv[1]; /*|| Hand edit for union ||*/ yym = yyn; /* * Consult goto table to find next state. */ yyn = yyr1[yyn]; yyj = yypgo[yyn] + *yyps + 1; if (yyj >= YYLAST || yychk[yystate = yyact[yyj]] != -yyn) { yystate = yyact[yypgo[yyn]]; } switch(yym) { $A } goto yystack; /* Stack new state and value */ }