This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Taint handling for runperl:
[perl5.git] / perly.c
1 /*    perly.c
2  *
3  *    Copyright (c) 2004, 2005, 2006 Larry Wall and others
4  *
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.
7  * 
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.
12  *
13  *    Here is an important copyright statement from the original, generated
14  *    file:
15  *
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.
20  */
21
22
23 /* allow stack size to grow effectively without limit */
24 #define YYMAXDEPTH 10000000
25
26 #include "EXTERN.h"
27 #define PERL_IN_PERLY_C
28 #include "perl.h"
29
30 typedef signed char yysigned_char;
31
32 #ifdef DEBUGGING
33 #  define YYDEBUG 1
34 #else
35 #  define YYDEBUG 0
36 #endif
37
38 /* contains all the parser state tables; auto-generated from perly.y */
39 #include "perly.tab"
40
41 # define YYSIZE_T size_t
42
43 #define yyerrok         (yyerrstatus = 0)
44 #define yyclearin       (yychar = YYEMPTY)
45 #define YYEMPTY         (-2)
46 #define YYEOF           0
47
48 #define YYACCEPT        goto yyacceptlab
49 #define YYABORT         goto yyabortlab
50 #define YYERROR         goto yyerrlab1
51
52
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.  */
56
57 #define YYFAIL          goto yyerrlab
58
59 #define YYRECOVERING()  (!!yyerrstatus)
60
61 #define YYBACKUP(Token, Value)                                  \
62 do                                                              \
63     if (yychar == YYEMPTY && yylen == 1) {                      \
64         yychar = (Token);                                       \
65         yylval = (Value);                                       \
66         yytoken = YYTRANSLATE (yychar);                         \
67         YYPOPSTACK;                                             \
68         goto yybackup;                                          \
69     }                                                           \
70     else {                                                      \
71         yyerror ("syntax error: cannot back up");               \
72         YYERROR;                                                \
73     }                                                           \
74 while (0)
75
76 #define YYTERROR        1
77 #define YYERRCODE       256
78
79 /* Enable debugging if requested.  */
80 #ifdef DEBUGGING
81
82 #  define yydebug (DEBUG_p_TEST)
83
84 #  define YYFPRINTF PerlIO_printf
85
86 #  define YYDPRINTF(Args)                       \
87 do {                                            \
88     if (yydebug)                                \
89         YYFPRINTF Args;                         \
90 } while (0)
91
92 #  define YYDSYMPRINTF(Title, Token, Value)                     \
93 do {                                                            \
94     if (yydebug) {                                              \
95         YYFPRINTF (Perl_debug_log, "%s ", Title);               \
96         yysymprint (Perl_debug_log,  Token, Value);     \
97         YYFPRINTF (Perl_debug_log, "\n");                       \
98     }                                                           \
99 } while (0)
100
101 /*--------------------------------.
102 | Print this symbol on YYOUTPUT.  |
103 `--------------------------------*/
104
105 static void
106 yysymprint(PerlIO * const yyoutput, int yytype, const YYSTYPE * const yyvaluep)
107 {
108     if (yytype < YYNTOKENS) {
109         YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
110 #   ifdef YYPRINT
111         YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
112 #   else
113         YYFPRINTF (yyoutput, "0x%"UVxf, (UV)yyvaluep->ival);
114 #   endif
115     }
116     else
117         YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
118
119     YYFPRINTF (yyoutput, ")");
120 }
121
122
123 /*  yy_stack_print()
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 */
126
127 static void
128 yy_stack_print (pTHX_ const short *yyss, const short *yyssp, const YYSTYPE *yyvs, const char**yyns)
129 {
130     int i;
131     int start = 1;
132     int count = (int)(yyssp - yyss);
133
134     if (count > 8) {
135         start = count - 8 + 1;
136         count = 8;
137     }
138
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, yyss += start; i < count; i++, yyss++)
144         PerlIO_printf(Perl_debug_log, " %8d", *yyss);
145     PerlIO_printf(Perl_debug_log, "\ntoken:");
146     for (i=0, yyns += start; i < count; i++, yyns++)
147         PerlIO_printf(Perl_debug_log, " %8.8s", *yyns);
148     PerlIO_printf(Perl_debug_log, "\nvalue:");
149     for (i=0, yyvs += start; i < count; i++, yyvs++)
150         PerlIO_printf(Perl_debug_log, " %8"UVxf, (UV)yyvs->ival);
151     PerlIO_printf(Perl_debug_log, "\n\n");
152 }
153
154 #  define YY_STACK_PRINT(yyss, yyssp, yyvs, yyns)               \
155 do {                                                            \
156     if (yydebug && DEBUG_v_TEST)                                \
157         yy_stack_print (aTHX_ (yyss), (yyssp), (yyvs), (yyns)); \
158 } while (0)
159
160
161 /*------------------------------------------------.
162 | Report that the YYRULE is going to be reduced.  |
163 `------------------------------------------------*/
164
165 static void
166 yy_reduce_print (pTHX_ int yyrule)
167 {
168     int yyi;
169     const unsigned int yylineno = yyrline[yyrule];
170     YYFPRINTF (Perl_debug_log, "Reducing stack by rule %d (line %u), ",
171                           yyrule - 1, yylineno);
172     /* Print the symbols being reduced, and their result.  */
173     for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
174         YYFPRINTF (Perl_debug_log, "%s ", yytname [yyrhs[yyi]]);
175     YYFPRINTF (Perl_debug_log, "-> %s\n", yytname [yyr1[yyrule]]);
176 }
177
178 #  define YY_REDUCE_PRINT(Rule)         \
179 do {                                    \
180     if (yydebug)                        \
181         yy_reduce_print (aTHX_ Rule);           \
182 } while (0)
183
184 #else /* !DEBUGGING */
185 #  define YYDPRINTF(Args)
186 #  define YYDSYMPRINTF(Title, Token, Value)
187 #  define YY_STACK_PRINT(yyss, yyssp, yyvs, yyns)
188 #  define YY_REDUCE_PRINT(Rule)
189 #endif /* !DEBUGGING */
190
191
192 /* YYINITDEPTH -- initial size of the parser's stacks.  */
193 #ifndef YYINITDEPTH
194 # define YYINITDEPTH 200
195 #endif
196
197
198 #if YYERROR_VERBOSE
199 #  ifndef yystrlen
200 #    if defined (__GLIBC__) && defined (_STRING_H)
201 #      define yystrlen strlen
202 #    else
203 /* Return the length of YYSTR.  */
204 static YYSIZE_T
205 yystrlen (const char *yystr)
206 {
207     register const char *yys = yystr;
208
209     while (*yys++ != '\0')
210         continue;
211
212     return yys - yystr - 1;
213 }
214 #    endif
215 #  endif
216
217 #  ifndef yystpcpy
218 #    if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
219 #      define yystpcpy stpcpy
220 #    else
221 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
222    YYDEST.  */
223 static char *
224 yystpcpy (pTHX_ char *yydest, const char *yysrc)
225 {
226     register char *yyd = yydest;
227     register const char *yys = yysrc;
228
229     while ((*yyd++ = *yys++) != '\0')
230         continue;
231
232     return yyd - 1;
233 }
234 #    endif
235 #  endif
236
237 #endif /* !YYERROR_VERBOSE */
238
239 /*----------.
240 | yyparse.  |
241 `----------*/
242
243 int
244 Perl_yyparse (pTHX)
245 {
246     dVAR;
247     int yychar; /* The lookahead symbol.  */
248     YYSTYPE yylval; /* The semantic value of the lookahead symbol.  */
249     int yynerrs; /* Number of syntax errors so far.  */
250     register int yystate;
251     register int yyn;
252     int yyresult;
253
254     /* Number of tokens to shift before error messages enabled.  */
255     int yyerrstatus;
256     /* Lookahead token as an internal (translated) token number.  */
257     int yytoken = 0;
258
259     /* two stacks and their tools:
260           yyss: related to states,
261           yyvs: related to semantic values,
262
263           Refer to the stacks thru separate pointers, to allow yyoverflow
264           to reallocate them elsewhere.  */
265
266     /* The state stack.  */
267     short *yyss;
268     register short *yyssp;
269
270     /* The semantic value stack.  */
271     YYSTYPE *yyvs;
272     register YYSTYPE *yyvsp;
273
274     /* for ease of re-allocation and automatic freeing, have two SVs whose
275       * SvPVX points to the stacks */
276     SV *yyss_sv, *yyvs_sv;
277
278 #ifdef DEBUGGING
279     /* maintain also a stack of token/rule names for debugging with -Dpv */
280     const char **yyns, **yynsp;
281     SV *yyns_sv;
282 #  define YYPOPSTACK   (yyvsp--, yyssp--, yynsp--)
283 #else
284 #  define YYPOPSTACK   (yyvsp--, yyssp--)
285 #endif
286
287
288     YYSIZE_T yystacksize = YYINITDEPTH;
289
290     /* The variables used to return semantic value and location from the
291           action routines.  */
292     YYSTYPE yyval;
293
294
295     /* When reducing, the number of symbols on the RHS of the reduced
296           rule.  */
297     int yylen;
298
299     YYDPRINTF ((Perl_debug_log, "Starting parse\n"));
300
301     ENTER;                      /* force stack free before we return */
302     SAVEVPTR(PL_yycharp);
303     SAVEVPTR(PL_yylvalp);
304     PL_yycharp = &yychar; /* so PL_yyerror() can access it */
305     PL_yylvalp = &yylval; /* so various functions in toke.c can access it */
306
307     yyss_sv = newSV(YYINITDEPTH * sizeof(short));
308     yyvs_sv = newSV(YYINITDEPTH * sizeof(YYSTYPE));
309     SAVEFREESV(yyss_sv);
310     SAVEFREESV(yyvs_sv);
311     yyss = (short *) SvPVX(yyss_sv);
312     yyvs = (YYSTYPE *) SvPVX(yyvs_sv);
313     /* note that elements zero of yyvs and yyns are not used */
314     yyssp = yyss;
315     yyvsp = yyvs;
316 #ifdef DEBUGGING
317     yyns_sv = newSV(YYINITDEPTH * sizeof(char *));
318     SAVEFREESV(yyns_sv);
319     /* XXX This seems strange to cast char * to char ** */
320     yyns = (const char **) SvPVX(yyns_sv);
321     yynsp = yyns;
322 #endif
323
324     yystate = 0;
325     yyerrstatus = 0;
326     yynerrs = 0;
327     yychar = YYEMPTY;           /* Cause a token to be read.  */
328
329
330
331     YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
332
333     goto yysetstate;
334
335 /*------------------------------------------------------------.
336 | yynewstate -- Push a new state, which is found in yystate.  |
337 `------------------------------------------------------------*/
338   yynewstate:
339     /* In all cases, when you get here, the value and location stacks
340           have just been pushed. so pushing a state here evens the stacks.
341           */
342     yyssp++;
343
344   yysetstate:
345     *yyssp = yystate;
346
347     if (yyss + yystacksize - 1 <= yyssp) {
348          /* Get the current used size of the three stacks, in elements.  */
349          const YYSIZE_T yysize = yyssp - yyss + 1;
350
351          /* Extend the stack our own way.  */
352          if (YYMAXDEPTH <= yystacksize)
353                goto yyoverflowlab;
354          yystacksize *= 2;
355          if (YYMAXDEPTH < yystacksize)
356                yystacksize = YYMAXDEPTH;
357
358          SvGROW(yyss_sv, yystacksize * sizeof(short));
359          SvGROW(yyvs_sv, yystacksize * sizeof(YYSTYPE));
360          yyss = (short *) SvPVX(yyss_sv);
361          yyvs = (YYSTYPE *) SvPVX(yyvs_sv);
362 #ifdef DEBUGGING
363          SvGROW(yyns_sv, yystacksize * sizeof(char *));
364          /* XXX This seems strange to cast char * to char ** */
365          yyns = (const char **) SvPVX(yyns_sv);
366          if (! yyns)
367                goto yyoverflowlab;
368          yynsp = yyns + yysize - 1;
369 #endif
370          if (!yyss || ! yyvs)
371                goto yyoverflowlab;
372
373          yyssp = yyss + yysize - 1;
374          yyvsp = yyvs + yysize - 1;
375
376
377          YYDPRINTF ((Perl_debug_log, "Stack size increased to %lu\n",
378                                    (unsigned long int) yystacksize));
379
380          if (yyss + yystacksize - 1 <= yyssp)
381                YYABORT;
382     }
383
384     goto yybackup;
385
386   /*-----------.
387   | yybackup.  |
388   `-----------*/
389   yybackup:
390
391 /* Do appropriate processing given the current state.  */
392 /* Read a lookahead token if we need one and don't already have one.  */
393 /* yyresume: */
394
395     /* First try to decide what to do without reference to lookahead token.  */
396
397     yyn = yypact[yystate];
398     if (yyn == YYPACT_NINF)
399         goto yydefault;
400
401     /* Not known => get a lookahead token if don't already have one.  */
402
403     /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
404     if (yychar == YYEMPTY) {
405         YYDPRINTF ((Perl_debug_log, "Reading a token: "));
406         yychar = yylex();
407 #  ifdef EBCDIC
408         if (yychar >= 0 && yychar < 255) {
409             yychar = NATIVE_TO_ASCII(yychar);
410         }
411 #  endif
412     }
413
414     if (yychar <= YYEOF) {
415         yychar = yytoken = YYEOF;
416         YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
417     }
418     else {
419         yytoken = YYTRANSLATE (yychar);
420         YYDSYMPRINTF ("Next token is", yytoken, &yylval);
421     }
422
423     /* If the proper action on seeing token YYTOKEN is to reduce or to
424           detect an error, take that action.  */
425     yyn += yytoken;
426     if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
427         goto yydefault;
428     yyn = yytable[yyn];
429     if (yyn <= 0) {
430         if (yyn == 0 || yyn == YYTABLE_NINF)
431             goto yyerrlab;
432         yyn = -yyn;
433         goto yyreduce;
434     }
435
436     if (yyn == YYFINAL)
437         YYACCEPT;
438
439     /* Shift the lookahead token.  */
440     YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));
441
442     /* Discard the token being shifted unless it is eof.  */
443     if (yychar != YYEOF)
444         yychar = YYEMPTY;
445
446     *++yyvsp = yylval;
447 #ifdef DEBUGGING
448     *++yynsp = (const char *)(yytname[yytoken]);
449 #endif
450
451
452     /* Count tokens shifted since error; after three, turn off error
453           status.  */
454     if (yyerrstatus)
455         yyerrstatus--;
456
457     yystate = yyn;
458     YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
459
460     goto yynewstate;
461
462
463   /*-----------------------------------------------------------.
464   | yydefault -- do the default action for the current state.  |
465   `-----------------------------------------------------------*/
466   yydefault:
467     yyn = yydefact[yystate];
468     if (yyn == 0)
469         goto yyerrlab;
470     goto yyreduce;
471
472
473   /*-----------------------------.
474   | yyreduce -- Do a reduction.  |
475   `-----------------------------*/
476   yyreduce:
477     /* yyn is the number of a rule to reduce with.  */
478     yylen = yyr2[yyn];
479
480     /* If YYLEN is nonzero, implement the default value of the action:
481       "$$ = $1".
482
483       Otherwise, the following line sets YYVAL to garbage.
484       This behavior is undocumented and Bison
485       users should not rely upon it.  Assigning to YYVAL
486       unconditionally makes the parser a bit smaller, and it avoids a
487       GCC warning that YYVAL may be used uninitialized.  */
488     yyval = yyvsp[1-yylen];
489
490
491     YY_REDUCE_PRINT (yyn);
492     switch (yyn) {
493
494 /* contains all the rule actions; auto-generated from perly.y */
495
496 #define dep() deprecate("\"do\" to call subroutines")
497 #include "perly.act"
498
499     }
500
501     yyvsp -= yylen;
502     yyssp -= yylen;
503 #ifdef DEBUGGING
504     yynsp -= yylen;
505 #endif
506
507
508     *++yyvsp = yyval;
509 #ifdef DEBUGGING
510     *++yynsp = (const char *)(yytname [yyr1[yyn]]);
511 #endif
512
513     /* Now shift the result of the reduction.  Determine what state
514           that goes to, based on the state we popped back to and the rule
515           number reduced by.  */
516
517     yyn = yyr1[yyn];
518
519     yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
520     if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
521         yystate = yytable[yystate];
522     else
523         yystate = yydefgoto[yyn - YYNTOKENS];
524
525     YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
526
527 #ifdef DEBUGGING
528     /* tmp push yystate for stack print; this is normally pushed later in
529      * yynewstate */
530     yyssp++;
531     *yyssp = yystate;
532     YY_STACK_PRINT (yyss, yyssp, yyvs, yyns);
533     yyssp--;
534 #endif
535
536     goto yynewstate;
537
538
539   /*------------------------------------.
540   | yyerrlab -- here on detecting error |
541   `------------------------------------*/
542   yyerrlab:
543     /* If not already recovering from an error, report this error.  */
544     if (!yyerrstatus) {
545         ++yynerrs;
546 #if YYERROR_VERBOSE
547         yyn = yypact[yystate];
548
549         if (YYPACT_NINF < yyn && yyn < YYLAST) {
550             YYSIZE_T yysize = 0;
551             const int yytype = YYTRANSLATE (yychar);
552             char *yymsg;
553             int yyx, yycount;
554
555             yycount = 0;
556             /* Start YYX at -YYN if negative to avoid negative indexes in
557                   YYCHECK.  */
558             for (yyx = yyn < 0 ? -yyn : 0;
559                       yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
560                 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
561                     yysize += yystrlen (yytname[yyx]) + 15, yycount++;
562             yysize += yystrlen ("syntax error, unexpected ") + 1;
563             yysize += yystrlen (yytname[yytype]);
564             Newx(yymsg, yysize, char *);
565             if (yymsg != 0) {
566                 const char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
567                 yyp = yystpcpy (yyp, yytname[yytype]);
568
569                 if (yycount < 5) {
570                     yycount = 0;
571                     for (yyx = yyn < 0 ? -yyn : 0;
572                               yyx < (int) (sizeof (yytname) / sizeof (char *));
573                               yyx++)
574                     {
575                         if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) {
576                             const char *yyq = ! yycount ?
577                                                     ", expecting " : " or ";
578                             yyp = yystpcpy (yyp, yyq);
579                             yyp = yystpcpy (yyp, yytname[yyx]);
580                             yycount++;
581                         }
582                     }
583                 }
584                 yyerror (yymsg);
585                 YYSTACK_FREE (yymsg);
586             }
587             else
588                 yyerror ("syntax error; also virtual memory exhausted");
589         }
590         else
591 #endif /* YYERROR_VERBOSE */
592             yyerror ("syntax error");
593     }
594
595
596     if (yyerrstatus == 3) {
597         /* If just tried and failed to reuse lookahead token after an
598               error, discard it.  */
599
600         /* Return failure if at end of input.  */
601         if (yychar == YYEOF) {
602             /* Pop the error token.  */
603             YYPOPSTACK;
604             /* Pop the rest of the stack.  */
605             while (yyss < yyssp) {
606                 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp);
607                 YYPOPSTACK;
608             }
609             YYABORT;
610         }
611
612         YYDSYMPRINTF ("Error: discarding", yytoken, &yylval);
613         yychar = YYEMPTY;
614
615     }
616
617     /* Else will try to reuse lookahead token after shifting the error
618           token.  */
619     goto yyerrlab1;
620
621
622   /*----------------------------------------------------.
623   | yyerrlab1 -- error raised explicitly by an action.  |
624   `----------------------------------------------------*/
625   yyerrlab1:
626     yyerrstatus = 3;    /* Each real token shifted decrements this.  */
627
628     for (;;) {
629         yyn = yypact[yystate];
630         if (yyn != YYPACT_NINF) {
631             yyn += YYTERROR;
632             if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
633                 yyn = yytable[yyn];
634                 if (0 < yyn)
635                     break;
636             }
637         }
638
639         /* Pop the current state because it cannot handle the error token.  */
640         if (yyssp == yyss)
641             YYABORT;
642
643         YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp);
644         yyvsp--;
645 #ifdef DEBUGGING
646         yynsp--;
647 #endif
648         yystate = *--yyssp;
649
650         YY_STACK_PRINT (yyss, yyssp, yyvs, yyns);
651     }
652
653     if (yyn == YYFINAL)
654         YYACCEPT;
655
656     YYDPRINTF ((Perl_debug_log, "Shifting error token, "));
657
658     *++yyvsp = yylval;
659 #ifdef DEBUGGING
660     *++yynsp ="<err>";
661 #endif
662
663     yystate = yyn;
664     YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
665
666     goto yynewstate;
667
668
669   /*-------------------------------------.
670   | yyacceptlab -- YYACCEPT comes here.  |
671   `-------------------------------------*/
672   yyacceptlab:
673     yyresult = 0;
674     goto yyreturn;
675
676   /*-----------------------------------.
677   | yyabortlab -- YYABORT comes here.  |
678   `-----------------------------------*/
679   yyabortlab:
680     yyresult = 1;
681     goto yyreturn;
682
683   /*----------------------------------------------.
684   | yyoverflowlab -- parser overflow comes here.  |
685   `----------------------------------------------*/
686   yyoverflowlab:
687     yyerror ("parser stack overflow");
688     yyresult = 2;
689     /* Fall through.  */
690
691   yyreturn:
692
693     LEAVE;                      /* force stack free before we return */
694
695     return yyresult;
696 }
697
698 /*
699  * Local variables:
700  * c-indentation-style: bsd
701  * c-basic-offset: 4
702  * indent-tabs-mode: t
703  * End:
704  *
705  * ex: set ts=8 sts=4 sw=4 noet:
706  */