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.
22 * Note that this file is also #included in madly.c, to allow compilation
23 * of a second parser, Perl_madparse, that is identical to Perl_yyparse,
24 * but which includes extra code for dumping the parse tree.
25 * This is controlled by the PERL_IN_MADLY_C define.
29 #define PERL_IN_PERLY_C
32 typedef unsigned char yytype_uint8;
33 typedef signed char yytype_int8;
34 typedef unsigned short int yytype_uint16;
35 typedef short int yytype_int16;
36 typedef signed char yysigned_char;
38 /* YYINITDEPTH -- initial size of the parser's stacks. */
39 #define YYINITDEPTH 200
47 /* contains all the parser state tables; auto-generated from perly.y */
50 # define YYSIZE_T size_t
55 #define YYACCEPT goto yyacceptlab
56 #define YYABORT goto yyabortlab
57 #define YYERROR goto yyerrlab1
59 /* Enable debugging if requested. */
62 # define yydebug (DEBUG_p_TEST)
64 # define YYFPRINTF PerlIO_printf
66 # define YYDPRINTF(Args) \
72 # define YYDSYMPRINTF(Title, Token, Value) \
75 YYFPRINTF (Perl_debug_log, "%s ", Title); \
76 yysymprint (aTHX_ Perl_debug_log, Token, Value); \
77 YYFPRINTF (Perl_debug_log, "\n"); \
81 /*--------------------------------.
82 | Print this symbol on YYOUTPUT. |
83 `--------------------------------*/
86 yysymprint(pTHX_ PerlIO * const yyoutput, int yytype, const YYSTYPE * const yyvaluep)
88 if (yytype < YYNTOKENS) {
89 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
91 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
93 YYFPRINTF (yyoutput, "0x%"UVxf, (UV)yyvaluep->ival);
97 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
99 YYFPRINTF (yyoutput, ")");
104 * print the top 8 items on the parse stack.
108 yy_stack_print (pTHX_ const yy_parser *parser)
110 const yy_stack_frame *ps, *min;
112 min = parser->ps - 8 + 1;
113 if (min <= parser->stack)
114 min = parser->stack + 1;
116 PerlIO_printf(Perl_debug_log, "\nindex:");
117 for (ps = min; ps <= parser->ps; ps++)
118 PerlIO_printf(Perl_debug_log, " %8d", (int)(ps - parser->stack));
120 PerlIO_printf(Perl_debug_log, "\nstate:");
121 for (ps = min; ps <= parser->ps; ps++)
122 PerlIO_printf(Perl_debug_log, " %8d", ps->state);
124 PerlIO_printf(Perl_debug_log, "\ntoken:");
125 for (ps = min; ps <= parser->ps; ps++)
126 PerlIO_printf(Perl_debug_log, " %8.8s", ps->name);
128 PerlIO_printf(Perl_debug_log, "\nvalue:");
129 for (ps = min; ps <= parser->ps; ps++) {
130 switch (yy_type_tab[yystos[ps->state]]) {
132 PerlIO_printf(Perl_debug_log, " %8.8s",
134 ? PL_op_name[ps->val.opval->op_type]
138 #ifndef PERL_IN_MADLY_C
139 case toketype_i_tkval:
142 PerlIO_printf(Perl_debug_log, " %8"IVdf, (IV)ps->val.ival);
145 PerlIO_printf(Perl_debug_log, " %8"UVxf, (UV)ps->val.ival);
148 PerlIO_printf(Perl_debug_log, "\n\n");
151 # define YY_STACK_PRINT(parser) \
153 if (yydebug && DEBUG_v_TEST) \
154 yy_stack_print (aTHX_ parser); \
158 /*------------------------------------------------.
159 | Report that the YYRULE is going to be reduced. |
160 `------------------------------------------------*/
163 yy_reduce_print (pTHX_ int yyrule)
166 const unsigned int yylineno = yyrline[yyrule];
167 YYFPRINTF (Perl_debug_log, "Reducing stack by rule %d (line %u), ",
168 yyrule - 1, yylineno);
169 /* Print the symbols being reduced, and their result. */
170 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
171 YYFPRINTF (Perl_debug_log, "%s ", yytname [yyrhs[yyi]]);
172 YYFPRINTF (Perl_debug_log, "-> %s\n", yytname [yyr1[yyrule]]);
175 # define YY_REDUCE_PRINT(Rule) \
178 yy_reduce_print (aTHX_ Rule); \
181 #else /* !DEBUGGING */
182 # define YYDPRINTF(Args)
183 # define YYDSYMPRINTF(Title, Token, Value)
184 # define YY_STACK_PRINT(parser)
185 # define YY_REDUCE_PRINT(Rule)
186 #endif /* !DEBUGGING */
188 /* called during cleanup (via SAVEDESTRUCTOR_X) to free any items on the
189 * parse stack, thus avoiding leaks if we die */
192 S_clear_yystack(pTHX_ const yy_parser *parser)
194 yy_stack_frame *ps = parser->ps;
200 YYDPRINTF ((Perl_debug_log, "clearing the parse stack\n"));
202 for (i=0; i< parser->yylen; i++) {
203 SvREFCNT_dec(ps[-i].compcv);
207 /* now free whole the stack, including the just-reduced ops */
209 while (ps > parser->stack) {
210 LEAVE_SCOPE(ps->savestack_ix);
211 if (yy_type_tab[yystos[ps->state]] == toketype_opval
214 if (ps->compcv != PL_compcv) {
215 PL_compcv = ps->compcv;
216 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
218 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
219 op_free(ps->val.opval);
221 SvREFCNT_dec(ps->compcv);
225 Safefree(parser->stack);
234 #ifdef PERL_IN_MADLY_C
235 Perl_madparse (pTHX_ int gramtype)
237 Perl_yyparse (pTHX_ int gramtype)
245 /* Lookahead token as an internal (translated) token number. */
248 yy_parser *parser; /* the parser object */
249 yy_stack_frame *ps; /* current parser stack frame */
251 #define YYPOPSTACK parser->ps = --ps
252 #define YYPUSHSTACK parser->ps = ++ps
254 /* The variable used to return semantic value and location from the
255 action routines: ie $$. */
258 #ifndef PERL_IN_MADLY_C
261 return madparse(gramtype);
265 YYDPRINTF ((Perl_debug_log, "Starting parse\n"));
269 ENTER; /* force parser state cleanup/restoration before we return */
270 SAVEPPTR(parser->yylval.pval);
271 SAVEINT(parser->yychar);
272 SAVEINT(parser->yyerrstatus);
273 SAVEINT(parser->stack_size);
274 SAVEINT(parser->yylen);
275 SAVEVPTR(parser->stack);
276 SAVEVPTR(parser->ps);
278 /* initialise state for this parse */
279 parser->yychar = gramtype;
280 parser->yyerrstatus = 0;
281 parser->stack_size = YYINITDEPTH;
283 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
284 ps = parser->ps = parser->stack;
286 SAVEDESTRUCTOR_X(S_clear_yystack, parser);
288 /*------------------------------------------------------------.
289 | yynewstate -- Push a new state, which is found in yystate. |
290 `------------------------------------------------------------*/
295 YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
300 size_t size = ps - parser->stack + 1;
302 /* grow the stack? We always leave 1 spare slot,
303 * in case of a '' -> 'foo' reduction */
305 if (size >= (size_t)parser->stack_size - 1) {
306 /* this will croak on insufficient memory */
307 parser->stack_size *= 2;
308 Renew(parser->stack, parser->stack_size, yy_stack_frame);
309 ps = parser->ps = parser->stack + size -1;
311 YYDPRINTF((Perl_debug_log,
312 "parser stack size increased to %lu frames\n",
313 (unsigned long int)parser->stack_size));
317 /* Do appropriate processing given the current state. */
318 /* Read a lookahead token if we need one and don't already have one. */
320 /* First try to decide what to do without reference to lookahead token. */
322 yyn = yypact[yystate];
323 if (yyn == YYPACT_NINF)
326 /* Not known => get a lookahead token if don't already have one. */
328 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
329 if (parser->yychar == YYEMPTY) {
330 YYDPRINTF ((Perl_debug_log, "Reading a token: "));
331 #ifdef PERL_IN_MADLY_C
332 parser->yychar = PL_madskills ? madlex() : yylex();
334 parser->yychar = yylex();
338 if (parser->yychar >= 0 && parser->yychar < 255) {
339 parser->yychar = NATIVE_TO_ASCII(parser->yychar);
344 if (parser->yychar <= YYEOF) {
345 parser->yychar = yytoken = YYEOF;
346 YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
349 yytoken = YYTRANSLATE (parser->yychar);
350 YYDSYMPRINTF ("Next token is", yytoken, &parser->yylval);
353 /* If the proper action on seeing token YYTOKEN is to reduce or to
354 detect an error, take that action. */
356 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
360 if (yyn == 0 || yyn == YYTABLE_NINF)
369 /* Shift the lookahead token. */
370 YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));
372 /* Discard the token being shifted unless it is eof. */
373 if (parser->yychar != YYEOF)
374 parser->yychar = YYEMPTY;
378 ps->val = parser->yylval;
379 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
380 ps->savestack_ix = PL_savestack_ix;
382 ps->name = (const char *)(yytname[yytoken]);
385 /* Count tokens shifted since error; after three, turn off error
387 if (parser->yyerrstatus)
388 parser->yyerrstatus--;
393 /*-----------------------------------------------------------.
394 | yydefault -- do the default action for the current state. |
395 `-----------------------------------------------------------*/
397 yyn = yydefact[yystate];
403 /*-----------------------------.
404 | yyreduce -- Do a reduction. |
405 `-----------------------------*/
407 /* yyn is the number of a rule to reduce with. */
408 parser->yylen = yyr2[yyn];
410 /* If YYLEN is nonzero, implement the default value of the action:
413 Otherwise, the following line sets YYVAL to garbage.
414 This behavior is undocumented and Bison
415 users should not rely upon it. Assigning to YYVAL
416 unconditionally makes the parser a bit smaller, and it avoids a
417 GCC warning that YYVAL may be used uninitialized. */
418 yyval = ps[1-parser->yylen].val;
420 YY_STACK_PRINT(parser);
421 YY_REDUCE_PRINT (yyn);
426 #define dep() deprecate("\"do\" to call subroutines")
428 #ifdef PERL_IN_MADLY_C
429 # define IVAL(i) (i)->tk_lval.ival
430 # define PVAL(p) (p)->tk_lval.pval
431 # define TOKEN_GETMAD(a,b,c) token_getmad((a),(b),(c))
432 # define TOKEN_FREE(a) token_free(a)
433 # define OP_GETMAD(a,b,c) op_getmad((a),(b),(c))
434 # define IF_MAD(a,b) (a)
440 # define TOKEN_GETMAD(a,b,c)
441 # define TOKEN_FREE(a)
442 # define OP_GETMAD(a,b,c)
443 # define IF_MAD(a,b) (b)
448 /* contains all the rule actions; auto-generated from perly.y */
455 for (i=0; i< parser->yylen; i++) {
456 SvREFCNT_dec(ps[-i].compcv);
460 parser->ps = ps -= (parser->yylen-1);
462 /* Now shift the result of the reduction. Determine what state
463 that goes to, based on the state we popped back to and the rule
464 number reduced by. */
467 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
468 ps->savestack_ix = PL_savestack_ix;
470 ps->name = (const char *)(yytname [yyr1[yyn]]);
475 yystate = yypgoto[yyn - YYNTOKENS] + ps[-1].state;
476 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == ps[-1].state)
477 yystate = yytable[yystate];
479 yystate = yydefgoto[yyn - YYNTOKENS];
485 /*------------------------------------.
486 | yyerrlab -- here on detecting error |
487 `------------------------------------*/
489 /* If not already recovering from an error, report this error. */
490 if (!parser->yyerrstatus) {
491 yyerror ("syntax error");
495 if (parser->yyerrstatus == 3) {
496 /* If just tried and failed to reuse lookahead token after an
497 error, discard it. */
499 /* Return failure if at end of input. */
500 if (parser->yychar == YYEOF) {
501 /* Pop the error token. */
502 SvREFCNT_dec(ps->compcv);
504 /* Pop the rest of the stack. */
505 while (ps > parser->stack) {
506 YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
507 LEAVE_SCOPE(ps->savestack_ix);
508 if (yy_type_tab[yystos[ps->state]] == toketype_opval
511 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
512 if (ps->compcv != PL_compcv) {
513 PL_compcv = ps->compcv;
514 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
516 op_free(ps->val.opval);
518 SvREFCNT_dec(ps->compcv);
524 YYDSYMPRINTF ("Error: discarding", yytoken, &parser->yylval);
525 if (yy_type_tab[yytoken] == toketype_opval)
526 op_free(parser->yylval.opval);
527 parser->yychar = YYEMPTY;
531 /* Else will try to reuse lookahead token after shifting the error
536 /*----------------------------------------------------.
537 | yyerrlab1 -- error raised explicitly by an action. |
538 `----------------------------------------------------*/
540 parser->yyerrstatus = 3; /* Each real token shifted decrements this. */
543 yyn = yypact[yystate];
544 if (yyn != YYPACT_NINF) {
546 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
553 /* Pop the current state because it cannot handle the error token. */
554 if (ps == parser->stack)
557 YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
558 LEAVE_SCOPE(ps->savestack_ix);
559 if (yy_type_tab[yystos[ps->state]] == toketype_opval && ps->val.opval) {
560 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
561 if (ps->compcv != PL_compcv) {
562 PL_compcv = ps->compcv;
563 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
565 op_free(ps->val.opval);
567 SvREFCNT_dec(ps->compcv);
571 YY_STACK_PRINT(parser);
577 YYDPRINTF ((Perl_debug_log, "Shifting error token, "));
581 ps->val = parser->yylval;
582 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
583 ps->savestack_ix = PL_savestack_ix;
591 /*-------------------------------------.
592 | yyacceptlab -- YYACCEPT comes here. |
593 `-------------------------------------*/
596 for (ps=parser->ps; ps > parser->stack; ps--) {
597 SvREFCNT_dec(ps->compcv);
599 parser->ps = parser->stack; /* disable cleanup */
602 /*-----------------------------------.
603 | yyabortlab -- YYABORT comes here. |
604 `-----------------------------------*/
610 LEAVE; /* force parser stack cleanup before we return */
616 * c-indentation-style: bsd
618 * indent-tabs-mode: nil
621 * ex: set ts=8 sts=4 sw=4 et: