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