This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Correct two subtle typos.
[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 21 *
0de566d7
DM
22 */
23
79072805 24#include "EXTERN.h"
864dbfa3 25#define PERL_IN_PERLY_C
79072805 26#include "perl.h"
30d9c59b 27#include "feature.h"
09bef843 28
3797f23d
DM
29typedef unsigned char yytype_uint8;
30typedef signed char yytype_int8;
31typedef unsigned short int yytype_uint16;
32typedef short int yytype_int16;
0de566d7
DM
33typedef signed char yysigned_char;
34
28ac2b49
Z
35/* YYINITDEPTH -- initial size of the parser's stacks. */
36#define YYINITDEPTH 200
37
599f1ac6
FC
38#ifdef YYDEBUG
39# undef YYDEBUG
40#endif
41#ifdef DEBUGGING
42# define YYDEBUG 1
43#else
44# define YYDEBUG 0
45#endif
46
b3045d9c
FC
47#ifndef YY_NULL
48# define YY_NULL 0
93a17b20 49#endif
09bef843 50
f05e27e5
DM
51/* contains all the parser state tables; auto-generated from perly.y */
52#include "perly.tab"
0de566d7
DM
53
54# define YYSIZE_T size_t
55
0de566d7 56#define YYEOF 0
07a06489 57#define YYTERROR 1
0de566d7
DM
58
59#define YYACCEPT goto yyacceptlab
60#define YYABORT goto yyabortlab
61#define YYERROR goto yyerrlab1
62
0de566d7 63/* Enable debugging if requested. */
9388183f 64#ifdef DEBUGGING
0de566d7
DM
65
66# define yydebug (DEBUG_p_TEST)
67
68# define YYFPRINTF PerlIO_printf
69
70# define YYDPRINTF(Args) \
71do { \
72 if (yydebug) \
73 YYFPRINTF Args; \
74} while (0)
75
9388183f 76# define YYDSYMPRINTF(Title, Token, Value) \
0de566d7
DM
77do { \
78 if (yydebug) { \
79 YYFPRINTF (Perl_debug_log, "%s ", Title); \
356f4fed 80 yysymprint (aTHX_ Perl_debug_log, Token, Value); \
0de566d7
DM
81 YYFPRINTF (Perl_debug_log, "\n"); \
82 } \
83} while (0)
84
85/*--------------------------------.
86| Print this symbol on YYOUTPUT. |
87`--------------------------------*/
88
89static void
356f4fed 90yysymprint(pTHX_ PerlIO * const yyoutput, int yytype, const YYSTYPE * const yyvaluep)
0de566d7 91{
dc3bf405 92 PERL_UNUSED_CONTEXT;
0de566d7
DM
93 if (yytype < YYNTOKENS) {
94 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
95# ifdef YYPRINT
96 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
9388183f 97# else
e4584336 98 YYFPRINTF (yyoutput, "0x%"UVxf, (UV)yyvaluep->ival);
0de566d7
DM
99# endif
100 }
101 else
102 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
103
0de566d7
DM
104 YYFPRINTF (yyoutput, ")");
105}
106
107
9388183f 108/* yy_stack_print()
1654d593
DM
109 * print the top 8 items on the parse stack.
110 */
0de566d7
DM
111
112static void
1654d593 113yy_stack_print (pTHX_ const yy_parser *parser)
0de566d7 114{
1654d593 115 const yy_stack_frame *ps, *min;
9388183f 116
2d29f438 117 min = parser->ps - 8 + 1;
22735491
DM
118 if (min <= parser->stack)
119 min = parser->stack + 1;
9388183f
CB
120
121 PerlIO_printf(Perl_debug_log, "\nindex:");
1654d593 122 for (ps = min; ps <= parser->ps; ps++)
00c0e1ee 123 PerlIO_printf(Perl_debug_log, " %8d", (int)(ps - parser->stack));
1654d593 124
9388183f 125 PerlIO_printf(Perl_debug_log, "\nstate:");
1654d593
DM
126 for (ps = min; ps <= parser->ps; ps++)
127 PerlIO_printf(Perl_debug_log, " %8d", ps->state);
128
9388183f 129 PerlIO_printf(Perl_debug_log, "\ntoken:");
1654d593
DM
130 for (ps = min; ps <= parser->ps; ps++)
131 PerlIO_printf(Perl_debug_log, " %8.8s", ps->name);
132
9388183f 133 PerlIO_printf(Perl_debug_log, "\nvalue:");
1654d593
DM
134 for (ps = min; ps <= parser->ps; ps++) {
135 switch (yy_type_tab[yystos[ps->state]]) {
d5c6462e 136 case toketype_opval:
21612876 137 PerlIO_printf(Perl_debug_log, " %8.8s",
1654d593
DM
138 ps->val.opval
139 ? PL_op_name[ps->val.opval->op_type]
670f3923 140 : "(Nullop)"
21612876 141 );
d5c6462e 142 break;
d5c6462e 143 case toketype_ival:
1654d593 144 PerlIO_printf(Perl_debug_log, " %8"IVdf, (IV)ps->val.ival);
d5c6462e
DM
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
DM
151}
152
1654d593
DM
153# define YY_STACK_PRINT(parser) \
154do { \
155 if (yydebug && DEBUG_v_TEST) \
156 yy_stack_print (aTHX_ parser); \
0de566d7
DM
157} while (0)
158
09bef843 159
0de566d7
DM
160/*------------------------------------------------.
161| Report that the YYRULE is going to be reduced. |
162`------------------------------------------------*/
163
164static void
165yy_reduce_print (pTHX_ int yyrule)
166{
167 int yyi;
df35152e 168 const unsigned int yylineno = yyrline[yyrule];
0de566d7
DM
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) \
178do { \
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
DM
187# define YY_REDUCE_PRINT(Rule)
188#endif /* !DEBUGGING */
189
718a7425
DM
190/* called during cleanup (via SAVEDESTRUCTOR_X) to free any items on the
191 * parse stack, thus avoiding leaks if we die */
192
193static void
22735491 194S_clear_yystack(pTHX_ const yy_parser *parser)
718a7425 195{
1654d593 196 yy_stack_frame *ps = parser->ps;
0934c9d9 197 int i = 0;
718a7425 198
28ac2b49 199 if (!parser->stack)
718a7425 200 return;
1654d593 201
718a7425 202 YYDPRINTF ((Perl_debug_log, "clearing the parse stack\n"));
670f3923 203
8c63ea58
GG
204 for (i=0; i< parser->yylen; i++) {
205 SvREFCNT_dec(ps[-i].compcv);
206 }
0aded6e1 207 ps -= parser->yylen;
670f3923
DM
208
209 /* now free whole the stack, including the just-reduced ops */
210
22735491 211 while (ps > parser->stack) {
503de470 212 LEAVE_SCOPE(ps->savestack_ix);
1654d593
DM
213 if (yy_type_tab[yystos[ps->state]] == toketype_opval
214 && ps->val.opval)
670f3923 215 {
8c63ea58
GG
216 if (ps->compcv != PL_compcv) {
217 PL_compcv = ps->compcv;
218 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
325e1816 219 PL_comppad_name = PadlistNAMES(CvPADLIST(PL_compcv));
718a7425
DM
220 }
221 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
571a568a 222 op_free(ps->val.opval);
718a7425 223 }
8c63ea58 224 SvREFCNT_dec(ps->compcv);
1654d593 225 ps--;
718a7425 226 }
28ac2b49
Z
227
228 Safefree(parser->stack);
718a7425
DM
229}
230
718a7425 231
0de566d7
DM
232/*----------.
233| yyparse. |
234`----------*/
235
79072805 236int
28ac2b49 237Perl_yyparse (pTHX_ int gramtype)
79072805 238{
97aff369 239 dVAR;
eb578fdb
KW
240 int yystate;
241 int yyn;
0de566d7
DM
242 int yyresult;
243
0de566d7 244 /* Lookahead token as an internal (translated) token number. */
714c8e96 245 int yytoken = 0;
0de566d7 246
eb578fdb
KW
247 yy_parser *parser; /* the parser object */
248 yy_stack_frame *ps; /* current parser stack frame */
a0d0e21e 249
1654d593
DM
250#define YYPOPSTACK parser->ps = --ps
251#define YYPUSHSTACK parser->ps = ++ps
0de566d7 252
acdf0a21 253 /* The variable used to return semantic value and location from the
5912531f 254 action routines: ie $$. */
0de566d7
DM
255 YYSTYPE yyval;
256
0de566d7
DM
257 YYDPRINTF ((Perl_debug_log, "Starting parse\n"));
258
acdf0a21 259 parser = PL_parser;
1654d593 260
28ac2b49
Z
261 ENTER; /* force parser state cleanup/restoration before we return */
262 SAVEPPTR(parser->yylval.pval);
263 SAVEINT(parser->yychar);
264 SAVEINT(parser->yyerrstatus);
265 SAVEINT(parser->stack_size);
266 SAVEINT(parser->yylen);
267 SAVEVPTR(parser->stack);
268 SAVEVPTR(parser->ps);
269
270 /* initialise state for this parse */
271 parser->yychar = gramtype;
272 parser->yyerrstatus = 0;
273 parser->stack_size = YYINITDEPTH;
274 parser->yylen = 0;
275 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
276 ps = parser->ps = parser->stack;
277 ps->state = 0;
e3abe207 278 SAVEDESTRUCTOR_X(S_clear_yystack, parser);
0de566d7 279
0de566d7
DM
280/*------------------------------------------------------------.
281| yynewstate -- Push a new state, which is found in yystate. |
282`------------------------------------------------------------*/
283 yynewstate:
0de566d7 284
1654d593 285 yystate = ps->state;
05a03161 286
670f3923 287 YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
0de566d7 288
5912531f 289 parser->yylen = 0;
0de566d7 290
1654d593 291 {
22735491 292 size_t size = ps - parser->stack + 1;
0de566d7 293
1654d593
DM
294 /* grow the stack? We always leave 1 spare slot,
295 * in case of a '' -> 'foo' reduction */
0de566d7 296
85c508c3 297 if (size >= (size_t)parser->stack_size - 1) {
1654d593
DM
298 /* this will croak on insufficient memory */
299 parser->stack_size *= 2;
22735491
DM
300 Renew(parser->stack, parser->stack_size, yy_stack_frame);
301 ps = parser->ps = parser->stack + size -1;
670f3923 302
1654d593
DM
303 YYDPRINTF((Perl_debug_log,
304 "parser stack size increased to %lu frames\n",
305 (unsigned long int)parser->stack_size));
306 }
93a17b20 307 }
0de566d7 308
0de566d7
DM
309/* Do appropriate processing given the current state. */
310/* Read a lookahead token if we need one and don't already have one. */
0de566d7
DM
311
312 /* First try to decide what to do without reference to lookahead token. */
313
314 yyn = yypact[yystate];
315 if (yyn == YYPACT_NINF)
316 goto yydefault;
317
318 /* Not known => get a lookahead token if don't already have one. */
319
320 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
5912531f 321 if (parser->yychar == YYEMPTY) {
0de566d7 322 YYDPRINTF ((Perl_debug_log, "Reading a token: "));
5912531f 323 parser->yychar = yylex();
bc463c31 324
f4cd282c
KW
325/* perly.tab is shipped based on an ASCII system; if it were to be regenerated
326 * on a platform that doesn't use ASCII, this translation back would need to be
327 * removed */
12fbd33b 328# ifdef EBCDIC
5912531f 329 if (parser->yychar >= 0 && parser->yychar < 255) {
f4cd282c 330 parser->yychar = NATIVE_TO_LATIN1(parser->yychar);
12fbd33b
DM
331 }
332# endif
0de566d7
DM
333 }
334
5912531f
DM
335 if (parser->yychar <= YYEOF) {
336 parser->yychar = yytoken = YYEOF;
0de566d7 337 YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
93a17b20 338 }
0de566d7 339 else {
5912531f
DM
340 yytoken = YYTRANSLATE (parser->yychar);
341 YYDSYMPRINTF ("Next token is", yytoken, &parser->yylval);
93a17b20 342 }
771df094 343
0de566d7
DM
344 /* If the proper action on seeing token YYTOKEN is to reduce or to
345 detect an error, take that action. */
346 yyn += yytoken;
347 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
348 goto yydefault;
349 yyn = yytable[yyn];
350 if (yyn <= 0) {
351 if (yyn == 0 || yyn == YYTABLE_NINF)
352 goto yyerrlab;
353 yyn = -yyn;
354 goto yyreduce;
355 }
7b57b0ea 356
0de566d7
DM
357 if (yyn == YYFINAL)
358 YYACCEPT;
771df094 359
0de566d7
DM
360 /* Shift the lookahead token. */
361 YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));
362
363 /* Discard the token being shifted unless it is eof. */
5912531f
DM
364 if (parser->yychar != YYEOF)
365 parser->yychar = YYEMPTY;
0de566d7 366
1654d593
DM
367 YYPUSHSTACK;
368 ps->state = yyn;
5912531f 369 ps->val = parser->yylval;
ec8ec19f 370 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
503de470 371 ps->savestack_ix = PL_savestack_ix;
9388183f 372#ifdef DEBUGGING
1654d593 373 ps->name = (const char *)(yytname[yytoken]);
9388183f 374#endif
0de566d7 375
0de566d7
DM
376 /* Count tokens shifted since error; after three, turn off error
377 status. */
5912531f
DM
378 if (parser->yyerrstatus)
379 parser->yyerrstatus--;
0de566d7 380
0de566d7
DM
381 goto yynewstate;
382
383
384 /*-----------------------------------------------------------.
385 | yydefault -- do the default action for the current state. |
386 `-----------------------------------------------------------*/
387 yydefault:
388 yyn = yydefact[yystate];
389 if (yyn == 0)
390 goto yyerrlab;
391 goto yyreduce;
392
393
394 /*-----------------------------.
395 | yyreduce -- Do a reduction. |
396 `-----------------------------*/
397 yyreduce:
398 /* yyn is the number of a rule to reduce with. */
5912531f 399 parser->yylen = yyr2[yyn];
0de566d7
DM
400
401 /* If YYLEN is nonzero, implement the default value of the action:
a0288114 402 "$$ = $1".
0de566d7
DM
403
404 Otherwise, the following line sets YYVAL to garbage.
405 This behavior is undocumented and Bison
406 users should not rely upon it. Assigning to YYVAL
407 unconditionally makes the parser a bit smaller, and it avoids a
408 GCC warning that YYVAL may be used uninitialized. */
5912531f 409 yyval = ps[1-parser->yylen].val;
0de566d7 410
1654d593 411 YY_STACK_PRINT(parser);
0de566d7 412 YY_REDUCE_PRINT (yyn);
718a7425 413
0de566d7
DM
414 switch (yyn) {
415
f05e27e5
DM
416/* contains all the rule actions; auto-generated from perly.y */
417#include "perly.act"
418
93a17b20 419 }
0de566d7 420
670f3923
DM
421 {
422 int i;
5912531f 423 for (i=0; i< parser->yylen; i++) {
8c63ea58 424 SvREFCNT_dec(ps[-i].compcv);
670f3923
DM
425 }
426 }
427
5912531f 428 parser->ps = ps -= (parser->yylen-1);
0de566d7 429
05a03161
DM
430 /* Now shift the result of the reduction. Determine what state
431 that goes to, based on the state we popped back to and the rule
432 number reduced by. */
433
1654d593 434 ps->val = yyval;
ec8ec19f 435 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
503de470 436 ps->savestack_ix = PL_savestack_ix;
9388183f 437#ifdef DEBUGGING
1654d593 438 ps->name = (const char *)(yytname [yyr1[yyn]]);
9388183f 439#endif
0de566d7
DM
440
441 yyn = yyr1[yyn];
442
1654d593
DM
443 yystate = yypgoto[yyn - YYNTOKENS] + ps[-1].state;
444 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == ps[-1].state)
0de566d7 445 yystate = yytable[yystate];
93a17b20 446 else
0de566d7 447 yystate = yydefgoto[yyn - YYNTOKENS];
1654d593 448 ps->state = yystate;
05a03161 449
0de566d7
DM
450 goto yynewstate;
451
452
453 /*------------------------------------.
454 | yyerrlab -- here on detecting error |
455 `------------------------------------*/
456 yyerrlab:
457 /* If not already recovering from an error, report this error. */
5912531f 458 if (!parser->yyerrstatus) {
07a06489 459 yyerror ("syntax error");
93a17b20 460 }
0de566d7
DM
461
462
5912531f 463 if (parser->yyerrstatus == 3) {
0de566d7
DM
464 /* If just tried and failed to reuse lookahead token after an
465 error, discard it. */
466
467 /* Return failure if at end of input. */
5912531f 468 if (parser->yychar == YYEOF) {
0de566d7 469 /* Pop the error token. */
8c63ea58 470 SvREFCNT_dec(ps->compcv);
0de566d7
DM
471 YYPOPSTACK;
472 /* Pop the rest of the stack. */
22735491 473 while (ps > parser->stack) {
1654d593 474 YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
503de470 475 LEAVE_SCOPE(ps->savestack_ix);
1654d593
DM
476 if (yy_type_tab[yystos[ps->state]] == toketype_opval
477 && ps->val.opval)
670f3923 478 {
0539ab63 479 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
8c63ea58
GG
480 if (ps->compcv != PL_compcv) {
481 PL_compcv = ps->compcv;
482 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
718a7425 483 }
1654d593 484 op_free(ps->val.opval);
0539ab63 485 }
8c63ea58 486 SvREFCNT_dec(ps->compcv);
0de566d7
DM
487 YYPOPSTACK;
488 }
489 YYABORT;
490 }
491
5912531f
DM
492 YYDSYMPRINTF ("Error: discarding", yytoken, &parser->yylval);
493 parser->yychar = YYEMPTY;
0de566d7 494
93a17b20 495 }
0de566d7
DM
496
497 /* Else will try to reuse lookahead token after shifting the error
498 token. */
499 goto yyerrlab1;
500
501
502 /*----------------------------------------------------.
503 | yyerrlab1 -- error raised explicitly by an action. |
504 `----------------------------------------------------*/
505 yyerrlab1:
5912531f 506 parser->yyerrstatus = 3; /* Each real token shifted decrements this. */
0de566d7
DM
507
508 for (;;) {
509 yyn = yypact[yystate];
510 if (yyn != YYPACT_NINF) {
511 yyn += YYTERROR;
512 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
513 yyn = yytable[yyn];
514 if (0 < yyn)
515 break;
516 }
517 }
518
519 /* Pop the current state because it cannot handle the error token. */
22735491 520 if (ps == parser->stack)
0de566d7
DM
521 YYABORT;
522
1654d593 523 YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
503de470 524 LEAVE_SCOPE(ps->savestack_ix);
1654d593 525 if (yy_type_tab[yystos[ps->state]] == toketype_opval && ps->val.opval) {
0539ab63 526 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
8c63ea58
GG
527 if (ps->compcv != PL_compcv) {
528 PL_compcv = ps->compcv;
529 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
718a7425 530 }
1654d593 531 op_free(ps->val.opval);
0539ab63 532 }
8c63ea58 533 SvREFCNT_dec(ps->compcv);
1654d593
DM
534 YYPOPSTACK;
535 yystate = ps->state;
0de566d7 536
1654d593 537 YY_STACK_PRINT(parser);
93a17b20 538 }
0de566d7
DM
539
540 if (yyn == YYFINAL)
541 YYACCEPT;
542
543 YYDPRINTF ((Perl_debug_log, "Shifting error token, "));
544
1654d593
DM
545 YYPUSHSTACK;
546 ps->state = yyn;
5912531f 547 ps->val = parser->yylval;
ec8ec19f 548 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
503de470 549 ps->savestack_ix = PL_savestack_ix;
9388183f 550#ifdef DEBUGGING
1654d593 551 ps->name ="<err>";
9388183f 552#endif
0de566d7 553
0de566d7
DM
554 goto yynewstate;
555
556
557 /*-------------------------------------.
558 | yyacceptlab -- YYACCEPT comes here. |
559 `-------------------------------------*/
560 yyacceptlab:
561 yyresult = 0;
8c63ea58
GG
562 for (ps=parser->ps; ps > parser->stack; ps--) {
563 SvREFCNT_dec(ps->compcv);
564 }
22735491 565 parser->ps = parser->stack; /* disable cleanup */
0de566d7
DM
566 goto yyreturn;
567
568 /*-----------------------------------.
569 | yyabortlab -- YYABORT comes here. |
570 `-----------------------------------*/
571 yyabortlab:
572 yyresult = 1;
573 goto yyreturn;
574
0de566d7 575 yyreturn:
e3abe207 576 LEAVE; /* force parser stack cleanup before we return */
0de566d7 577 return yyresult;
e1f15930 578}
66610fdd
RGS
579
580/*
581 * Local variables:
582 * c-indentation-style: bsd
583 * c-basic-offset: 4
14d04a33 584 * indent-tabs-mode: nil
66610fdd
RGS
585 * End:
586 *
14d04a33 587 * ex: set ts=8 sts=4 sw=4 et:
37442d52 588 */