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