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
29 typedef unsigned char yytype_uint8;
30 typedef signed char yytype_int8;
31 typedef unsigned short int yytype_uint16;
32 typedef short int yytype_int16;
33 typedef signed char yysigned_char;
35 /* YYINITDEPTH -- initial size of the parser's stacks. */
36 #define YYINITDEPTH 200
51 /* contains all the parser state tables; auto-generated from perly.y */
54 # define YYSIZE_T size_t
59 #define YYACCEPT goto yyacceptlab
60 #define YYABORT goto yyabortlab
61 #define YYERROR goto yyerrlab1
63 /* Enable debugging if requested. */
66 # define yydebug (DEBUG_p_TEST)
68 # define YYFPRINTF PerlIO_printf
70 # define YYDPRINTF(Args) \
76 # define YYDSYMPRINTF(Title, Token, Value) \
79 YYFPRINTF (Perl_debug_log, "%s ", Title); \
80 yysymprint (aTHX_ Perl_debug_log, Token, Value); \
81 YYFPRINTF (Perl_debug_log, "\n"); \
85 /*--------------------------------.
86 | Print this symbol on YYOUTPUT. |
87 `--------------------------------*/
90 yysymprint(pTHX_ PerlIO * const yyoutput, int yytype, const YYSTYPE * const yyvaluep)
93 if (yytype < YYNTOKENS) {
94 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
96 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
98 YYFPRINTF (yyoutput, "0x%"UVxf, (UV)yyvaluep->ival);
102 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
104 YYFPRINTF (yyoutput, ")");
109 * print the top 8 items on the parse stack.
113 yy_stack_print (pTHX_ const yy_parser *parser)
115 const yy_stack_frame *ps, *min;
117 min = parser->ps - 8 + 1;
118 if (min <= parser->stack)
119 min = parser->stack + 1;
121 PerlIO_printf(Perl_debug_log, "\nindex:");
122 for (ps = min; ps <= parser->ps; ps++)
123 PerlIO_printf(Perl_debug_log, " %8d", (int)(ps - parser->stack));
125 PerlIO_printf(Perl_debug_log, "\nstate:");
126 for (ps = min; ps <= parser->ps; ps++)
127 PerlIO_printf(Perl_debug_log, " %8d", ps->state);
129 PerlIO_printf(Perl_debug_log, "\ntoken:");
130 for (ps = min; ps <= parser->ps; ps++)
131 PerlIO_printf(Perl_debug_log, " %8.8s", ps->name);
133 PerlIO_printf(Perl_debug_log, "\nvalue:");
134 for (ps = min; ps <= parser->ps; ps++) {
135 switch (yy_type_tab[yystos[ps->state]]) {
137 PerlIO_printf(Perl_debug_log, " %8.8s",
139 ? PL_op_name[ps->val.opval->op_type]
144 PerlIO_printf(Perl_debug_log, " %8"IVdf, (IV)ps->val.ival);
147 PerlIO_printf(Perl_debug_log, " %8"UVxf, (UV)ps->val.ival);
150 PerlIO_printf(Perl_debug_log, "\n\n");
153 # define YY_STACK_PRINT(parser) \
155 if (yydebug && DEBUG_v_TEST) \
156 yy_stack_print (aTHX_ parser); \
160 /*------------------------------------------------.
161 | Report that the YYRULE is going to be reduced. |
162 `------------------------------------------------*/
165 yy_reduce_print (pTHX_ int yyrule)
168 const unsigned int yylineno = yyrline[yyrule];
169 YYFPRINTF (Perl_debug_log, "Reducing stack by rule %d (line %u), ",
170 yyrule - 1, yylineno);
171 /* Print the symbols being reduced, and their result. */
172 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
173 YYFPRINTF (Perl_debug_log, "%s ", yytname [yyrhs[yyi]]);
174 YYFPRINTF (Perl_debug_log, "-> %s\n", yytname [yyr1[yyrule]]);
177 # define YY_REDUCE_PRINT(Rule) \
180 yy_reduce_print (aTHX_ Rule); \
183 #else /* !DEBUGGING */
184 # define YYDPRINTF(Args)
185 # define YYDSYMPRINTF(Title, Token, Value)
186 # define YY_STACK_PRINT(parser)
187 # define YY_REDUCE_PRINT(Rule)
188 #endif /* !DEBUGGING */
190 /* called during cleanup (via SAVEDESTRUCTOR_X) to free any items on the
191 * parse stack, thus avoiding leaks if we die */
194 S_clear_yystack(pTHX_ const yy_parser *parser)
196 yy_stack_frame *ps = parser->ps;
202 YYDPRINTF ((Perl_debug_log, "clearing the parse stack\n"));
204 for (i=0; i< parser->yylen; i++) {
205 SvREFCNT_dec(ps[-i].compcv);
209 /* now free whole the stack, including the just-reduced ops */
211 while (ps > parser->stack) {
212 LEAVE_SCOPE(ps->savestack_ix);
213 if (yy_type_tab[yystos[ps->state]] == toketype_opval
216 if (ps->compcv != PL_compcv) {
217 PL_compcv = ps->compcv;
218 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
219 PL_comppad_name = PadlistNAMES(CvPADLIST(PL_compcv));
221 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
222 op_free(ps->val.opval);
224 SvREFCNT_dec(ps->compcv);
228 Safefree(parser->stack);
237 Perl_yyparse (pTHX_ int gramtype)
244 /* Lookahead token as an internal (translated) token number. */
247 yy_parser *parser; /* the parser object */
248 yy_stack_frame *ps; /* current parser stack frame */
250 #define YYPOPSTACK parser->ps = --ps
251 #define YYPUSHSTACK parser->ps = ++ps
253 /* The variable used to return semantic value and location from the
254 action routines: ie $$. */
257 YYDPRINTF ((Perl_debug_log, "Starting parse\n"));
261 ENTER; /* force parser state cleanup/restoration before we return */
262 SAVEPPTR(parser->yylval.pval);
263 SAVEINT(parser->yychar);
264 SAVEINT(parser->yyerrstatus);
265 SAVEINT(parser->stack_size);
266 SAVEINT(parser->yylen);
267 SAVEVPTR(parser->stack);
268 SAVEVPTR(parser->ps);
270 /* initialise state for this parse */
271 parser->yychar = gramtype;
272 parser->yyerrstatus = 0;
273 parser->stack_size = YYINITDEPTH;
275 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
276 ps = parser->ps = parser->stack;
278 SAVEDESTRUCTOR_X(S_clear_yystack, parser);
280 /*------------------------------------------------------------.
281 | yynewstate -- Push a new state, which is found in yystate. |
282 `------------------------------------------------------------*/
287 YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
292 size_t size = ps - parser->stack + 1;
294 /* grow the stack? We always leave 1 spare slot,
295 * in case of a '' -> 'foo' reduction */
297 if (size >= (size_t)parser->stack_size - 1) {
298 /* this will croak on insufficient memory */
299 parser->stack_size *= 2;
300 Renew(parser->stack, parser->stack_size, yy_stack_frame);
301 ps = parser->ps = parser->stack + size -1;
303 YYDPRINTF((Perl_debug_log,
304 "parser stack size increased to %lu frames\n",
305 (unsigned long int)parser->stack_size));
309 /* Do appropriate processing given the current state. */
310 /* Read a lookahead token if we need one and don't already have one. */
312 /* First try to decide what to do without reference to lookahead token. */
314 yyn = yypact[yystate];
315 if (yyn == YYPACT_NINF)
318 /* Not known => get a lookahead token if don't already have one. */
320 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
321 if (parser->yychar == YYEMPTY) {
322 YYDPRINTF ((Perl_debug_log, "Reading a token: "));
323 parser->yychar = yylex();
325 /* perly.tab is shipped based on an ASCII system; if it were to be regenerated
326 * on a platform that doesn't use ASCII, this translation back would need to be
329 if (parser->yychar >= 0 && parser->yychar < 255) {
330 parser->yychar = NATIVE_TO_LATIN1(parser->yychar);
335 if (parser->yychar <= YYEOF) {
336 parser->yychar = yytoken = YYEOF;
337 YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
340 yytoken = YYTRANSLATE (parser->yychar);
341 YYDSYMPRINTF ("Next token is", yytoken, &parser->yylval);
344 /* If the proper action on seeing token YYTOKEN is to reduce or to
345 detect an error, take that action. */
347 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
351 if (yyn == 0 || yyn == YYTABLE_NINF)
360 /* Shift the lookahead token. */
361 YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));
363 /* Discard the token being shifted unless it is eof. */
364 if (parser->yychar != YYEOF)
365 parser->yychar = YYEMPTY;
369 ps->val = parser->yylval;
370 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
371 ps->savestack_ix = PL_savestack_ix;
373 ps->name = (const char *)(yytname[yytoken]);
376 /* Count tokens shifted since error; after three, turn off error
378 if (parser->yyerrstatus)
379 parser->yyerrstatus--;
384 /*-----------------------------------------------------------.
385 | yydefault -- do the default action for the current state. |
386 `-----------------------------------------------------------*/
388 yyn = yydefact[yystate];
394 /*-----------------------------.
395 | yyreduce -- Do a reduction. |
396 `-----------------------------*/
398 /* yyn is the number of a rule to reduce with. */
399 parser->yylen = yyr2[yyn];
401 /* If YYLEN is nonzero, implement the default value of the action:
404 Otherwise, the following line sets YYVAL to garbage.
405 This behavior is undocumented and Bison
406 users should not rely upon it. Assigning to YYVAL
407 unconditionally makes the parser a bit smaller, and it avoids a
408 GCC warning that YYVAL may be used uninitialized. */
409 yyval = ps[1-parser->yylen].val;
411 YY_STACK_PRINT(parser);
412 YY_REDUCE_PRINT (yyn);
416 /* contains all the rule actions; auto-generated from perly.y */
423 for (i=0; i< parser->yylen; i++) {
424 SvREFCNT_dec(ps[-i].compcv);
428 parser->ps = ps -= (parser->yylen-1);
430 /* Now shift the result of the reduction. Determine what state
431 that goes to, based on the state we popped back to and the rule
432 number reduced by. */
435 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
436 ps->savestack_ix = PL_savestack_ix;
438 ps->name = (const char *)(yytname [yyr1[yyn]]);
443 yystate = yypgoto[yyn - YYNTOKENS] + ps[-1].state;
444 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == ps[-1].state)
445 yystate = yytable[yystate];
447 yystate = yydefgoto[yyn - YYNTOKENS];
453 /*------------------------------------.
454 | yyerrlab -- here on detecting error |
455 `------------------------------------*/
457 /* If not already recovering from an error, report this error. */
458 if (!parser->yyerrstatus) {
459 yyerror ("syntax error");
463 if (parser->yyerrstatus == 3) {
464 /* If just tried and failed to reuse lookahead token after an
465 error, discard it. */
467 /* Return failure if at end of input. */
468 if (parser->yychar == YYEOF) {
469 /* Pop the error token. */
470 SvREFCNT_dec(ps->compcv);
472 /* Pop the rest of the stack. */
473 while (ps > parser->stack) {
474 YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
475 LEAVE_SCOPE(ps->savestack_ix);
476 if (yy_type_tab[yystos[ps->state]] == toketype_opval
479 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
480 if (ps->compcv != PL_compcv) {
481 PL_compcv = ps->compcv;
482 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
484 op_free(ps->val.opval);
486 SvREFCNT_dec(ps->compcv);
492 YYDSYMPRINTF ("Error: discarding", yytoken, &parser->yylval);
493 parser->yychar = YYEMPTY;
497 /* Else will try to reuse lookahead token after shifting the error
502 /*----------------------------------------------------.
503 | yyerrlab1 -- error raised explicitly by an action. |
504 `----------------------------------------------------*/
506 parser->yyerrstatus = 3; /* Each real token shifted decrements this. */
509 yyn = yypact[yystate];
510 if (yyn != YYPACT_NINF) {
512 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
519 /* Pop the current state because it cannot handle the error token. */
520 if (ps == parser->stack)
523 YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
524 LEAVE_SCOPE(ps->savestack_ix);
525 if (yy_type_tab[yystos[ps->state]] == toketype_opval && ps->val.opval) {
526 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
527 if (ps->compcv != PL_compcv) {
528 PL_compcv = ps->compcv;
529 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
531 op_free(ps->val.opval);
533 SvREFCNT_dec(ps->compcv);
537 YY_STACK_PRINT(parser);
543 YYDPRINTF ((Perl_debug_log, "Shifting error token, "));
547 ps->val = parser->yylval;
548 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
549 ps->savestack_ix = PL_savestack_ix;
557 /*-------------------------------------.
558 | yyacceptlab -- YYACCEPT comes here. |
559 `-------------------------------------*/
562 for (ps=parser->ps; ps > parser->stack; ps--) {
563 SvREFCNT_dec(ps->compcv);
565 parser->ps = parser->stack; /* disable cleanup */
568 /*-----------------------------------.
569 | yyabortlab -- YYABORT comes here. |
570 `-----------------------------------*/
576 LEAVE; /* force parser stack cleanup before we return */
582 * c-indentation-style: bsd
584 * indent-tabs-mode: nil
587 * ex: set ts=8 sts=4 sw=4 et: