yaccpars (5142B)
1 #define YYFLAG -1000 2 #define YYERROR goto yyerrlab 3 #define YYACCEPT return(0) 4 #define YYABORT return(1) 5 #define yyclearin yychar = -1 6 #define yyerrok yyerrflag = 0 7 8 #ifdef yydebug 9 #include "y.debug" 10 #else 11 #define yydebug 0 12 static const char* yytoknames[1]; /* for debugging */ 13 static const char* yystates[1]; /* for debugging */ 14 #endif 15 16 /* parser for yacc output */ 17 #ifdef YYARG 18 #define yynerrs yyarg->yynerrs 19 #define yyerrflag yyarg->yyerrflag 20 #define yyval yyarg->yyval 21 #define yylval yyarg->yylval 22 #else 23 int yynerrs = 0; /* number of errors */ 24 int yyerrflag = 0; /* error recovery flag */ 25 #endif 26 27 static const char* 28 yytokname(int yyc) 29 { 30 static char x[10]; 31 32 if(yyc > 0 && yyc <= sizeof(yytoknames)/sizeof(yytoknames[0])) 33 if(yytoknames[yyc-1]) 34 return yytoknames[yyc-1]; 35 sprintf(x, "<%d>", yyc); 36 return x; 37 } 38 39 static const char* 40 yystatname(int yys) 41 { 42 static char x[10]; 43 44 if(yys >= 0 && yys < sizeof(yystates)/sizeof(yystates[0])) 45 if(yystates[yys]) 46 return yystates[yys]; 47 sprintf(x, "<%d>\n", yys); 48 return x; 49 } 50 51 static long 52 #ifdef YYARG 53 yylex1(struct Yyarg *yyarg) 54 #else 55 yylex1(void) 56 #endif 57 { 58 long yychar; 59 const long *t3p; 60 int c; 61 62 #ifdef YYARG 63 yychar = yylex(yyarg); 64 #else 65 yychar = yylex(); 66 #endif 67 if(yychar <= 0) { 68 c = yytok1[0]; 69 goto out; 70 } 71 if(yychar < sizeof(yytok1)/sizeof(yytok1[0])) { 72 c = yytok1[yychar]; 73 goto out; 74 } 75 if(yychar >= YYPRIVATE) 76 if(yychar < YYPRIVATE+sizeof(yytok2)/sizeof(yytok2[0])) { 77 c = yytok2[yychar-YYPRIVATE]; 78 goto out; 79 } 80 for(t3p=yytok3;; t3p+=2) { 81 c = t3p[0]; 82 if(c == yychar) { 83 c = t3p[1]; 84 goto out; 85 } 86 if(c == 0) 87 break; 88 } 89 c = 0; 90 91 out: 92 if(c == 0) 93 c = yytok2[1]; /* unknown char */ 94 if(yydebug >= 3) 95 printf("lex %.4lX %s\n", yychar, yytokname(c)); 96 return c; 97 } 98 99 int 100 #ifdef YYARG 101 yyparse(struct Yyarg *yyarg) 102 #else 103 yyparse(void) 104 #endif 105 { 106 struct 107 { 108 YYSTYPE yyv; 109 int yys; 110 } yys[YYMAXDEPTH], *yyp, *yypt; 111 const short *yyxi; 112 int yyj, yym, yystate, yyn, yyg; 113 long yychar; 114 #ifndef YYARG 115 YYSTYPE save1, save2; 116 int save3, save4; 117 118 save1 = yylval; 119 save2 = yyval; 120 save3 = yynerrs; 121 save4 = yyerrflag; 122 #endif 123 124 yystate = 0; 125 yychar = -1; 126 yynerrs = 0; 127 yyerrflag = 0; 128 yyp = &yys[-1]; 129 goto yystack; 130 131 ret0: 132 yyn = 0; 133 goto ret; 134 135 ret1: 136 yyn = 1; 137 goto ret; 138 139 ret: 140 #ifndef YYARG 141 yylval = save1; 142 yyval = save2; 143 yynerrs = save3; 144 yyerrflag = save4; 145 #endif 146 return yyn; 147 148 yystack: 149 /* put a state and value onto the stack */ 150 if(yydebug >= 4) 151 printf("char %s in %s", yytokname(yychar), yystatname(yystate)); 152 153 yyp++; 154 if(yyp >= &yys[YYMAXDEPTH]) { 155 yyerror("yacc stack overflow"); 156 goto ret1; 157 } 158 yyp->yys = yystate; 159 yyp->yyv = yyval; 160 161 yynewstate: 162 yyn = yypact[yystate]; 163 if(yyn <= YYFLAG) 164 goto yydefault; /* simple state */ 165 if(yychar < 0) 166 #ifdef YYARG 167 yychar = yylex1(yyarg); 168 #else 169 yychar = yylex1(); 170 #endif 171 yyn += yychar; 172 if(yyn < 0 || yyn >= YYLAST) 173 goto yydefault; 174 yyn = yyact[yyn]; 175 if(yychk[yyn] == yychar) { /* valid shift */ 176 yychar = -1; 177 yyval = yylval; 178 yystate = yyn; 179 if(yyerrflag > 0) 180 yyerrflag--; 181 goto yystack; 182 } 183 184 yydefault: 185 /* default state action */ 186 yyn = yydef[yystate]; 187 if(yyn == -2) { 188 if(yychar < 0) 189 #ifdef YYARG 190 yychar = yylex1(yyarg); 191 #else 192 yychar = yylex1(); 193 #endif 194 195 /* look through exception table */ 196 for(yyxi=yyexca;; yyxi+=2) 197 if(yyxi[0] == -1 && yyxi[1] == yystate) 198 break; 199 for(yyxi += 2;; yyxi += 2) { 200 yyn = yyxi[0]; 201 if(yyn < 0 || yyn == yychar) 202 break; 203 } 204 yyn = yyxi[1]; 205 if(yyn < 0) 206 goto ret0; 207 } 208 if(yyn == 0) { 209 /* error ... attempt to resume parsing */ 210 switch(yyerrflag) { 211 case 0: /* brand new error */ 212 yyerror("syntax error"); 213 if(yydebug >= 1) { 214 printf("%s", yystatname(yystate)); 215 printf("saw %s\n", yytokname(yychar)); 216 } 217 goto yyerrlab; 218 yyerrlab: 219 yynerrs++; 220 221 case 1: 222 case 2: /* incompletely recovered error ... try again */ 223 yyerrflag = 3; 224 225 /* find a state where "error" is a legal shift action */ 226 while(yyp >= yys) { 227 yyn = yypact[yyp->yys] + YYERRCODE; 228 if(yyn >= 0 && yyn < YYLAST) { 229 yystate = yyact[yyn]; /* simulate a shift of "error" */ 230 if(yychk[yystate] == YYERRCODE) 231 goto yystack; 232 } 233 234 /* the current yyp has no shift onn "error", pop stack */ 235 if(yydebug >= 2) 236 printf("error recovery pops state %d, uncovers %d\n", 237 yyp->yys, (yyp-1)->yys ); 238 yyp--; 239 } 240 /* there is no state on the stack with an error shift ... abort */ 241 goto ret1; 242 243 case 3: /* no shift yet; clobber input char */ 244 if(yydebug >= YYEOFCODE) 245 printf("error recovery discards %s\n", yytokname(yychar)); 246 if(yychar == YYEOFCODE) 247 goto ret1; 248 yychar = -1; 249 goto yynewstate; /* try again in the same state */ 250 } 251 } 252 253 /* reduction by production yyn */ 254 if(yydebug >= 2) 255 printf("reduce %d in:\n\t%s", yyn, yystatname(yystate)); 256 257 yypt = yyp; 258 yyp -= yyr2[yyn]; 259 yyval = (yyp+1)->yyv; 260 yym = yyn; 261 262 /* consult goto table to find next state */ 263 yyn = yyr1[yyn]; 264 yyg = yypgo[yyn]; 265 yyj = yyg + yyp->yys + 1; 266 267 if(yyj >= YYLAST || yychk[yystate=yyact[yyj]] != -yyn) 268 yystate = yyact[yyg]; 269 switch(yym) { 270 $A 271 } 272 goto yystack; /* stack new state and value */ 273 }