1/* $Id: yaccpar.skel,v 1.10 2018/05/06 21:28:14 Guy.Harris Exp $ */ 2 3#include "defs.h" 4 5/* If the skeleton is changed, the banner should be changed so that */ 6/* the altered version can be easily distinguished from the original. */ 7/* */ 8/* The #defines included with the banner are there because they are */ 9/* useful in subsequent code. The macros #defined in the header or */ 10/* the body either are not useful outside of semantic actions or */ 11/* are conditional. */ 12 13%% banner 14/* original parser id follows */ 15/* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */ 16/* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */ 17 18#define YYBYACC 1 19%% insert VERSION here 20 21#define YYEMPTY (-1) 22#define yyclearin (yychar = YYEMPTY) 23#define yyerrok (yyerrflag = 0) 24#define YYRECOVERING() (yyerrflag != 0) 25#define YYENOMEM (-2) 26#define YYEOF 0 27%% xdecls 28 29extern int YYPARSE_DECL(); 30%% tables 31extern YYINT yylhs[]; 32extern YYINT yylen[]; 33extern YYINT yydefred[]; 34extern YYINT yydgoto[]; 35extern YYINT yysindex[]; 36extern YYINT yyrindex[]; 37extern YYINT yygindex[]; 38extern YYINT yytable[]; 39extern YYINT yycheck[]; 40 41#if YYDEBUG || defined(yytname) 42extern char *yyname[]; 43#endif 44#if YYDEBUG 45extern char *yyrule[]; 46#endif 47%% global_vars 48 49#if YYDEBUG 50int yydebug; 51#endif 52%% impure_vars 53 54int yyerrflag; 55int yychar; 56YYSTYPE yyval; 57YYSTYPE yylval; 58int yynerrs; 59%% hdr_defs 60 61/* define the initial stack-sizes */ 62#ifdef YYSTACKSIZE 63#undef YYMAXDEPTH 64#define YYMAXDEPTH YYSTACKSIZE 65#else 66#ifdef YYMAXDEPTH 67#define YYSTACKSIZE YYMAXDEPTH 68#else 69#define YYSTACKSIZE 10000 70#define YYMAXDEPTH 10000 71#endif 72#endif 73 74#define YYINITSTACKSIZE 200 75 76typedef struct { 77 unsigned stacksize; 78 YYINT *s_base; 79 YYINT *s_mark; 80 YYINT *s_last; 81 YYSTYPE *l_base; 82 YYSTYPE *l_mark; 83} YYSTACKDATA; 84%% hdr_vars 85/* variables for the parser stack */ 86static YYSTACKDATA yystack; 87%% body_vars 88 int yyerrflag; 89 int yychar; 90 YYSTYPE yyval; 91 YYSTYPE yylval; 92 int yynerrs; 93 94 /* variables for the parser stack */ 95 YYSTACKDATA yystack; 96%% body_1 97 98#if YYDEBUG 99#include <stdio.h> /* needed for printf */ 100#endif 101 102#include <stdlib.h> /* needed for malloc, etc */ 103#include <string.h> /* needed for memset */ 104 105/* allocate initial stack or double stack size, up to YYMAXDEPTH */ 106static int yygrowstack(YYSTACKDATA *data) 107{ 108 int i; 109 unsigned newsize; 110 YYINT *newss; 111 YYSTYPE *newvs; 112 113 if ((newsize = data->stacksize) == 0) 114 newsize = YYINITSTACKSIZE; 115 else if (newsize >= YYMAXDEPTH) 116 return YYENOMEM; 117 else if ((newsize *= 2) > YYMAXDEPTH) 118 newsize = YYMAXDEPTH; 119 120 i = (int) (data->s_mark - data->s_base); 121 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss)); 122 if (newss == NULL) 123 return YYENOMEM; 124 125 data->s_base = newss; 126 data->s_mark = newss + i; 127 128 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); 129 if (newvs == NULL) 130 return YYENOMEM; 131 132 data->l_base = newvs; 133 data->l_mark = newvs + i; 134 135 data->stacksize = newsize; 136 data->s_last = data->s_base + newsize - 1; 137 return 0; 138} 139 140#if YYPURE || defined(YY_NO_LEAKS) 141static void yyfreestack(YYSTACKDATA *data) 142{ 143 free(data->s_base); 144 free(data->l_base); 145 memset(data, 0, sizeof(*data)); 146} 147#else 148#define yyfreestack(data) /* nothing */ 149#endif 150 151#define YYABORT goto yyabort 152#define YYREJECT goto yyabort 153#define YYACCEPT goto yyaccept 154#define YYERROR goto yyerrlab 155 156int 157YYPARSE_DECL() 158{ 159%% body_2 160 int yym, yyn, yystate; 161#if YYDEBUG 162 const char *yys; 163 164 if ((yys = getenv("YYDEBUG")) != NULL) 165 { 166 yyn = *yys; 167 if (yyn >= '0' && yyn <= '9') 168 yydebug = yyn - '0'; 169 } 170#endif 171 172%% init_vars 173 memset(&yyval, 0, sizeof(yyval)); 174 memset(&yylval, 0, sizeof(yylval)); 175 176%% body_3 177 yym = 0; 178 yyn = 0; 179 yynerrs = 0; 180 yyerrflag = 0; 181 yychar = YYEMPTY; 182 yystate = 0; 183 184#if YYPURE 185 memset(&yystack, 0, sizeof(yystack)); 186#endif 187 188 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 189 yystack.s_mark = yystack.s_base; 190 yystack.l_mark = yystack.l_base; 191 yystate = 0; 192 *yystack.s_mark = 0; 193 194yyloop: 195 if ((yyn = yydefred[yystate]) != 0) goto yyreduce; 196 if (yychar < 0) 197 { 198 yychar = YYLEX; 199 if (yychar < 0) yychar = YYEOF; 200#if YYDEBUG 201 if (yydebug) 202 { 203 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 204 printf("%sdebug: state %d, reading %d (%s)\n", 205 YYPREFIX, yystate, yychar, yys); 206 } 207#endif 208 } 209 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 && 210 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 211 { 212#if YYDEBUG 213 if (yydebug) 214 printf("%sdebug: state %d, shifting to state %d\n", 215 YYPREFIX, yystate, yytable[yyn]); 216#endif 217 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 218 yystate = yytable[yyn]; 219 *++yystack.s_mark = yytable[yyn]; 220 *++yystack.l_mark = yylval; 221 yychar = YYEMPTY; 222 if (yyerrflag > 0) --yyerrflag; 223 goto yyloop; 224 } 225 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 && 226 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 227 { 228 yyn = yytable[yyn]; 229 goto yyreduce; 230 } 231 if (yyerrflag != 0) goto yyinrecovery; 232 233 YYERROR_CALL("syntax error"); 234 235 goto yyerrlab; /* redundant goto avoids 'unused label' warning */ 236yyerrlab: 237 ++yynerrs; 238 239yyinrecovery: 240 if (yyerrflag < 3) 241 { 242 yyerrflag = 3; 243 for (;;) 244 { 245 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 && 246 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE) 247 { 248#if YYDEBUG 249 if (yydebug) 250 printf("%sdebug: state %d, error recovery shifting\ 251 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); 252#endif 253 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 254 yystate = yytable[yyn]; 255 *++yystack.s_mark = yytable[yyn]; 256 *++yystack.l_mark = yylval; 257 goto yyloop; 258 } 259 else 260 { 261#if YYDEBUG 262 if (yydebug) 263 printf("%sdebug: error recovery discarding state %d\n", 264 YYPREFIX, *yystack.s_mark); 265#endif 266 if (yystack.s_mark <= yystack.s_base) goto yyabort; 267 --yystack.s_mark; 268 --yystack.l_mark; 269 } 270 } 271 } 272 else 273 { 274 if (yychar == YYEOF) goto yyabort; 275#if YYDEBUG 276 if (yydebug) 277 { 278 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 279 printf("%sdebug: state %d, error recovery discards token %d (%s)\n", 280 YYPREFIX, yystate, yychar, yys); 281 } 282#endif 283 yychar = YYEMPTY; 284 goto yyloop; 285 } 286 287yyreduce: 288#if YYDEBUG 289 if (yydebug) 290 printf("%sdebug: state %d, reducing by rule %d (%s)\n", 291 YYPREFIX, yystate, yyn, yyrule[yyn]); 292#endif 293 yym = yylen[yyn]; 294 if (yym > 0) 295 yyval = yystack.l_mark[1-yym]; 296 else 297 memset(&yyval, 0, sizeof yyval); 298 299 switch (yyn) 300 { 301%% trailer 302 } 303 yystack.s_mark -= yym; 304 yystate = *yystack.s_mark; 305 yystack.l_mark -= yym; 306 yym = yylhs[yyn]; 307 if (yystate == 0 && yym == 0) 308 { 309#if YYDEBUG 310 if (yydebug) 311 printf("%sdebug: after reduction, shifting from state 0 to\ 312 state %d\n", YYPREFIX, YYFINAL); 313#endif 314 yystate = YYFINAL; 315 *++yystack.s_mark = YYFINAL; 316 *++yystack.l_mark = yyval; 317 if (yychar < 0) 318 { 319 yychar = YYLEX; 320 if (yychar < 0) yychar = YYEOF; 321#if YYDEBUG 322 if (yydebug) 323 { 324 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 325 printf("%sdebug: state %d, reading %d (%s)\n", 326 YYPREFIX, YYFINAL, yychar, yys); 327 } 328#endif 329 } 330 if (yychar == YYEOF) goto yyaccept; 331 goto yyloop; 332 } 333 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 && 334 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate) 335 yystate = yytable[yyn]; 336 else 337 yystate = yydgoto[yym]; 338#if YYDEBUG 339 if (yydebug) 340 printf("%sdebug: after reduction, shifting from state %d \ 341to state %d\n", YYPREFIX, *yystack.s_mark, yystate); 342#endif 343 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 344 *++yystack.s_mark = (YYINT) yystate; 345 *++yystack.l_mark = yyval; 346 goto yyloop; 347 348yyoverflow: 349 YYERROR_CALL("yacc stack overflow"); 350 351yyabort: 352 yyfreestack(&yystack); 353 return (1); 354 355yyaccept: 356 yyfreestack(&yystack); 357 return (0); 358} 359