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