3 * Copyright (c) 2004, 2005, 2006, 2007, 2008,
4 * 2009, 2010, 2011 by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
9 * Note that this file was originally generated as an output from
10 * GNU bison version 1.875, but now the code is statically maintained
11 * and edited; the bits that are dependent on perly.y are now
12 * #included from the files perly.tab and perly.act.
14 * Here is an important copyright statement from the original, generated
17 * As a special exception, when this file is copied by Bison into a
18 * Bison output file, you may use that output file without
19 * restriction. This special exception was added by the Free
20 * Software Foundation in version 1.24 of Bison.
25 #define PERL_IN_PERLY_C
30 typedef unsigned char yytype_uint8;
31 typedef signed char yytype_int8;
32 typedef unsigned short int yytype_uint16;
33 typedef short int yytype_int16;
34 typedef signed char yysigned_char;
36 /* YYINITDEPTH -- initial size of the parser's stacks. */
37 #define YYINITDEPTH 200
53 # define YY_NULLPTR NULL
56 /* contains all the parser state tables; auto-generated from perly.y */
59 # define YYSIZE_T size_t
61 /* the max number of RHS shifted elements that can make up a rule.
62 * This should really be auto-generated from the max value in yyr2[]
63 * but that involves extra work, so set it slightly higher than the
64 * current max, and assert each time yyr2[] is accessed.
65 * Used to determine if the parse stack needs extending.
73 #define YYACCEPT goto yyacceptlab
74 #define YYABORT goto yyabortlab
75 #define YYERROR goto yyerrlab1
77 /* Enable debugging if requested. */
80 # define yydebug (DEBUG_p_TEST)
82 # define YYFPRINTF PerlIO_printf
84 # define YYDPRINTF(Args) \
90 # define YYDSYMPRINTF(Title, Token, Value) \
93 YYFPRINTF (Perl_debug_log, "%s ", Title); \
94 yysymprint (aTHX_ Perl_debug_log, Token, Value); \
95 YYFPRINTF (Perl_debug_log, "\n"); \
99 /*--------------------------------.
100 | Print this symbol on YYOUTPUT. |
101 `--------------------------------*/
104 yysymprint(pTHX_ PerlIO * const yyoutput, int yytype, const YYSTYPE * const yyvaluep)
107 if (yytype < YYNTOKENS) {
108 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
110 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
112 YYFPRINTF (yyoutput, "0x%" UVxf, (UV)yyvaluep->ival);
116 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
118 YYFPRINTF (yyoutput, ")");
123 * print the top 8 items on the parse stack.
127 yy_stack_print (pTHX_ const yy_parser *parser)
129 const yy_stack_frame *ps, *min;
131 min = parser->ps - 8 + 1;
132 if (min <= parser->stack)
133 min = parser->stack + 1;
135 PerlIO_printf(Perl_debug_log, "\nindex:");
136 for (ps = min; ps <= parser->ps; ps++)
137 PerlIO_printf(Perl_debug_log, " %8d", (int)(ps - parser->stack));
139 PerlIO_printf(Perl_debug_log, "\nstate:");
140 for (ps = min; ps <= parser->ps; ps++)
141 PerlIO_printf(Perl_debug_log, " %8d", ps->state);
143 PerlIO_printf(Perl_debug_log, "\ntoken:");
144 for (ps = min; ps <= parser->ps; ps++)
145 PerlIO_printf(Perl_debug_log, " %8.8s", ps->name);
147 PerlIO_printf(Perl_debug_log, "\nvalue:");
148 for (ps = min; ps <= parser->ps; ps++) {
149 switch (yy_type_tab[yystos[ps->state]]) {
151 PerlIO_printf(Perl_debug_log, " %8.8s",
153 ? PL_op_name[ps->val.opval->op_type]
158 PerlIO_printf(Perl_debug_log, " %8" IVdf, (IV)ps->val.ival);
161 PerlIO_printf(Perl_debug_log, " %8" UVxf, (UV)ps->val.ival);
164 PerlIO_printf(Perl_debug_log, "\n\n");
167 # define YY_STACK_PRINT(parser) \
169 if (yydebug && DEBUG_v_TEST) \
170 yy_stack_print (aTHX_ parser); \
174 /*------------------------------------------------.
175 | Report that the YYRULE is going to be reduced. |
176 `------------------------------------------------*/
179 yy_reduce_print (pTHX_ int yyrule)
182 const unsigned int yylineno = yyrline[yyrule];
183 YYFPRINTF (Perl_debug_log, "Reducing stack by rule %d (line %u), ",
184 yyrule - 1, yylineno);
185 /* Print the symbols being reduced, and their result. */
186 #if PERL_BISON_VERSION >= 30000 /* 3.0+ */
187 for (yyi = 0; yyi < yyr2[yyrule]; yyi++)
188 YYFPRINTF (Perl_debug_log, "%s ",
189 yytname [yystos[(PL_parser->ps)[yyi + 1 - yyr2[yyrule]].state]]);
191 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
192 YYFPRINTF (Perl_debug_log, "%s ", yytname [yyrhs[yyi]]);
194 YYFPRINTF (Perl_debug_log, "-> %s\n", yytname [yyr1[yyrule]]);
197 # define YY_REDUCE_PRINT(Rule) \
200 yy_reduce_print (aTHX_ Rule); \
203 #else /* !DEBUGGING */
204 # define YYDPRINTF(Args)
205 # define YYDSYMPRINTF(Title, Token, Value)
206 # define YY_STACK_PRINT(parser)
207 # define YY_REDUCE_PRINT(Rule)
208 #endif /* !DEBUGGING */
210 /* called during cleanup (via SAVEDESTRUCTOR_X) to free any items on the
211 * parse stack, thus avoiding leaks if we die */
214 S_clear_yystack(pTHX_ const yy_parser *parser)
216 yy_stack_frame *ps = parser->ps;
222 YYDPRINTF ((Perl_debug_log, "clearing the parse stack\n"));
224 for (i=0; i< parser->yylen; i++) {
225 SvREFCNT_dec(ps[-i].compcv);
229 /* now free whole the stack, including the just-reduced ops */
231 while (ps > parser->stack) {
232 LEAVE_SCOPE(ps->savestack_ix);
233 if (yy_type_tab[yystos[ps->state]] == toketype_opval
236 if (ps->compcv && (ps->compcv != PL_compcv)) {
237 PL_compcv = ps->compcv;
238 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
239 PL_comppad_name = PadlistNAMES(CvPADLIST(PL_compcv));
241 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
242 op_free(ps->val.opval);
244 SvREFCNT_dec(ps->compcv);
248 Safefree(parser->stack);
257 Perl_yyparse (pTHX_ int gramtype)
264 /* Lookahead token as an internal (translated) token number. */
267 yy_parser *parser; /* the parser object */
268 yy_stack_frame *ps; /* current parser stack frame */
270 #define YYPOPSTACK parser->ps = --ps
271 #define YYPUSHSTACK parser->ps = ++ps
273 /* The variable used to return semantic value and location from the
274 action routines: ie $$. */
277 YYDPRINTF ((Perl_debug_log, "Starting parse\n"));
281 ENTER; /* force parser state cleanup/restoration before we return */
282 SAVEPPTR(parser->yylval.pval);
283 SAVEINT(parser->yychar);
284 SAVEINT(parser->yyerrstatus);
285 SAVEINT(parser->yylen);
286 SAVEVPTR(parser->stack);
287 SAVEVPTR(parser->stack_maxbase);
288 SAVEVPTR(parser->ps);
290 /* initialise state for this parse */
291 parser->yychar = gramtype;
292 yytoken = YYTRANSLATE(NATIVE_TO_UNI(parser->yychar));
294 parser->yyerrstatus = 0;
296 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
297 parser->stack_maxbase = parser->stack + YYINITDEPTH - YY_MAXRULE;
298 ps = parser->ps = parser->stack;
300 SAVEDESTRUCTOR_X(S_clear_yystack, parser);
303 /* main loop: shift some tokens, then reduce when possible */
305 /* grow the stack to accommodate longest possible rule */
306 if (ps >= parser->stack_maxbase) {
307 Size_t pos = ps - parser->stack;
308 Size_t newsize = 2 * (parser->stack_maxbase + YY_MAXRULE
310 /* this will croak on insufficient memory */
311 Renew(parser->stack, newsize, yy_stack_frame);
312 ps = parser->ps = parser->stack + pos;
313 parser->stack_maxbase = parser->stack + newsize - YY_MAXRULE;
315 YYDPRINTF((Perl_debug_log,
316 "parser stack size increased to %lu frames\n",
317 (unsigned long int)newsize));
321 /* shift a token, or quit when it's possible to reduce */
323 assert(ps < parser->stack_maxbase + YY_MAXRULE);
326 YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
330 /* Do appropriate processing given the current state. Read a
331 * lookahead token if we need one and don't already have one.
334 /* First try to decide what to do without reference to
335 * lookahead token. */
337 yyn = yypact[yystate];
338 if (yyn == YYPACT_NINF)
341 /* Not known => get a lookahead token if don't already have
342 * one. YYCHAR is either YYEMPTY or YYEOF or a valid
343 * lookahead symbol. */
345 if (parser->yychar == YYEMPTY) {
346 YYDPRINTF ((Perl_debug_log, "Reading a token:\n"));
347 parser->yychar = yylex();
348 assert(parser->yychar >= 0);
349 if (parser->yychar == YYEOF) {
350 YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
352 /* perly.tab is shipped based on an ASCII system, so need
353 * to index it with characters translated to ASCII.
354 * Although it's not designed for this purpose, we can use
355 * NATIVE_TO_UNI here. It returns its argument on ASCII
356 * platforms, and on EBCDIC translates native to ascii in
357 * the 0-255 range, leaving everything else unchanged.
358 * This jibes with yylex() returning some bare characters
359 * in that range, but all tokens it returns are either 0,
360 * or above 255. There could be a problem if NULs weren't
361 * 0, or were ever returned as raw chars by yylex() */
362 yytoken = YYTRANSLATE(NATIVE_TO_UNI(parser->yychar));
365 /* make sure no-ones changed yychar since the last call to yylex */
366 assert(yytoken == YYTRANSLATE(NATIVE_TO_UNI(parser->yychar)));
367 YYDSYMPRINTF("lookahead token is", yytoken, &parser->yylval);
370 /* If the proper action on seeing token YYTOKEN is to reduce or to
371 * detect an error, take that action.
372 * Casting yyn to unsigned allows a >=0 test to be included as
373 * part of the <=YYLAST test for speed */
375 if ((unsigned int)yyn > YYLAST || yycheck[yyn] != yytoken) {
377 /* do the default action for the current state. */
378 yyn = yydefact[yystate];
381 break; /* time to reduce */
386 if (yyn == 0 || yyn == YYTABLE_NINF)
389 break; /* time to reduce */
395 /* Shift the lookahead token. */
396 YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));
398 /* Discard the token being shifted unless it is eof. */
399 if (parser->yychar != YYEOF)
400 parser->yychar = YYEMPTY;
404 ps->val = parser->yylval;
405 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
406 ps->savestack_ix = PL_savestack_ix;
408 ps->name = (const char *)(yytname[yytoken]);
411 /* Count tokens shifted since error; after three, turn off error
413 if (parser->yyerrstatus)
414 parser->yyerrstatus--;
420 /* yyn is the number of a rule to reduce with. */
421 parser->yylen = yyr2[yyn];
422 assert(parser->yylen <= YY_MAXRULE); /* see defn of YY_MAXRULE above */
424 /* If YYLEN is nonzero, implement the default value of the action:
427 Otherwise, the following line sets YYVAL to garbage.
428 This behavior is undocumented and Bison
429 users should not rely upon it. Assigning to YYVAL
430 unconditionally makes the parser a bit smaller, and it avoids a
431 GCC warning that YYVAL may be used uninitialized. */
432 yyval = ps[1-parser->yylen].val;
434 YY_STACK_PRINT(parser);
435 YY_REDUCE_PRINT (yyn);
439 /* contains all the rule actions; auto-generated from perly.y */
446 for (i=0; i< parser->yylen; i++) {
447 SvREFCNT_dec(ps[-i].compcv);
451 parser->ps = ps -= (parser->yylen-1);
453 /* Now shift the result of the reduction. Determine what state
454 that goes to, based on the state we popped back to and the rule
455 number reduced by. */
458 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
459 ps->savestack_ix = PL_savestack_ix;
461 ps->name = (const char *)(yytname [yyr1[yyn]]);
466 yystate = yypgoto[yyn - YYNTOKENS] + ps[-1].state;
467 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == ps[-1].state)
468 yystate = yytable[yystate];
470 yystate = yydefgoto[yyn - YYNTOKENS];
476 /*------------------------------------.
477 | yyerrlab -- here on detecting error |
478 `------------------------------------*/
480 /* If not already recovering from an error, report this error. */
481 if (!parser->yyerrstatus) {
482 yyerror ("syntax error");
486 if (parser->yyerrstatus == 3) {
487 /* If just tried and failed to reuse lookahead token after an
488 error, discard it. */
490 /* Return failure if at end of input. */
491 if (parser->yychar == YYEOF) {
492 /* Pop the error token. */
493 SvREFCNT_dec(ps->compcv);
495 /* Pop the rest of the stack. */
496 while (ps > parser->stack) {
497 YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
498 LEAVE_SCOPE(ps->savestack_ix);
499 if (yy_type_tab[yystos[ps->state]] == toketype_opval
502 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
503 if (ps->compcv != PL_compcv) {
504 PL_compcv = ps->compcv;
505 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
507 op_free(ps->val.opval);
509 SvREFCNT_dec(ps->compcv);
515 YYDSYMPRINTF ("Error: discarding", yytoken, &parser->yylval);
516 parser->yychar = YYEMPTY;
520 /* Else will try to reuse lookahead token after shifting the error
525 /*----------------------------------------------------.
526 | yyerrlab1 -- error raised explicitly by an action. |
527 `----------------------------------------------------*/
529 parser->yyerrstatus = 3; /* Each real token shifted decrements this. */
532 yyn = yypact[yystate];
533 if (yyn != YYPACT_NINF) {
535 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
542 /* Pop the current state because it cannot handle the error token. */
543 if (ps == parser->stack)
546 YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
547 LEAVE_SCOPE(ps->savestack_ix);
548 if (yy_type_tab[yystos[ps->state]] == toketype_opval && ps->val.opval) {
549 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
550 if (ps->compcv != PL_compcv) {
551 PL_compcv = ps->compcv;
552 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
554 op_free(ps->val.opval);
556 SvREFCNT_dec(ps->compcv);
560 YY_STACK_PRINT(parser);
566 YYDPRINTF ((Perl_debug_log, "Shifting error token, "));
570 ps->val = parser->yylval;
571 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
572 ps->savestack_ix = PL_savestack_ix;
580 /*-------------------------------------.
581 | yyacceptlab -- YYACCEPT comes here. |
582 `-------------------------------------*/
585 for (ps=parser->ps; ps > parser->stack; ps--) {
586 SvREFCNT_dec(ps->compcv);
588 parser->ps = parser->stack; /* disable cleanup */
591 /*-----------------------------------.
592 | yyabortlab -- YYABORT comes here. |
593 `-----------------------------------*/
599 LEAVE; /* force parser stack cleanup before we return */
604 * ex: set ts=8 sts=4 sw=4 et: