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