3 * Copyright (c) 2004, 2005, 2006 Larry Wall and others
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
8 * Note that this file was originally generated as an output from
9 * GNU bison version 1.875, but now the code is statically maintained
10 * and edited; the bits that are dependent on perly.y are now
11 * #included from the files perly.tab and perly.act.
13 * Here is an important copyright statement from the original, generated
16 * As a special exception, when this file is copied by Bison into a
17 * Bison output file, you may use that output file without
18 * restriction. This special exception was added by the Free
19 * Software Foundation in version 1.24 of Bison.
21 * Note that this file is also #included in madly.c, to allow compilation
22 * of a second parser, Perl_madparse, that is identical to Perl_yyparse,
23 * but which includes extra code for dumping the parse tree.
24 * This is controlled by the PERL_IN_MADLY_C define.
29 /* allow stack size to grow effectively without limit */
30 #define YYMAXDEPTH 10000000
33 #define PERL_IN_PERLY_C
36 typedef unsigned char yytype_uint8;
37 typedef signed char yytype_int8;
38 typedef unsigned short int yytype_uint16;
39 typedef short int yytype_int16;
40 typedef signed char yysigned_char;
48 /* contains all the parser state tables; auto-generated from perly.y */
51 # define YYSIZE_T size_t
53 #define yyerrok (yyerrstatus = 0)
54 #define yyclearin (yychar = YYEMPTY)
58 #define YYACCEPT goto yyacceptlab
59 #define YYABORT goto yyabortlab
60 #define YYERROR goto yyerrlab1
63 /* Like YYERROR except do call yyerror. This remains here temporarily
64 to ease the transition to the new meaning of YYERROR, for GCC.
65 Once GCC version 2 has supplanted version 1, this can go. */
67 #define YYFAIL goto yyerrlab
69 #define YYRECOVERING() (!!yyerrstatus)
71 #define YYBACKUP(Token, Value) \
73 if (yychar == YYEMPTY && yylen == 1) { \
76 yytoken = YYTRANSLATE (yychar); \
81 yyerror ("syntax error: cannot back up"); \
89 /* Enable debugging if requested. */
92 # define yydebug (DEBUG_p_TEST)
94 # define YYFPRINTF PerlIO_printf
96 # define YYDPRINTF(Args) \
102 # define YYDSYMPRINTF(Title, Token, Value) \
105 YYFPRINTF (Perl_debug_log, "%s ", Title); \
106 yysymprint (aTHX_ Perl_debug_log, Token, Value); \
107 YYFPRINTF (Perl_debug_log, "\n"); \
111 /*--------------------------------.
112 | Print this symbol on YYOUTPUT. |
113 `--------------------------------*/
116 yysymprint(pTHX_ PerlIO * const yyoutput, int yytype, const YYSTYPE * const yyvaluep)
118 if (yytype < YYNTOKENS) {
119 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
121 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
123 YYFPRINTF (yyoutput, "0x%"UVxf, (UV)yyvaluep->ival);
127 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
129 YYFPRINTF (yyoutput, ")");
134 * print the top 8 items on the parse stack. The args have the same
135 * meanings as the local vars in yyparse() of the same name */
138 yy_stack_print (pTHX_ const short *yyss, const short *yyssp, const YYSTYPE *yyvs, const char**yyns)
142 int count = (int)(yyssp - yyss);
145 start = count - 8 + 1;
149 PerlIO_printf(Perl_debug_log, "\nindex:");
150 for (i=0; i < count; i++)
151 PerlIO_printf(Perl_debug_log, " %8d", start+i);
152 PerlIO_printf(Perl_debug_log, "\nstate:");
153 for (i=0; i < count; i++)
154 PerlIO_printf(Perl_debug_log, " %8d", yyss[start+i]);
155 PerlIO_printf(Perl_debug_log, "\ntoken:");
156 for (i=0; i < count; i++)
157 PerlIO_printf(Perl_debug_log, " %8.8s", yyns[start+i]);
158 PerlIO_printf(Perl_debug_log, "\nvalue:");
159 for (i=0; i < count; i++) {
160 switch (yy_type_tab[yystos[yyss[start+i]]]) {
162 PerlIO_printf(Perl_debug_log, " %8.8s",
164 ? PL_op_name[yyvs[start+i].opval->op_type]
168 #ifndef PERL_IN_MADLY_C
169 case toketype_p_tkval:
170 PerlIO_printf(Perl_debug_log, " %8.8s",
171 yyvs[start+i].pval ? yyvs[start+i].pval : "(NULL)");
174 case toketype_i_tkval:
177 PerlIO_printf(Perl_debug_log, " %8"IVdf, yyvs[start+i].ival);
180 PerlIO_printf(Perl_debug_log, " %8"UVxf, (UV)yyvs[start+i].ival);
183 PerlIO_printf(Perl_debug_log, "\n\n");
186 # define YY_STACK_PRINT(yyss, yyssp, yyvs, yyns) \
188 if (yydebug && DEBUG_v_TEST) \
189 yy_stack_print (aTHX_ (yyss), (yyssp), (yyvs), (yyns)); \
193 /*------------------------------------------------.
194 | Report that the YYRULE is going to be reduced. |
195 `------------------------------------------------*/
198 yy_reduce_print (pTHX_ int yyrule)
201 const unsigned int yylineno = yyrline[yyrule];
202 YYFPRINTF (Perl_debug_log, "Reducing stack by rule %d (line %u), ",
203 yyrule - 1, yylineno);
204 /* Print the symbols being reduced, and their result. */
205 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
206 YYFPRINTF (Perl_debug_log, "%s ", yytname [yyrhs[yyi]]);
207 YYFPRINTF (Perl_debug_log, "-> %s\n", yytname [yyr1[yyrule]]);
210 # define YY_REDUCE_PRINT(Rule) \
213 yy_reduce_print (aTHX_ Rule); \
216 #else /* !DEBUGGING */
217 # define YYDPRINTF(Args)
218 # define YYDSYMPRINTF(Title, Token, Value)
219 # define YY_STACK_PRINT(yyss, yyssp, yyvs, yyns)
220 # define YY_REDUCE_PRINT(Rule)
221 #endif /* !DEBUGGING */
224 /* YYINITDEPTH -- initial size of the parser's stacks. */
226 # define YYINITDEPTH 200
232 # if defined (__GLIBC__) && defined (_STRING_H)
233 # define yystrlen strlen
235 /* Return the length of YYSTR. */
237 yystrlen (const char *yystr)
239 register const char *yys = yystr;
241 while (*yys++ != '\0')
244 return yys - yystr - 1;
250 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
251 # define yystpcpy stpcpy
253 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
256 yystpcpy (pTHX_ char *yydest, const char *yysrc)
258 register char *yyd = yydest;
259 register const char *yys = yysrc;
261 while ((*yyd++ = *yys++) != '\0')
269 #endif /* !YYERROR_VERBOSE */
272 /* a snapshot of the current stack position variables for use by
283 /* called during cleanup (via SAVEDESTRUCTOR_X) to free any items on the
284 * parse stack, thus avoiding leaks if we die */
287 S_clear_yystack(pTHX_ const void *p)
289 yystack_positions *y = (yystack_positions*) p;
294 YYDPRINTF ((Perl_debug_log, "clearing the parse stack\n"));
296 /* Freeing ops on the stack, and the op_latefree/op_latefreed flags:
298 * When we pop tokens off the stack during error recovery, or when
299 * we pop all the tokens off the stack after a die during a shift or
300 * reduce (ie Perl_croak somewhere in yylex(), or in one of the
301 * newFOO() functions, then its possible that some of these tokens are
302 * of type opval, pointing to an OP. All these ops are orphans; each is
303 * its own miniature subtree that has not yet been attached to a
304 * larger tree. In this case, we shoould clearly free the op (making
305 * sure, for each op we free thyat we have PL_comppad pointing to the
306 * right place for freeing any SVs attached to the op in threaded
309 * However, there is a particular problem if we die in newFOO called
310 * by a reducing action; e.g.
313 * { $$ = newFOO($1,$2,$3) }
316 * OP *newFOO { .... croak .... }
318 * In this case, when we come to clean bar baz and boz off the stack,
319 * we don't know whether newFOO() has already:
322 * * attached them to part of a larger tree
324 * To get round this problem, we set the flag op_latefree on every op
325 * that gets pushed onto the parser stack. If op_free() sees this
326 * flag, it clears the op and frees any children,, but *doesn't* free
327 * the op itself; instead it sets the op_latefreed flag. This means
328 * that we can safely call op_free() multiple times on each stack op.
329 * So, when clearing the stack, we first, for each op that was being
330 * reduced, call op_free with op_latefree=1. This ensures that all ops
331 * hanging off these op are freed, but the reducing ops themselces are
332 * just undefed. Then we set op_latefreed=0 on *all* ops on the stack
333 * and free them. A little though should convince you that this
334 * two-part approach to the reducing ops should handle all three cases
338 /* free any reducing ops (1st pass) */
340 for (i=0; i< y->yylen; i++) {
341 if (yy_type_tab[yystos[y->yyssp[-i]]] == toketype_opval
342 && y->yyvsp[-i].opval) {
343 if (y->yypsp[-i] != PL_comppad) {
344 PAD_RESTORE_LOCAL(y->yypsp[-i]);
346 op_free(y->yyvsp[-i].opval);
350 /* now free whole the stack, including the just-reduced ops */
352 while (y->yyssp > y->yyss) {
353 if (yy_type_tab[yystos[*y->yyssp]] == toketype_opval
356 if (*y->yypsp != PL_comppad) {
357 PAD_RESTORE_LOCAL(*y->yypsp);
359 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
360 y->yyvsp->opval->op_latefree = 0;
361 op_free(y->yyvsp->opval);
376 #ifdef PERL_IN_MADLY_C
383 int yychar; /* The lookahead symbol. */
384 YYSTYPE yylval; /* The semantic value of the lookahead symbol. */
385 int yynerrs; /* Number of syntax errors so far. */
386 register int yystate;
390 /* Number of tokens to shift before error messages enabled. */
392 /* Lookahead token as an internal (translated) token number. */
395 /* three stacks and their tools:
396 yyss: related to states,
397 yyvs: related to semantic values,
398 yyps: current value of PL_comppad for each state
401 Refer to the stacks thru separate pointers, to allow yyoverflow
402 to reallocate them elsewhere. */
404 /* The state stack. */
406 register short *yyssp;
408 /* The semantic value stack. */
410 register YYSTYPE *yyvsp;
415 /* for ease of re-allocation and automatic freeing, have three SVs whose
416 * SvPVX points to the stacks */
417 SV *yyss_sv, *yyvs_sv, *yyps_sv;
419 yystack_positions *ss_save;
423 /* maintain also a stack of token/rule names for debugging with -Dpv */
424 const char **yyns, **yynsp;
426 # define YYPOPSTACK (yyvsp--, yyssp--, yypsp--, yynsp--)
428 # define YYPOPSTACK (yyvsp--, yyssp--, yypsp--)
432 YYSIZE_T yystacksize = YYINITDEPTH;
434 /* The variables used to return semantic value and location from the
439 /* When reducing, the number of symbols on the RHS of the reduced
443 #ifndef PERL_IN_MADLY_C
450 YYDPRINTF ((Perl_debug_log, "Starting parse\n"));
452 ENTER; /* force stack free before we return */
453 SAVEVPTR(PL_yycharp);
454 SAVEVPTR(PL_yylvalp);
455 PL_yycharp = &yychar; /* so PL_yyerror() can access it */
456 PL_yylvalp = &yylval; /* so various functions in toke.c can access it */
458 yyss_sv = newSV(YYINITDEPTH * sizeof(short));
459 yyvs_sv = newSV(YYINITDEPTH * sizeof(YYSTYPE));
460 yyps_sv = newSV(YYINITDEPTH * sizeof(AV*));
461 ss_save_sv = newSV(sizeof(yystack_positions));
465 SAVEFREESV(ss_save_sv);
466 yyss = (short *) SvPVX(yyss_sv);
467 yyvs = (YYSTYPE *) SvPVX(yyvs_sv);
468 yyps = (AV **) SvPVX(yyps_sv);
469 ss_save = (yystack_positions *) SvPVX(ss_save_sv);
471 ss_save->yyss = NULL; /* disarm stack cleanup */
472 /* cleanup the parse stack on premature exit */
473 SAVEDESTRUCTOR_X(S_clear_yystack, (void*) ss_save);
475 /* note that elements zero of yyvs and yyns are not used */
480 yyns_sv = newSV(YYINITDEPTH * sizeof(char *));
482 /* XXX This seems strange to cast char * to char ** */
483 yyns = (const char **) SvPVX(yyns_sv);
490 yychar = YYEMPTY; /* Cause a token to be read. */
494 /*------------------------------------------------------------.
495 | yynewstate -- Push a new state, which is found in yystate. |
496 `------------------------------------------------------------*/
498 /* In all cases, when you get here, the value and location stacks
499 have just been pushed. so pushing a state here evens the stacks.
504 YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
507 if (yy_type_tab[yystos[yystate]] == toketype_opval && yyvsp->opval) {
508 yyvsp->opval->op_latefree = 1;
509 yyvsp->opval->op_latefreed = 0;
512 ss_save->yyss = yyss;
513 ss_save->yyssp = yyssp;
514 ss_save->yyvsp = yyvsp;
515 ss_save->yypsp = yypsp;
518 if (yyss + yystacksize - 1 <= yyssp) {
519 /* Get the current used size of the three stacks, in elements. */
520 const YYSIZE_T yysize = yyssp - yyss + 1;
522 /* Extend the stack our own way. */
523 if (YYMAXDEPTH <= yystacksize)
526 if (YYMAXDEPTH < yystacksize)
527 yystacksize = YYMAXDEPTH;
529 SvGROW(yyss_sv, yystacksize * sizeof(short));
530 SvGROW(yyvs_sv, yystacksize * sizeof(YYSTYPE));
531 SvGROW(yyps_sv, yystacksize * sizeof(AV*));
532 yyss = (short *) SvPVX(yyss_sv);
533 yyvs = (YYSTYPE *) SvPVX(yyvs_sv);
534 yyps = (AV **) SvPVX(yyps_sv);
536 SvGROW(yyns_sv, yystacksize * sizeof(char *));
537 /* XXX This seems strange to cast char * to char ** */
538 yyns = (const char **) SvPVX(yyns_sv);
541 yynsp = yyns + yysize - 1;
543 if (!yyss || ! yyvs || ! yyps)
546 yyssp = yyss + yysize - 1;
547 yyvsp = yyvs + yysize - 1;
548 yypsp = yyps + yysize - 1;
551 YYDPRINTF ((Perl_debug_log, "Stack size increased to %lu\n",
552 (unsigned long int) yystacksize));
554 if (yyss + yystacksize - 1 <= yyssp)
557 ss_save->yyss = yyss;
558 ss_save->yyssp = yyssp;
559 ss_save->yyvsp = yyvsp;
560 ss_save->yypsp = yypsp;
571 /* Do appropriate processing given the current state. */
572 /* Read a lookahead token if we need one and don't already have one. */
575 /* First try to decide what to do without reference to lookahead token. */
577 yyn = yypact[yystate];
578 if (yyn == YYPACT_NINF)
581 /* Not known => get a lookahead token if don't already have one. */
583 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
584 if (yychar == YYEMPTY) {
585 YYDPRINTF ((Perl_debug_log, "Reading a token: "));
586 #ifdef PERL_IN_MADLY_C
587 yychar = PL_madskills ? madlex() : yylex();
593 if (yychar >= 0 && yychar < 255) {
594 yychar = NATIVE_TO_ASCII(yychar);
599 if (yychar <= YYEOF) {
600 yychar = yytoken = YYEOF;
601 YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
604 yytoken = YYTRANSLATE (yychar);
605 YYDSYMPRINTF ("Next token is", yytoken, &yylval);
608 /* If the proper action on seeing token YYTOKEN is to reduce or to
609 detect an error, take that action. */
611 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
615 if (yyn == 0 || yyn == YYTABLE_NINF)
624 /* Shift the lookahead token. */
625 YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));
627 /* Discard the token being shifted unless it is eof. */
632 *++yypsp = PL_comppad;
634 *++yynsp = (const char *)(yytname[yytoken]);
638 /* Count tokens shifted since error; after three, turn off error
648 /*-----------------------------------------------------------.
649 | yydefault -- do the default action for the current state. |
650 `-----------------------------------------------------------*/
652 yyn = yydefact[yystate];
658 /*-----------------------------.
659 | yyreduce -- Do a reduction. |
660 `-----------------------------*/
662 /* yyn is the number of a rule to reduce with. */
665 /* If YYLEN is nonzero, implement the default value of the action:
668 Otherwise, the following line sets YYVAL to garbage.
669 This behavior is undocumented and Bison
670 users should not rely upon it. Assigning to YYVAL
671 unconditionally makes the parser a bit smaller, and it avoids a
672 GCC warning that YYVAL may be used uninitialized. */
673 yyval = yyvsp[1-yylen];
676 YY_REDUCE_PRINT (yyn);
678 /* running external code may trigger a die (eg 'use nosuchmodule'):
679 * record the current stack state so that an unwind will
680 * free all the pesky OPs lounging around on the parse stack */
681 ss_save->yyss = yyss;
682 ss_save->yyssp = yyssp;
683 ss_save->yyvsp = yyvsp;
684 ss_save->yypsp = yypsp;
685 ss_save->yylen = yylen;
690 #define dep() deprecate("\"do\" to call subroutines")
692 #ifdef PERL_IN_MADLY_C
693 # define IVAL(i) (i)->tk_lval.ival
694 # define PVAL(p) (p)->tk_lval.pval
695 # define TOKEN_GETMAD(a,b,c) token_getmad((a),(b),(c))
696 # define TOKEN_FREE(a) token_free(a)
697 # define OP_GETMAD(a,b,c) op_getmad((a),(b),(c))
698 # define IF_MAD(a,b) (a)
704 # define TOKEN_GETMAD(a,b,c)
705 # define TOKEN_FREE(a)
706 # define OP_GETMAD(a,b,c)
707 # define IF_MAD(a,b) (b)
712 /* contains all the rule actions; auto-generated from perly.y */
717 /* any just-reduced ops with the op_latefreed flag cleared need to be
718 * freed; the rest need the flag resetting */
721 for (i=0; i< yylen; i++) {
722 if (yy_type_tab[yystos[yyssp[-i]]] == toketype_opval
725 yyvsp[-i].opval->op_latefree = 0;
726 if (yyvsp[-i].opval->op_latefreed)
727 op_free(yyvsp[-i].opval);
740 *++yypsp = PL_comppad;
742 *++yynsp = (const char *)(yytname [yyr1[yyn]]);
744 /* Now shift the result of the reduction. Determine what state
745 that goes to, based on the state we popped back to and the rule
746 number reduced by. */
750 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
751 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
752 yystate = yytable[yystate];
754 yystate = yydefgoto[yyn - YYNTOKENS];
757 /* tmp push yystate for stack print; this is normally pushed later in
761 YY_STACK_PRINT (yyss, yyssp, yyvs, yyns);
768 /*------------------------------------.
769 | yyerrlab -- here on detecting error |
770 `------------------------------------*/
772 /* If not already recovering from an error, report this error. */
776 yyn = yypact[yystate];
778 if (YYPACT_NINF < yyn && yyn < YYLAST) {
780 const int yytype = YYTRANSLATE (yychar);
785 /* Start YYX at -YYN if negative to avoid negative indexes in
787 for (yyx = yyn < 0 ? -yyn : 0;
788 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
789 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
790 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
791 yysize += yystrlen ("syntax error, unexpected ") + 1;
792 yysize += yystrlen (yytname[yytype]);
793 Newx(yymsg, yysize, char *);
795 const char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
796 yyp = yystpcpy (yyp, yytname[yytype]);
800 for (yyx = yyn < 0 ? -yyn : 0;
801 yyx < (int) (sizeof (yytname) / sizeof (char *));
804 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) {
805 const char *yyq = ! yycount ?
806 ", expecting " : " or ";
807 yyp = yystpcpy (yyp, yyq);
808 yyp = yystpcpy (yyp, yytname[yyx]);
814 YYSTACK_FREE (yymsg);
817 yyerror ("syntax error; also virtual memory exhausted");
820 #endif /* YYERROR_VERBOSE */
821 yyerror ("syntax error");
825 if (yyerrstatus == 3) {
826 /* If just tried and failed to reuse lookahead token after an
827 error, discard it. */
829 /* Return failure if at end of input. */
830 if (yychar == YYEOF) {
831 /* Pop the error token. */
833 /* Pop the rest of the stack. */
834 while (yyss < yyssp) {
835 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp);
836 if (yy_type_tab[yystos[*yyssp]] == toketype_opval
839 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
840 if (*yypsp != PL_comppad) {
841 PAD_RESTORE_LOCAL(*yypsp);
843 yyvsp->opval->op_latefree = 0;
844 op_free(yyvsp->opval);
851 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval);
856 /* Else will try to reuse lookahead token after shifting the error
861 /*----------------------------------------------------.
862 | yyerrlab1 -- error raised explicitly by an action. |
863 `----------------------------------------------------*/
865 yyerrstatus = 3; /* Each real token shifted decrements this. */
868 yyn = yypact[yystate];
869 if (yyn != YYPACT_NINF) {
871 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
878 /* Pop the current state because it cannot handle the error token. */
882 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp);
883 if (yy_type_tab[yystos[*yyssp]] == toketype_opval && yyvsp->opval) {
884 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
885 if (*yypsp != PL_comppad) {
886 PAD_RESTORE_LOCAL(*yypsp);
888 yyvsp->opval->op_latefree = 0;
889 op_free(yyvsp->opval);
898 YY_STACK_PRINT (yyss, yyssp, yyvs, yyns);
904 YYDPRINTF ((Perl_debug_log, "Shifting error token, "));
907 *++yypsp = PL_comppad;
917 /*-------------------------------------.
918 | yyacceptlab -- YYACCEPT comes here. |
919 `-------------------------------------*/
924 /*-----------------------------------.
925 | yyabortlab -- YYABORT comes here. |
926 `-----------------------------------*/
931 /*----------------------------------------------.
932 | yyoverflowlab -- parser overflow comes here. |
933 `----------------------------------------------*/
935 yyerror ("parser stack overflow");
941 ss_save->yyss = NULL; /* disarm parse stack cleanup */
942 LEAVE; /* force stack free before we return */
949 * c-indentation-style: bsd
951 * indent-tabs-mode: t
954 * ex: set ts=8 sts=4 sw=4 noet: