Commit | Line | Data |
---|---|---|
0de566d7 DM |
1 | /* perly.c |
2 | * | |
1129b882 | 3 | * Copyright (c) 2004, 2005, 2006, 2007, 2008 by Larry Wall and others |
0de566d7 DM |
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 | |
f05e27e5 DM |
10 | * and edited; the bits that are dependent on perly.y are now |
11 | * #included from the files perly.tab and perly.act. | |
0de566d7 DM |
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. | |
bc463c31 DM |
20 | * |
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, | |
f05e27e5 DM |
23 | * but which includes extra code for dumping the parse tree. |
24 | * This is controlled by the PERL_IN_MADLY_C define. | |
0de566d7 DM |
25 | */ |
26 | ||
79072805 | 27 | #include "EXTERN.h" |
864dbfa3 | 28 | #define PERL_IN_PERLY_C |
79072805 | 29 | #include "perl.h" |
09bef843 | 30 | |
3797f23d DM |
31 | typedef unsigned char yytype_uint8; |
32 | typedef signed char yytype_int8; | |
33 | typedef unsigned short int yytype_uint16; | |
34 | typedef short int yytype_int16; | |
0de566d7 DM |
35 | typedef signed char yysigned_char; |
36 | ||
28ac2b49 Z |
37 | /* YYINITDEPTH -- initial size of the parser's stacks. */ |
38 | #define YYINITDEPTH 200 | |
39 | ||
0de566d7 DM |
40 | #ifdef DEBUGGING |
41 | # define YYDEBUG 1 | |
93a17b20 | 42 | #else |
0de566d7 | 43 | # define YYDEBUG 0 |
93a17b20 | 44 | #endif |
09bef843 | 45 | |
f05e27e5 DM |
46 | /* contains all the parser state tables; auto-generated from perly.y */ |
47 | #include "perly.tab" | |
0de566d7 DM |
48 | |
49 | # define YYSIZE_T size_t | |
50 | ||
0de566d7 | 51 | #define YYEOF 0 |
07a06489 | 52 | #define YYTERROR 1 |
0de566d7 DM |
53 | |
54 | #define YYACCEPT goto yyacceptlab | |
55 | #define YYABORT goto yyabortlab | |
56 | #define YYERROR goto yyerrlab1 | |
57 | ||
0de566d7 | 58 | /* Enable debugging if requested. */ |
9388183f | 59 | #ifdef DEBUGGING |
0de566d7 DM |
60 | |
61 | # define yydebug (DEBUG_p_TEST) | |
62 | ||
63 | # define YYFPRINTF PerlIO_printf | |
64 | ||
65 | # define YYDPRINTF(Args) \ | |
66 | do { \ | |
67 | if (yydebug) \ | |
68 | YYFPRINTF Args; \ | |
69 | } while (0) | |
70 | ||
9388183f | 71 | # define YYDSYMPRINTF(Title, Token, Value) \ |
0de566d7 DM |
72 | do { \ |
73 | if (yydebug) { \ | |
74 | YYFPRINTF (Perl_debug_log, "%s ", Title); \ | |
356f4fed | 75 | yysymprint (aTHX_ Perl_debug_log, Token, Value); \ |
0de566d7 DM |
76 | YYFPRINTF (Perl_debug_log, "\n"); \ |
77 | } \ | |
78 | } while (0) | |
79 | ||
80 | /*--------------------------------. | |
81 | | Print this symbol on YYOUTPUT. | | |
82 | `--------------------------------*/ | |
83 | ||
84 | static void | |
356f4fed | 85 | yysymprint(pTHX_ PerlIO * const yyoutput, int yytype, const YYSTYPE * const yyvaluep) |
0de566d7 | 86 | { |
0de566d7 DM |
87 | if (yytype < YYNTOKENS) { |
88 | YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); | |
89 | # ifdef YYPRINT | |
90 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); | |
9388183f | 91 | # else |
e4584336 | 92 | YYFPRINTF (yyoutput, "0x%"UVxf, (UV)yyvaluep->ival); |
0de566d7 DM |
93 | # endif |
94 | } | |
95 | else | |
96 | YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); | |
97 | ||
0de566d7 DM |
98 | YYFPRINTF (yyoutput, ")"); |
99 | } | |
100 | ||
101 | ||
9388183f | 102 | /* yy_stack_print() |
1654d593 DM |
103 | * print the top 8 items on the parse stack. |
104 | */ | |
0de566d7 DM |
105 | |
106 | static void | |
1654d593 | 107 | yy_stack_print (pTHX_ const yy_parser *parser) |
0de566d7 | 108 | { |
1654d593 | 109 | const yy_stack_frame *ps, *min; |
9388183f | 110 | |
2d29f438 | 111 | min = parser->ps - 8 + 1; |
22735491 DM |
112 | if (min <= parser->stack) |
113 | min = parser->stack + 1; | |
9388183f CB |
114 | |
115 | PerlIO_printf(Perl_debug_log, "\nindex:"); | |
1654d593 | 116 | for (ps = min; ps <= parser->ps; ps++) |
00c0e1ee | 117 | PerlIO_printf(Perl_debug_log, " %8d", (int)(ps - parser->stack)); |
1654d593 | 118 | |
9388183f | 119 | PerlIO_printf(Perl_debug_log, "\nstate:"); |
1654d593 DM |
120 | for (ps = min; ps <= parser->ps; ps++) |
121 | PerlIO_printf(Perl_debug_log, " %8d", ps->state); | |
122 | ||
9388183f | 123 | PerlIO_printf(Perl_debug_log, "\ntoken:"); |
1654d593 DM |
124 | for (ps = min; ps <= parser->ps; ps++) |
125 | PerlIO_printf(Perl_debug_log, " %8.8s", ps->name); | |
126 | ||
9388183f | 127 | PerlIO_printf(Perl_debug_log, "\nvalue:"); |
1654d593 DM |
128 | for (ps = min; ps <= parser->ps; ps++) { |
129 | switch (yy_type_tab[yystos[ps->state]]) { | |
d5c6462e | 130 | case toketype_opval: |
21612876 | 131 | PerlIO_printf(Perl_debug_log, " %8.8s", |
1654d593 DM |
132 | ps->val.opval |
133 | ? PL_op_name[ps->val.opval->op_type] | |
670f3923 | 134 | : "(Nullop)" |
21612876 | 135 | ); |
d5c6462e DM |
136 | break; |
137 | #ifndef PERL_IN_MADLY_C | |
138 | case toketype_p_tkval: | |
139 | PerlIO_printf(Perl_debug_log, " %8.8s", | |
1654d593 | 140 | ps->val.pval ? ps->val.pval : "(NULL)"); |
d5c6462e DM |
141 | break; |
142 | ||
143 | case toketype_i_tkval: | |
144 | #endif | |
145 | case toketype_ival: | |
1654d593 | 146 | PerlIO_printf(Perl_debug_log, " %8"IVdf, (IV)ps->val.ival); |
d5c6462e DM |
147 | break; |
148 | default: | |
1654d593 | 149 | PerlIO_printf(Perl_debug_log, " %8"UVxf, (UV)ps->val.ival); |
d5c6462e | 150 | } |
21612876 | 151 | } |
9388183f | 152 | PerlIO_printf(Perl_debug_log, "\n\n"); |
0de566d7 DM |
153 | } |
154 | ||
1654d593 DM |
155 | # define YY_STACK_PRINT(parser) \ |
156 | do { \ | |
157 | if (yydebug && DEBUG_v_TEST) \ | |
158 | yy_stack_print (aTHX_ parser); \ | |
0de566d7 DM |
159 | } while (0) |
160 | ||
09bef843 | 161 | |
0de566d7 DM |
162 | /*------------------------------------------------. |
163 | | Report that the YYRULE is going to be reduced. | | |
164 | `------------------------------------------------*/ | |
165 | ||
166 | static void | |
167 | yy_reduce_print (pTHX_ int yyrule) | |
168 | { | |
169 | int yyi; | |
df35152e | 170 | const unsigned int yylineno = yyrline[yyrule]; |
0de566d7 DM |
171 | YYFPRINTF (Perl_debug_log, "Reducing stack by rule %d (line %u), ", |
172 | yyrule - 1, yylineno); | |
173 | /* Print the symbols being reduced, and their result. */ | |
174 | for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) | |
175 | YYFPRINTF (Perl_debug_log, "%s ", yytname [yyrhs[yyi]]); | |
176 | YYFPRINTF (Perl_debug_log, "-> %s\n", yytname [yyr1[yyrule]]); | |
177 | } | |
178 | ||
179 | # define YY_REDUCE_PRINT(Rule) \ | |
180 | do { \ | |
181 | if (yydebug) \ | |
182 | yy_reduce_print (aTHX_ Rule); \ | |
183 | } while (0) | |
184 | ||
185 | #else /* !DEBUGGING */ | |
186 | # define YYDPRINTF(Args) | |
9388183f | 187 | # define YYDSYMPRINTF(Title, Token, Value) |
1654d593 | 188 | # define YY_STACK_PRINT(parser) |
0de566d7 DM |
189 | # define YY_REDUCE_PRINT(Rule) |
190 | #endif /* !DEBUGGING */ | |
191 | ||
718a7425 DM |
192 | /* called during cleanup (via SAVEDESTRUCTOR_X) to free any items on the |
193 | * parse stack, thus avoiding leaks if we die */ | |
194 | ||
195 | static void | |
22735491 | 196 | S_clear_yystack(pTHX_ const yy_parser *parser) |
718a7425 | 197 | { |
1654d593 | 198 | yy_stack_frame *ps = parser->ps; |
0934c9d9 | 199 | int i = 0; |
718a7425 | 200 | |
28ac2b49 | 201 | if (!parser->stack) |
718a7425 | 202 | return; |
1654d593 | 203 | |
718a7425 | 204 | YYDPRINTF ((Perl_debug_log, "clearing the parse stack\n")); |
670f3923 | 205 | |
7e5d8ed2 DM |
206 | /* Freeing ops on the stack, and the op_latefree / op_latefreed / |
207 | * op_attached flags: | |
670f3923 DM |
208 | * |
209 | * When we pop tokens off the stack during error recovery, or when | |
210 | * we pop all the tokens off the stack after a die during a shift or | |
7e5d8ed2 DM |
211 | * reduce (i.e. Perl_croak somewhere in yylex() or in one of the |
212 | * newFOO() functions), then it's possible that some of these tokens are | |
670f3923 DM |
213 | * of type opval, pointing to an OP. All these ops are orphans; each is |
214 | * its own miniature subtree that has not yet been attached to a | |
7e5d8ed2 DM |
215 | * larger tree. In this case, we should clearly free the op (making |
216 | * sure, for each op we free that we have PL_comppad pointing to the | |
670f3923 DM |
217 | * right place for freeing any SVs attached to the op in threaded |
218 | * builds. | |
219 | * | |
7e5d8ed2 | 220 | * However, there is a particular problem if we die in newFOO() called |
670f3923 DM |
221 | * by a reducing action; e.g. |
222 | * | |
223 | * foo : bar baz boz | |
224 | * { $$ = newFOO($1,$2,$3) } | |
225 | * | |
226 | * where | |
7e5d8ed2 | 227 | * OP *newFOO { ....; if (...) croak; .... } |
670f3923 DM |
228 | * |
229 | * In this case, when we come to clean bar baz and boz off the stack, | |
230 | * we don't know whether newFOO() has already: | |
231 | * * freed them | |
7e5d8ed2 | 232 | * * left them as is |
670f3923 | 233 | * * attached them to part of a larger tree |
7e5d8ed2 DM |
234 | * * attached them to PL_compcv |
235 | * * attached them to PL_compcv then freed it (as in BEGIN {die } ) | |
670f3923 DM |
236 | * |
237 | * To get round this problem, we set the flag op_latefree on every op | |
238 | * that gets pushed onto the parser stack. If op_free() sees this | |
239 | * flag, it clears the op and frees any children,, but *doesn't* free | |
240 | * the op itself; instead it sets the op_latefreed flag. This means | |
241 | * that we can safely call op_free() multiple times on each stack op. | |
242 | * So, when clearing the stack, we first, for each op that was being | |
243 | * reduced, call op_free with op_latefree=1. This ensures that all ops | |
486ec47a | 244 | * hanging off these op are freed, but the reducing ops themselves are |
670f3923 | 245 | * just undefed. Then we set op_latefreed=0 on *all* ops on the stack |
7e5d8ed2 DM |
246 | * and free them. A little thought should convince you that this |
247 | * two-part approach to the reducing ops should handle the first three | |
248 | * cases above safely. | |
249 | * | |
250 | * In the case of attaching to PL_compcv (currently just newATTRSUB | |
251 | * does this), then we set the op_attached flag on the op that has | |
252 | * been so attached, then avoid doing the final op_free during | |
253 | * cleanup, on the assumption that it will happen (or has already | |
254 | * happened) when PL_compcv is freed. | |
255 | * | |
256 | * Note this is fairly fragile mechanism. A more robust approach | |
257 | * would be to use two of these flag bits as 2-bit reference count | |
258 | * field for each op, indicating whether it is pointed to from: | |
259 | * * a parent op | |
260 | * * the parser stack | |
261 | * * a CV | |
262 | * but this would involve reworking all code (core and external) that | |
263 | * manipulate op trees. | |
0aded6e1 DM |
264 | * |
265 | * XXX DAPM 17/1/07 I've decided its too fragile for now, and so have | |
266 | * disabled it */ | |
267 | ||
268 | #define DISABLE_STACK_FREE | |
670f3923 | 269 | |
0aded6e1 DM |
270 | |
271 | #ifdef DISABLE_STACK_FREE | |
8c63ea58 GG |
272 | for (i=0; i< parser->yylen; i++) { |
273 | SvREFCNT_dec(ps[-i].compcv); | |
274 | } | |
0aded6e1 | 275 | ps -= parser->yylen; |
0aded6e1 | 276 | #else |
7e5d8ed2 | 277 | /* clear any reducing ops (1st pass) */ |
670f3923 | 278 | |
5912531f | 279 | for (i=0; i< parser->yylen; i++) { |
503de470 | 280 | LEAVE_SCOPE(ps[-i].savestack_ix); |
1654d593 DM |
281 | if (yy_type_tab[yystos[ps[-i].state]] == toketype_opval |
282 | && ps[-i].val.opval) { | |
7e5d8ed2 DM |
283 | if ( ! (ps[-i].val.opval->op_attached |
284 | && !ps[-i].val.opval->op_latefreed)) | |
285 | { | |
8c63ea58 GG |
286 | if (ps[-i].compcv != PL_compcv) { |
287 | PL_compcv = ps[-i].compcv; | |
288 | PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1); | |
7e5d8ed2 DM |
289 | } |
290 | op_free(ps[-i].val.opval); | |
670f3923 | 291 | } |
670f3923 DM |
292 | } |
293 | } | |
0aded6e1 | 294 | #endif |
670f3923 DM |
295 | |
296 | /* now free whole the stack, including the just-reduced ops */ | |
297 | ||
22735491 | 298 | while (ps > parser->stack) { |
503de470 | 299 | LEAVE_SCOPE(ps->savestack_ix); |
1654d593 DM |
300 | if (yy_type_tab[yystos[ps->state]] == toketype_opval |
301 | && ps->val.opval) | |
670f3923 | 302 | { |
8c63ea58 GG |
303 | if (ps->compcv != PL_compcv) { |
304 | PL_compcv = ps->compcv; | |
305 | PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1); | |
718a7425 DM |
306 | } |
307 | YYDPRINTF ((Perl_debug_log, "(freeing op)\n")); | |
0aded6e1 | 308 | #ifndef DISABLE_STACK_FREE |
1654d593 | 309 | ps->val.opval->op_latefree = 0; |
7e5d8ed2 | 310 | if (!(ps->val.opval->op_attached && !ps->val.opval->op_latefreed)) |
0aded6e1 | 311 | #endif |
7e5d8ed2 | 312 | op_free(ps->val.opval); |
718a7425 | 313 | } |
8c63ea58 | 314 | SvREFCNT_dec(ps->compcv); |
1654d593 | 315 | ps--; |
718a7425 | 316 | } |
28ac2b49 Z |
317 | |
318 | Safefree(parser->stack); | |
718a7425 DM |
319 | } |
320 | ||
718a7425 | 321 | |
0de566d7 DM |
322 | /*----------. |
323 | | yyparse. | | |
324 | `----------*/ | |
325 | ||
79072805 | 326 | int |
bc463c31 | 327 | #ifdef PERL_IN_MADLY_C |
28ac2b49 | 328 | Perl_madparse (pTHX_ int gramtype) |
bc463c31 | 329 | #else |
28ac2b49 | 330 | Perl_yyparse (pTHX_ int gramtype) |
bc463c31 | 331 | #endif |
79072805 | 332 | { |
97aff369 | 333 | dVAR; |
0de566d7 DM |
334 | register int yystate; |
335 | register int yyn; | |
336 | int yyresult; | |
337 | ||
0de566d7 | 338 | /* Lookahead token as an internal (translated) token number. */ |
714c8e96 | 339 | int yytoken = 0; |
0de566d7 | 340 | |
5912531f | 341 | register yy_parser *parser; /* the parser object */ |
1654d593 | 342 | register yy_stack_frame *ps; /* current parser stack frame */ |
a0d0e21e | 343 | |
1654d593 DM |
344 | #define YYPOPSTACK parser->ps = --ps |
345 | #define YYPUSHSTACK parser->ps = ++ps | |
0de566d7 | 346 | |
acdf0a21 | 347 | /* The variable used to return semantic value and location from the |
5912531f | 348 | action routines: ie $$. */ |
0de566d7 DM |
349 | YYSTYPE yyval; |
350 | ||
bc463c31 DM |
351 | #ifndef PERL_IN_MADLY_C |
352 | # ifdef PERL_MAD | |
00e74f14 | 353 | if (PL_madskills) |
28ac2b49 | 354 | return madparse(gramtype); |
bc463c31 | 355 | # endif |
81d86705 NC |
356 | #endif |
357 | ||
0de566d7 DM |
358 | YYDPRINTF ((Perl_debug_log, "Starting parse\n")); |
359 | ||
acdf0a21 | 360 | parser = PL_parser; |
1654d593 | 361 | |
28ac2b49 Z |
362 | ENTER; /* force parser state cleanup/restoration before we return */ |
363 | SAVEPPTR(parser->yylval.pval); | |
364 | SAVEINT(parser->yychar); | |
365 | SAVEINT(parser->yyerrstatus); | |
366 | SAVEINT(parser->stack_size); | |
367 | SAVEINT(parser->yylen); | |
368 | SAVEVPTR(parser->stack); | |
369 | SAVEVPTR(parser->ps); | |
370 | ||
371 | /* initialise state for this parse */ | |
372 | parser->yychar = gramtype; | |
373 | parser->yyerrstatus = 0; | |
374 | parser->stack_size = YYINITDEPTH; | |
375 | parser->yylen = 0; | |
376 | Newx(parser->stack, YYINITDEPTH, yy_stack_frame); | |
377 | ps = parser->ps = parser->stack; | |
378 | ps->state = 0; | |
e3abe207 | 379 | SAVEDESTRUCTOR_X(S_clear_yystack, parser); |
0de566d7 | 380 | |
0de566d7 DM |
381 | /*------------------------------------------------------------. |
382 | | yynewstate -- Push a new state, which is found in yystate. | | |
383 | `------------------------------------------------------------*/ | |
384 | yynewstate: | |
0de566d7 | 385 | |
1654d593 | 386 | yystate = ps->state; |
05a03161 | 387 | |
670f3923 | 388 | YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate)); |
0de566d7 | 389 | |
0aded6e1 | 390 | #ifndef DISABLE_STACK_FREE |
1654d593 DM |
391 | if (yy_type_tab[yystos[yystate]] == toketype_opval && ps->val.opval) { |
392 | ps->val.opval->op_latefree = 1; | |
393 | ps->val.opval->op_latefreed = 0; | |
670f3923 | 394 | } |
0aded6e1 | 395 | #endif |
670f3923 | 396 | |
5912531f | 397 | parser->yylen = 0; |
0de566d7 | 398 | |
1654d593 | 399 | { |
22735491 | 400 | size_t size = ps - parser->stack + 1; |
0de566d7 | 401 | |
1654d593 DM |
402 | /* grow the stack? We always leave 1 spare slot, |
403 | * in case of a '' -> 'foo' reduction */ | |
0de566d7 | 404 | |
85c508c3 | 405 | if (size >= (size_t)parser->stack_size - 1) { |
1654d593 DM |
406 | /* this will croak on insufficient memory */ |
407 | parser->stack_size *= 2; | |
22735491 DM |
408 | Renew(parser->stack, parser->stack_size, yy_stack_frame); |
409 | ps = parser->ps = parser->stack + size -1; | |
670f3923 | 410 | |
1654d593 DM |
411 | YYDPRINTF((Perl_debug_log, |
412 | "parser stack size increased to %lu frames\n", | |
413 | (unsigned long int)parser->stack_size)); | |
414 | } | |
93a17b20 | 415 | } |
0de566d7 | 416 | |
0de566d7 DM |
417 | /* Do appropriate processing given the current state. */ |
418 | /* Read a lookahead token if we need one and don't already have one. */ | |
0de566d7 DM |
419 | |
420 | /* First try to decide what to do without reference to lookahead token. */ | |
421 | ||
422 | yyn = yypact[yystate]; | |
423 | if (yyn == YYPACT_NINF) | |
424 | goto yydefault; | |
425 | ||
426 | /* Not known => get a lookahead token if don't already have one. */ | |
427 | ||
428 | /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ | |
5912531f | 429 | if (parser->yychar == YYEMPTY) { |
0de566d7 | 430 | YYDPRINTF ((Perl_debug_log, "Reading a token: ")); |
f05e27e5 | 431 | #ifdef PERL_IN_MADLY_C |
5912531f | 432 | parser->yychar = PL_madskills ? madlex() : yylex(); |
f05e27e5 | 433 | #else |
5912531f | 434 | parser->yychar = yylex(); |
81d86705 | 435 | #endif |
bc463c31 | 436 | |
12fbd33b | 437 | # ifdef EBCDIC |
5912531f DM |
438 | if (parser->yychar >= 0 && parser->yychar < 255) { |
439 | parser->yychar = NATIVE_TO_ASCII(parser->yychar); | |
12fbd33b DM |
440 | } |
441 | # endif | |
0de566d7 DM |
442 | } |
443 | ||
5912531f DM |
444 | if (parser->yychar <= YYEOF) { |
445 | parser->yychar = yytoken = YYEOF; | |
0de566d7 | 446 | YYDPRINTF ((Perl_debug_log, "Now at end of input.\n")); |
93a17b20 | 447 | } |
0de566d7 | 448 | else { |
5912531f DM |
449 | yytoken = YYTRANSLATE (parser->yychar); |
450 | YYDSYMPRINTF ("Next token is", yytoken, &parser->yylval); | |
93a17b20 | 451 | } |
771df094 | 452 | |
0de566d7 DM |
453 | /* If the proper action on seeing token YYTOKEN is to reduce or to |
454 | detect an error, take that action. */ | |
455 | yyn += yytoken; | |
456 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) | |
457 | goto yydefault; | |
458 | yyn = yytable[yyn]; | |
459 | if (yyn <= 0) { | |
460 | if (yyn == 0 || yyn == YYTABLE_NINF) | |
461 | goto yyerrlab; | |
462 | yyn = -yyn; | |
463 | goto yyreduce; | |
464 | } | |
7b57b0ea | 465 | |
0de566d7 DM |
466 | if (yyn == YYFINAL) |
467 | YYACCEPT; | |
771df094 | 468 | |
0de566d7 DM |
469 | /* Shift the lookahead token. */ |
470 | YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken])); | |
471 | ||
472 | /* Discard the token being shifted unless it is eof. */ | |
5912531f DM |
473 | if (parser->yychar != YYEOF) |
474 | parser->yychar = YYEMPTY; | |
0de566d7 | 475 | |
1654d593 DM |
476 | YYPUSHSTACK; |
477 | ps->state = yyn; | |
5912531f | 478 | ps->val = parser->yylval; |
ec8ec19f | 479 | ps->compcv = (CV*)SvREFCNT_inc(PL_compcv); |
503de470 | 480 | ps->savestack_ix = PL_savestack_ix; |
9388183f | 481 | #ifdef DEBUGGING |
1654d593 | 482 | ps->name = (const char *)(yytname[yytoken]); |
9388183f | 483 | #endif |
0de566d7 | 484 | |
0de566d7 DM |
485 | /* Count tokens shifted since error; after three, turn off error |
486 | status. */ | |
5912531f DM |
487 | if (parser->yyerrstatus) |
488 | parser->yyerrstatus--; | |
0de566d7 | 489 | |
0de566d7 DM |
490 | goto yynewstate; |
491 | ||
492 | ||
493 | /*-----------------------------------------------------------. | |
494 | | yydefault -- do the default action for the current state. | | |
495 | `-----------------------------------------------------------*/ | |
496 | yydefault: | |
497 | yyn = yydefact[yystate]; | |
498 | if (yyn == 0) | |
499 | goto yyerrlab; | |
500 | goto yyreduce; | |
501 | ||
502 | ||
503 | /*-----------------------------. | |
504 | | yyreduce -- Do a reduction. | | |
505 | `-----------------------------*/ | |
506 | yyreduce: | |
507 | /* yyn is the number of a rule to reduce with. */ | |
5912531f | 508 | parser->yylen = yyr2[yyn]; |
0de566d7 DM |
509 | |
510 | /* If YYLEN is nonzero, implement the default value of the action: | |
a0288114 | 511 | "$$ = $1". |
0de566d7 DM |
512 | |
513 | Otherwise, the following line sets YYVAL to garbage. | |
514 | This behavior is undocumented and Bison | |
515 | users should not rely upon it. Assigning to YYVAL | |
516 | unconditionally makes the parser a bit smaller, and it avoids a | |
517 | GCC warning that YYVAL may be used uninitialized. */ | |
5912531f | 518 | yyval = ps[1-parser->yylen].val; |
0de566d7 | 519 | |
1654d593 | 520 | YY_STACK_PRINT(parser); |
0de566d7 | 521 | YY_REDUCE_PRINT (yyn); |
718a7425 | 522 | |
0de566d7 DM |
523 | switch (yyn) { |
524 | ||
0de566d7 DM |
525 | |
526 | #define dep() deprecate("\"do\" to call subroutines") | |
f05e27e5 | 527 | |
bc463c31 | 528 | #ifdef PERL_IN_MADLY_C |
f05e27e5 DM |
529 | # define IVAL(i) (i)->tk_lval.ival |
530 | # define PVAL(p) (p)->tk_lval.pval | |
531 | # define TOKEN_GETMAD(a,b,c) token_getmad((a),(b),(c)) | |
532 | # define TOKEN_FREE(a) token_free(a) | |
533 | # define OP_GETMAD(a,b,c) op_getmad((a),(b),(c)) | |
534 | # define IF_MAD(a,b) (a) | |
535 | # define DO_MAD(a) a | |
536 | # define MAD | |
bc463c31 | 537 | #else |
f05e27e5 DM |
538 | # define IVAL(i) (i) |
539 | # define PVAL(p) (p) | |
540 | # define TOKEN_GETMAD(a,b,c) | |
541 | # define TOKEN_FREE(a) | |
542 | # define OP_GETMAD(a,b,c) | |
543 | # define IF_MAD(a,b) (b) | |
544 | # define DO_MAD(a) | |
545 | # undef MAD | |
bc463c31 | 546 | #endif |
7b57b0ea | 547 | |
f05e27e5 DM |
548 | /* contains all the rule actions; auto-generated from perly.y */ |
549 | #include "perly.act" | |
550 | ||
93a17b20 | 551 | } |
0de566d7 | 552 | |
670f3923 DM |
553 | /* any just-reduced ops with the op_latefreed flag cleared need to be |
554 | * freed; the rest need the flag resetting */ | |
555 | { | |
556 | int i; | |
5912531f | 557 | for (i=0; i< parser->yylen; i++) { |
8c63ea58 | 558 | #ifndef DISABLE_STACK_FREE |
1654d593 DM |
559 | if (yy_type_tab[yystos[ps[-i].state]] == toketype_opval |
560 | && ps[-i].val.opval) | |
670f3923 | 561 | { |
1654d593 DM |
562 | ps[-i].val.opval->op_latefree = 0; |
563 | if (ps[-i].val.opval->op_latefreed) | |
564 | op_free(ps[-i].val.opval); | |
670f3923 | 565 | } |
8c63ea58 GG |
566 | #endif |
567 | SvREFCNT_dec(ps[-i].compcv); | |
670f3923 DM |
568 | } |
569 | } | |
570 | ||
5912531f | 571 | parser->ps = ps -= (parser->yylen-1); |
0de566d7 | 572 | |
05a03161 DM |
573 | /* Now shift the result of the reduction. Determine what state |
574 | that goes to, based on the state we popped back to and the rule | |
575 | number reduced by. */ | |
576 | ||
1654d593 | 577 | ps->val = yyval; |
ec8ec19f | 578 | ps->compcv = (CV*)SvREFCNT_inc(PL_compcv); |
503de470 | 579 | ps->savestack_ix = PL_savestack_ix; |
9388183f | 580 | #ifdef DEBUGGING |
1654d593 | 581 | ps->name = (const char *)(yytname [yyr1[yyn]]); |
9388183f | 582 | #endif |
0de566d7 DM |
583 | |
584 | yyn = yyr1[yyn]; | |
585 | ||
1654d593 DM |
586 | yystate = yypgoto[yyn - YYNTOKENS] + ps[-1].state; |
587 | if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == ps[-1].state) | |
0de566d7 | 588 | yystate = yytable[yystate]; |
93a17b20 | 589 | else |
0de566d7 | 590 | yystate = yydefgoto[yyn - YYNTOKENS]; |
1654d593 | 591 | ps->state = yystate; |
05a03161 | 592 | |
0de566d7 DM |
593 | goto yynewstate; |
594 | ||
595 | ||
596 | /*------------------------------------. | |
597 | | yyerrlab -- here on detecting error | | |
598 | `------------------------------------*/ | |
599 | yyerrlab: | |
600 | /* If not already recovering from an error, report this error. */ | |
5912531f | 601 | if (!parser->yyerrstatus) { |
07a06489 | 602 | yyerror ("syntax error"); |
93a17b20 | 603 | } |
0de566d7 DM |
604 | |
605 | ||
5912531f | 606 | if (parser->yyerrstatus == 3) { |
0de566d7 DM |
607 | /* If just tried and failed to reuse lookahead token after an |
608 | error, discard it. */ | |
609 | ||
610 | /* Return failure if at end of input. */ | |
5912531f | 611 | if (parser->yychar == YYEOF) { |
0de566d7 | 612 | /* Pop the error token. */ |
8c63ea58 | 613 | SvREFCNT_dec(ps->compcv); |
0de566d7 DM |
614 | YYPOPSTACK; |
615 | /* Pop the rest of the stack. */ | |
22735491 | 616 | while (ps > parser->stack) { |
1654d593 | 617 | YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val); |
503de470 | 618 | LEAVE_SCOPE(ps->savestack_ix); |
1654d593 DM |
619 | if (yy_type_tab[yystos[ps->state]] == toketype_opval |
620 | && ps->val.opval) | |
670f3923 | 621 | { |
0539ab63 | 622 | YYDPRINTF ((Perl_debug_log, "(freeing op)\n")); |
8c63ea58 GG |
623 | if (ps->compcv != PL_compcv) { |
624 | PL_compcv = ps->compcv; | |
625 | PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1); | |
718a7425 | 626 | } |
1654d593 DM |
627 | ps->val.opval->op_latefree = 0; |
628 | op_free(ps->val.opval); | |
0539ab63 | 629 | } |
8c63ea58 | 630 | SvREFCNT_dec(ps->compcv); |
0de566d7 DM |
631 | YYPOPSTACK; |
632 | } | |
633 | YYABORT; | |
634 | } | |
635 | ||
5912531f | 636 | YYDSYMPRINTF ("Error: discarding", yytoken, &parser->yylval); |
0e38ac78 GG |
637 | if (yy_type_tab[yytoken] == toketype_opval) |
638 | op_free(parser->yylval.opval); | |
5912531f | 639 | parser->yychar = YYEMPTY; |
0de566d7 | 640 | |
93a17b20 | 641 | } |
0de566d7 DM |
642 | |
643 | /* Else will try to reuse lookahead token after shifting the error | |
644 | token. */ | |
645 | goto yyerrlab1; | |
646 | ||
647 | ||
648 | /*----------------------------------------------------. | |
649 | | yyerrlab1 -- error raised explicitly by an action. | | |
650 | `----------------------------------------------------*/ | |
651 | yyerrlab1: | |
5912531f | 652 | parser->yyerrstatus = 3; /* Each real token shifted decrements this. */ |
0de566d7 DM |
653 | |
654 | for (;;) { | |
655 | yyn = yypact[yystate]; | |
656 | if (yyn != YYPACT_NINF) { | |
657 | yyn += YYTERROR; | |
658 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { | |
659 | yyn = yytable[yyn]; | |
660 | if (0 < yyn) | |
661 | break; | |
662 | } | |
663 | } | |
664 | ||
665 | /* Pop the current state because it cannot handle the error token. */ | |
22735491 | 666 | if (ps == parser->stack) |
0de566d7 DM |
667 | YYABORT; |
668 | ||
1654d593 | 669 | YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val); |
503de470 | 670 | LEAVE_SCOPE(ps->savestack_ix); |
1654d593 | 671 | if (yy_type_tab[yystos[ps->state]] == toketype_opval && ps->val.opval) { |
0539ab63 | 672 | YYDPRINTF ((Perl_debug_log, "(freeing op)\n")); |
8c63ea58 GG |
673 | if (ps->compcv != PL_compcv) { |
674 | PL_compcv = ps->compcv; | |
675 | PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1); | |
718a7425 | 676 | } |
1654d593 DM |
677 | ps->val.opval->op_latefree = 0; |
678 | op_free(ps->val.opval); | |
0539ab63 | 679 | } |
8c63ea58 | 680 | SvREFCNT_dec(ps->compcv); |
1654d593 DM |
681 | YYPOPSTACK; |
682 | yystate = ps->state; | |
0de566d7 | 683 | |
1654d593 | 684 | YY_STACK_PRINT(parser); |
93a17b20 | 685 | } |
0de566d7 DM |
686 | |
687 | if (yyn == YYFINAL) | |
688 | YYACCEPT; | |
689 | ||
690 | YYDPRINTF ((Perl_debug_log, "Shifting error token, ")); | |
691 | ||
1654d593 DM |
692 | YYPUSHSTACK; |
693 | ps->state = yyn; | |
5912531f | 694 | ps->val = parser->yylval; |
ec8ec19f | 695 | ps->compcv = (CV*)SvREFCNT_inc(PL_compcv); |
503de470 | 696 | ps->savestack_ix = PL_savestack_ix; |
9388183f | 697 | #ifdef DEBUGGING |
1654d593 | 698 | ps->name ="<err>"; |
9388183f | 699 | #endif |
0de566d7 | 700 | |
0de566d7 DM |
701 | goto yynewstate; |
702 | ||
703 | ||
704 | /*-------------------------------------. | |
705 | | yyacceptlab -- YYACCEPT comes here. | | |
706 | `-------------------------------------*/ | |
707 | yyacceptlab: | |
708 | yyresult = 0; | |
8c63ea58 GG |
709 | for (ps=parser->ps; ps > parser->stack; ps--) { |
710 | SvREFCNT_dec(ps->compcv); | |
711 | } | |
22735491 | 712 | parser->ps = parser->stack; /* disable cleanup */ |
0de566d7 DM |
713 | goto yyreturn; |
714 | ||
715 | /*-----------------------------------. | |
716 | | yyabortlab -- YYABORT comes here. | | |
717 | `-----------------------------------*/ | |
718 | yyabortlab: | |
719 | yyresult = 1; | |
720 | goto yyreturn; | |
721 | ||
0de566d7 | 722 | yyreturn: |
e3abe207 | 723 | LEAVE; /* force parser stack cleanup before we return */ |
0de566d7 | 724 | return yyresult; |
e1f15930 | 725 | } |
66610fdd RGS |
726 | |
727 | /* | |
728 | * Local variables: | |
729 | * c-indentation-style: bsd | |
730 | * c-basic-offset: 4 | |
731 | * indent-tabs-mode: t | |
732 | * End: | |
733 | * | |
37442d52 RGS |
734 | * ex: set ts=8 sts=4 sw=4 noet: |
735 | */ |