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 #included
11 * 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.
23 /* allow stack size to grow effectively without limit */
24 #define YYMAXDEPTH 10000000
27 #define PERL_IN_PERLY_C
30 typedef signed char yysigned_char;
38 /* contains all the parser state tables; auto-generated from perly.y */
41 # define YYSIZE_T size_t
43 #define yyerrok (yyerrstatus = 0)
44 #define yyclearin (yychar = YYEMPTY)
48 #define YYACCEPT goto yyacceptlab
49 #define YYABORT goto yyabortlab
50 #define YYERROR goto yyerrlab1
53 /* Like YYERROR except do call yyerror. This remains here temporarily
54 to ease the transition to the new meaning of YYERROR, for GCC.
55 Once GCC version 2 has supplanted version 1, this can go. */
57 #define YYFAIL goto yyerrlab
59 #define YYRECOVERING() (!!yyerrstatus)
61 #define YYBACKUP(Token, Value) \
63 if (yychar == YYEMPTY && yylen == 1) { \
66 yytoken = YYTRANSLATE (yychar); \
71 yyerror ("syntax error: cannot back up"); \
79 /* Enable debugging if requested. */
82 # define yydebug (DEBUG_p_TEST)
84 # define YYFPRINTF PerlIO_printf
86 # define YYDPRINTF(Args) \
92 # define YYDSYMPRINTF(Title, Token, Value) \
95 YYFPRINTF (Perl_debug_log, "%s ", Title); \
96 yysymprint (Perl_debug_log, Token, Value); \
97 YYFPRINTF (Perl_debug_log, "\n"); \
101 /*--------------------------------.
102 | Print this symbol on YYOUTPUT. |
103 `--------------------------------*/
106 yysymprint(PerlIO * const yyoutput, int yytype, const YYSTYPE * const yyvaluep)
108 if (yytype < YYNTOKENS) {
109 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
111 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
113 YYFPRINTF (yyoutput, "0x%"UVxf, (UV)yyvaluep->ival);
117 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
119 YYFPRINTF (yyoutput, ")");
124 * print the top 8 items on the parse stack. The args have the same
125 * meanings as the local vars in yyparse() of the same name */
128 yy_stack_print (pTHX_ const short *yyss, const short *yyssp, const YYSTYPE *yyvs, const char**yyns)
132 int count = (int)(yyssp - yyss);
135 start = count - 8 + 1;
139 PerlIO_printf(Perl_debug_log, "\nindex:");
140 for (i=0; i < count; i++)
141 PerlIO_printf(Perl_debug_log, " %8d", start+i);
142 PerlIO_printf(Perl_debug_log, "\nstate:");
143 for (i=0; i < count; i++)
144 PerlIO_printf(Perl_debug_log, " %8d", yyss[start+i]);
145 PerlIO_printf(Perl_debug_log, "\ntoken:");
146 for (i=0; i < count; i++)
147 PerlIO_printf(Perl_debug_log, " %8.8s", yyns[start+i]);
148 PerlIO_printf(Perl_debug_log, "\nvalue:");
149 for (i=0; i < count; i++) {
150 if (yy_is_opval[yystos[yyss[start+i]]]) {
151 PerlIO_printf(Perl_debug_log, " %8.8s",
153 ? PL_op_name[yyvs[start+i].opval->op_type]
158 PerlIO_printf(Perl_debug_log, " %8"UVxf, (UV)yyvs[start+i].ival);
160 PerlIO_printf(Perl_debug_log, "\n\n");
163 # define YY_STACK_PRINT(yyss, yyssp, yyvs, yyns) \
165 if (yydebug && DEBUG_v_TEST) \
166 yy_stack_print (aTHX_ (yyss), (yyssp), (yyvs), (yyns)); \
170 /*------------------------------------------------.
171 | Report that the YYRULE is going to be reduced. |
172 `------------------------------------------------*/
175 yy_reduce_print (pTHX_ int yyrule)
178 const unsigned int yylineno = yyrline[yyrule];
179 YYFPRINTF (Perl_debug_log, "Reducing stack by rule %d (line %u), ",
180 yyrule - 1, yylineno);
181 /* Print the symbols being reduced, and their result. */
182 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
183 YYFPRINTF (Perl_debug_log, "%s ", yytname [yyrhs[yyi]]);
184 YYFPRINTF (Perl_debug_log, "-> %s\n", yytname [yyr1[yyrule]]);
187 # define YY_REDUCE_PRINT(Rule) \
190 yy_reduce_print (aTHX_ Rule); \
193 #else /* !DEBUGGING */
194 # define YYDPRINTF(Args)
195 # define YYDSYMPRINTF(Title, Token, Value)
196 # define YY_STACK_PRINT(yyss, yyssp, yyvs, yyns)
197 # define YY_REDUCE_PRINT(Rule)
198 #endif /* !DEBUGGING */
201 /* YYINITDEPTH -- initial size of the parser's stacks. */
203 # define YYINITDEPTH 200
209 # if defined (__GLIBC__) && defined (_STRING_H)
210 # define yystrlen strlen
212 /* Return the length of YYSTR. */
214 yystrlen (const char *yystr)
216 register const char *yys = yystr;
218 while (*yys++ != '\0')
221 return yys - yystr - 1;
227 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
228 # define yystpcpy stpcpy
230 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
233 yystpcpy (pTHX_ char *yydest, const char *yysrc)
235 register char *yyd = yydest;
236 register const char *yys = yysrc;
238 while ((*yyd++ = *yys++) != '\0')
246 #endif /* !YYERROR_VERBOSE */
249 /* a snapshot of the current stack position variables for use by
259 /* called during cleanup (via SAVEDESTRUCTOR_X) to free any items on the
260 * parse stack, thus avoiding leaks if we die */
263 S_clear_yystack(pTHX_ const void *p)
265 yystack_positions *y = (yystack_positions*) p;
269 YYDPRINTF ((Perl_debug_log, "clearing the parse stack\n"));
270 y->yyvsp -= y->yylen; /* ignore the tokens that have just been reduced */
271 y->yyssp -= y->yylen;
272 while (y->yyssp > y->yyss) {
273 if (yy_is_opval[yystos[*y->yyssp]])
274 op_free(y->yyvsp->opval);
288 int yychar; /* The lookahead symbol. */
289 YYSTYPE yylval; /* The semantic value of the lookahead symbol. */
290 int yynerrs; /* Number of syntax errors so far. */
291 register int yystate;
295 /* Number of tokens to shift before error messages enabled. */
297 /* Lookahead token as an internal (translated) token number. */
300 /* two stacks and their tools:
301 yyss: related to states,
302 yyvs: related to semantic values,
304 Refer to the stacks thru separate pointers, to allow yyoverflow
305 to reallocate them elsewhere. */
307 /* The state stack. */
309 register short *yyssp;
311 /* The semantic value stack. */
313 register YYSTYPE *yyvsp;
315 /* for ease of re-allocation and automatic freeing, have two SVs whose
316 * SvPVX points to the stacks */
317 SV *yyss_sv, *yyvs_sv;
319 yystack_positions *ss_save;
322 /* maintain also a stack of token/rule names for debugging with -Dpv */
323 const char **yyns, **yynsp;
325 # define YYPOPSTACK (yyvsp--, yyssp--, yynsp--)
327 # define YYPOPSTACK (yyvsp--, yyssp--)
331 YYSIZE_T yystacksize = YYINITDEPTH;
333 /* The variables used to return semantic value and location from the
338 /* When reducing, the number of symbols on the RHS of the reduced
347 YYDPRINTF ((Perl_debug_log, "Starting parse\n"));
349 ENTER; /* force stack free before we return */
350 SAVEVPTR(PL_yycharp);
351 SAVEVPTR(PL_yylvalp);
352 PL_yycharp = &yychar; /* so PL_yyerror() can access it */
353 PL_yylvalp = &yylval; /* so various functions in toke.c can access it */
355 yyss_sv = newSV(YYINITDEPTH * sizeof(short));
356 yyvs_sv = newSV(YYINITDEPTH * sizeof(YYSTYPE));
357 ss_save_sv = newSV(sizeof(yystack_positions));
360 SAVEFREESV(ss_save_sv);
361 yyss = (short *) SvPVX(yyss_sv);
362 yyvs = (YYSTYPE *) SvPVX(yyvs_sv);
363 ss_save = (yystack_positions *) SvPVX(ss_save_sv);
365 ss_save->yyss = NULL; /* disarm stack cleanup */
366 /* cleanup the parse stack on premature exit */
367 SAVEDESTRUCTOR_X(S_clear_yystack, (void*) ss_save);
369 /* note that elements zero of yyvs and yyns are not used */
373 yyns_sv = newSV(YYINITDEPTH * sizeof(char *));
375 /* XXX This seems strange to cast char * to char ** */
376 yyns = (const char **) SvPVX(yyns_sv);
383 yychar = YYEMPTY; /* Cause a token to be read. */
385 YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
389 /*------------------------------------------------------------.
390 | yynewstate -- Push a new state, which is found in yystate. |
391 `------------------------------------------------------------*/
393 /* In all cases, when you get here, the value and location stacks
394 have just been pushed. so pushing a state here evens the stacks.
401 if (yyss + yystacksize - 1 <= yyssp) {
402 /* Get the current used size of the three stacks, in elements. */
403 const YYSIZE_T yysize = yyssp - yyss + 1;
405 /* Extend the stack our own way. */
406 if (YYMAXDEPTH <= yystacksize)
409 if (YYMAXDEPTH < yystacksize)
410 yystacksize = YYMAXDEPTH;
412 SvGROW(yyss_sv, yystacksize * sizeof(short));
413 SvGROW(yyvs_sv, yystacksize * sizeof(YYSTYPE));
414 yyss = (short *) SvPVX(yyss_sv);
415 yyvs = (YYSTYPE *) SvPVX(yyvs_sv);
417 SvGROW(yyns_sv, yystacksize * sizeof(char *));
418 /* XXX This seems strange to cast char * to char ** */
419 yyns = (const char **) SvPVX(yyns_sv);
422 yynsp = yyns + yysize - 1;
427 yyssp = yyss + yysize - 1;
428 yyvsp = yyvs + yysize - 1;
431 YYDPRINTF ((Perl_debug_log, "Stack size increased to %lu\n",
432 (unsigned long int) yystacksize));
434 if (yyss + yystacksize - 1 <= yyssp)
445 /* Do appropriate processing given the current state. */
446 /* Read a lookahead token if we need one and don't already have one. */
449 /* First try to decide what to do without reference to lookahead token. */
451 yyn = yypact[yystate];
452 if (yyn == YYPACT_NINF)
455 /* Not known => get a lookahead token if don't already have one. */
457 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
458 if (yychar == YYEMPTY) {
459 YYDPRINTF ((Perl_debug_log, "Reading a token: "));
461 yychar = PL_madskills ? madlex() : yylex();
466 if (yychar >= 0 && yychar < 255) {
467 yychar = NATIVE_TO_ASCII(yychar);
472 if (yychar <= YYEOF) {
473 yychar = yytoken = YYEOF;
474 YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
477 yytoken = YYTRANSLATE (yychar);
478 YYDSYMPRINTF ("Next token is", yytoken, &yylval);
481 /* If the proper action on seeing token YYTOKEN is to reduce or to
482 detect an error, take that action. */
484 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
488 if (yyn == 0 || yyn == YYTABLE_NINF)
497 /* Shift the lookahead token. */
498 YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));
500 /* Discard the token being shifted unless it is eof. */
506 *++yynsp = (const char *)(yytname[yytoken]);
510 /* Count tokens shifted since error; after three, turn off error
516 YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
521 /*-----------------------------------------------------------.
522 | yydefault -- do the default action for the current state. |
523 `-----------------------------------------------------------*/
525 yyn = yydefact[yystate];
531 /*-----------------------------.
532 | yyreduce -- Do a reduction. |
533 `-----------------------------*/
535 /* yyn is the number of a rule to reduce with. */
538 /* If YYLEN is nonzero, implement the default value of the action:
541 Otherwise, the following line sets YYVAL to garbage.
542 This behavior is undocumented and Bison
543 users should not rely upon it. Assigning to YYVAL
544 unconditionally makes the parser a bit smaller, and it avoids a
545 GCC warning that YYVAL may be used uninitialized. */
546 yyval = yyvsp[1-yylen];
549 YY_REDUCE_PRINT (yyn);
551 /* running external code may trigger a die (eg 'use nosuchmodule'):
552 * record the current stack state so that an unwind will
553 * free all the pesky OPs lounging around on the parse stack */
554 ss_save->yyss = yyss;
555 ss_save->yyssp = yyssp;
556 ss_save->yyvsp = yyvsp;
557 ss_save->yylen = yylen;
561 /* contains all the rule actions; auto-generated from perly.y */
563 #define dep() deprecate("\"do\" to call subroutines")
577 *++yynsp = (const char *)(yytname [yyr1[yyn]]);
580 /* Now shift the result of the reduction. Determine what state
581 that goes to, based on the state we popped back to and the rule
582 number reduced by. */
586 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
587 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
588 yystate = yytable[yystate];
590 yystate = yydefgoto[yyn - YYNTOKENS];
592 YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
595 /* tmp push yystate for stack print; this is normally pushed later in
599 YY_STACK_PRINT (yyss, yyssp, yyvs, yyns);
606 /*------------------------------------.
607 | yyerrlab -- here on detecting error |
608 `------------------------------------*/
610 /* If not already recovering from an error, report this error. */
614 yyn = yypact[yystate];
616 if (YYPACT_NINF < yyn && yyn < YYLAST) {
618 const int yytype = YYTRANSLATE (yychar);
623 /* Start YYX at -YYN if negative to avoid negative indexes in
625 for (yyx = yyn < 0 ? -yyn : 0;
626 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
627 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
628 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
629 yysize += yystrlen ("syntax error, unexpected ") + 1;
630 yysize += yystrlen (yytname[yytype]);
631 Newx(yymsg, yysize, char *);
633 const char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
634 yyp = yystpcpy (yyp, yytname[yytype]);
638 for (yyx = yyn < 0 ? -yyn : 0;
639 yyx < (int) (sizeof (yytname) / sizeof (char *));
642 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) {
643 const char *yyq = ! yycount ?
644 ", expecting " : " or ";
645 yyp = yystpcpy (yyp, yyq);
646 yyp = yystpcpy (yyp, yytname[yyx]);
652 YYSTACK_FREE (yymsg);
655 yyerror ("syntax error; also virtual memory exhausted");
658 #endif /* YYERROR_VERBOSE */
659 yyerror ("syntax error");
663 if (yyerrstatus == 3) {
664 /* If just tried and failed to reuse lookahead token after an
665 error, discard it. */
667 /* Return failure if at end of input. */
668 if (yychar == YYEOF) {
669 /* Pop the error token. */
671 /* Pop the rest of the stack. */
672 while (yyss < yyssp) {
673 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp);
674 if (yy_is_opval[yystos[*yyssp]]) {
675 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
676 op_free(yyvsp->opval);
683 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval);
688 /* Else will try to reuse lookahead token after shifting the error
693 /*----------------------------------------------------.
694 | yyerrlab1 -- error raised explicitly by an action. |
695 `----------------------------------------------------*/
697 yyerrstatus = 3; /* Each real token shifted decrements this. */
700 yyn = yypact[yystate];
701 if (yyn != YYPACT_NINF) {
703 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
710 /* Pop the current state because it cannot handle the error token. */
714 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp);
715 if (yy_is_opval[yystos[*yyssp]]) {
716 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
717 op_free(yyvsp->opval);
725 YY_STACK_PRINT (yyss, yyssp, yyvs, yyns);
731 YYDPRINTF ((Perl_debug_log, "Shifting error token, "));
739 YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
744 /*-------------------------------------.
745 | yyacceptlab -- YYACCEPT comes here. |
746 `-------------------------------------*/
751 /*-----------------------------------.
752 | yyabortlab -- YYABORT comes here. |
753 `-----------------------------------*/
758 /*----------------------------------------------.
759 | yyoverflowlab -- parser overflow comes here. |
760 `----------------------------------------------*/
762 yyerror ("parser stack overflow");
768 ss_save->yyss = NULL; /* disarm parse stack cleanup */
769 LEAVE; /* force stack free before we return */
776 * c-indentation-style: bsd
778 * indent-tabs-mode: t
781 * ex: set ts=8 sts=4 sw=4 noet: