This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Test-Simple to CPAN version 1.001006
[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{
eb578fdb
KW
239 int yystate;
240 int yyn;
0de566d7
DM
241 int yyresult;
242
0de566d7 243 /* Lookahead token as an internal (translated) token number. */
714c8e96 244 int yytoken = 0;
0de566d7 245
eb578fdb
KW
246 yy_parser *parser; /* the parser object */
247 yy_stack_frame *ps; /* current parser stack frame */
a0d0e21e 248
1654d593
DM
249#define YYPOPSTACK parser->ps = --ps
250#define YYPUSHSTACK parser->ps = ++ps
0de566d7 251
acdf0a21 252 /* The variable used to return semantic value and location from the
5912531f 253 action routines: ie $$. */
0de566d7
DM
254 YYSTYPE yyval;
255
0de566d7
DM
256 YYDPRINTF ((Perl_debug_log, "Starting parse\n"));
257
acdf0a21 258 parser = PL_parser;
1654d593 259
28ac2b49
Z
260 ENTER; /* force parser state cleanup/restoration before we return */
261 SAVEPPTR(parser->yylval.pval);
262 SAVEINT(parser->yychar);
263 SAVEINT(parser->yyerrstatus);
264 SAVEINT(parser->stack_size);
265 SAVEINT(parser->yylen);
266 SAVEVPTR(parser->stack);
267 SAVEVPTR(parser->ps);
268
269 /* initialise state for this parse */
270 parser->yychar = gramtype;
271 parser->yyerrstatus = 0;
272 parser->stack_size = YYINITDEPTH;
273 parser->yylen = 0;
274 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
275 ps = parser->ps = parser->stack;
276 ps->state = 0;
e3abe207 277 SAVEDESTRUCTOR_X(S_clear_yystack, parser);
0de566d7 278
0de566d7
DM
279/*------------------------------------------------------------.
280| yynewstate -- Push a new state, which is found in yystate. |
281`------------------------------------------------------------*/
282 yynewstate:
0de566d7 283
1654d593 284 yystate = ps->state;
05a03161 285
670f3923 286 YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
0de566d7 287
5912531f 288 parser->yylen = 0;
0de566d7 289
1654d593 290 {
22735491 291 size_t size = ps - parser->stack + 1;
0de566d7 292
1654d593
DM
293 /* grow the stack? We always leave 1 spare slot,
294 * in case of a '' -> 'foo' reduction */
0de566d7 295
85c508c3 296 if (size >= (size_t)parser->stack_size - 1) {
1654d593
DM
297 /* this will croak on insufficient memory */
298 parser->stack_size *= 2;
22735491
DM
299 Renew(parser->stack, parser->stack_size, yy_stack_frame);
300 ps = parser->ps = parser->stack + size -1;
670f3923 301
1654d593
DM
302 YYDPRINTF((Perl_debug_log,
303 "parser stack size increased to %lu frames\n",
304 (unsigned long int)parser->stack_size));
305 }
93a17b20 306 }
0de566d7 307
0de566d7
DM
308/* Do appropriate processing given the current state. */
309/* Read a lookahead token if we need one and don't already have one. */
0de566d7
DM
310
311 /* First try to decide what to do without reference to lookahead token. */
312
313 yyn = yypact[yystate];
314 if (yyn == YYPACT_NINF)
315 goto yydefault;
316
317 /* Not known => get a lookahead token if don't already have one. */
318
319 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
5912531f 320 if (parser->yychar == YYEMPTY) {
0de566d7 321 YYDPRINTF ((Perl_debug_log, "Reading a token: "));
5912531f 322 parser->yychar = yylex();
bc463c31 323
f4cd282c
KW
324/* perly.tab is shipped based on an ASCII system; if it were to be regenerated
325 * on a platform that doesn't use ASCII, this translation back would need to be
326 * removed */
12fbd33b 327# ifdef EBCDIC
5912531f 328 if (parser->yychar >= 0 && parser->yychar < 255) {
f4cd282c 329 parser->yychar = NATIVE_TO_LATIN1(parser->yychar);
12fbd33b
DM
330 }
331# endif
0de566d7
DM
332 }
333
5912531f
DM
334 if (parser->yychar <= YYEOF) {
335 parser->yychar = yytoken = YYEOF;
0de566d7 336 YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
93a17b20 337 }
0de566d7 338 else {
5912531f
DM
339 yytoken = YYTRANSLATE (parser->yychar);
340 YYDSYMPRINTF ("Next token is", yytoken, &parser->yylval);
93a17b20 341 }
771df094 342
0de566d7
DM
343 /* If the proper action on seeing token YYTOKEN is to reduce or to
344 detect an error, take that action. */
345 yyn += yytoken;
346 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
347 goto yydefault;
348 yyn = yytable[yyn];
349 if (yyn <= 0) {
350 if (yyn == 0 || yyn == YYTABLE_NINF)
351 goto yyerrlab;
352 yyn = -yyn;
353 goto yyreduce;
354 }
7b57b0ea 355
0de566d7
DM
356 if (yyn == YYFINAL)
357 YYACCEPT;
771df094 358
0de566d7
DM
359 /* Shift the lookahead token. */
360 YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));
361
362 /* Discard the token being shifted unless it is eof. */
5912531f
DM
363 if (parser->yychar != YYEOF)
364 parser->yychar = YYEMPTY;
0de566d7 365
1654d593
DM
366 YYPUSHSTACK;
367 ps->state = yyn;
5912531f 368 ps->val = parser->yylval;
ec8ec19f 369 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
503de470 370 ps->savestack_ix = PL_savestack_ix;
9388183f 371#ifdef DEBUGGING
1654d593 372 ps->name = (const char *)(yytname[yytoken]);
9388183f 373#endif
0de566d7 374
0de566d7
DM
375 /* Count tokens shifted since error; after three, turn off error
376 status. */
5912531f
DM
377 if (parser->yyerrstatus)
378 parser->yyerrstatus--;
0de566d7 379
0de566d7
DM
380 goto yynewstate;
381
382
383 /*-----------------------------------------------------------.
384 | yydefault -- do the default action for the current state. |
385 `-----------------------------------------------------------*/
386 yydefault:
387 yyn = yydefact[yystate];
388 if (yyn == 0)
389 goto yyerrlab;
390 goto yyreduce;
391
392
393 /*-----------------------------.
394 | yyreduce -- Do a reduction. |
395 `-----------------------------*/
396 yyreduce:
397 /* yyn is the number of a rule to reduce with. */
5912531f 398 parser->yylen = yyr2[yyn];
0de566d7
DM
399
400 /* If YYLEN is nonzero, implement the default value of the action:
a0288114 401 "$$ = $1".
0de566d7
DM
402
403 Otherwise, the following line sets YYVAL to garbage.
404 This behavior is undocumented and Bison
405 users should not rely upon it. Assigning to YYVAL
406 unconditionally makes the parser a bit smaller, and it avoids a
407 GCC warning that YYVAL may be used uninitialized. */
5912531f 408 yyval = ps[1-parser->yylen].val;
0de566d7 409
1654d593 410 YY_STACK_PRINT(parser);
0de566d7 411 YY_REDUCE_PRINT (yyn);
718a7425 412
0de566d7
DM
413 switch (yyn) {
414
f05e27e5
DM
415/* contains all the rule actions; auto-generated from perly.y */
416#include "perly.act"
417
93a17b20 418 }
0de566d7 419
670f3923
DM
420 {
421 int i;
5912531f 422 for (i=0; i< parser->yylen; i++) {
8c63ea58 423 SvREFCNT_dec(ps[-i].compcv);
670f3923
DM
424 }
425 }
426
5912531f 427 parser->ps = ps -= (parser->yylen-1);
0de566d7 428
05a03161
DM
429 /* Now shift the result of the reduction. Determine what state
430 that goes to, based on the state we popped back to and the rule
431 number reduced by. */
432
1654d593 433 ps->val = yyval;
ec8ec19f 434 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
503de470 435 ps->savestack_ix = PL_savestack_ix;
9388183f 436#ifdef DEBUGGING
1654d593 437 ps->name = (const char *)(yytname [yyr1[yyn]]);
9388183f 438#endif
0de566d7
DM
439
440 yyn = yyr1[yyn];
441
1654d593
DM
442 yystate = yypgoto[yyn - YYNTOKENS] + ps[-1].state;
443 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == ps[-1].state)
0de566d7 444 yystate = yytable[yystate];
93a17b20 445 else
0de566d7 446 yystate = yydefgoto[yyn - YYNTOKENS];
1654d593 447 ps->state = yystate;
05a03161 448
0de566d7
DM
449 goto yynewstate;
450
451
452 /*------------------------------------.
453 | yyerrlab -- here on detecting error |
454 `------------------------------------*/
455 yyerrlab:
456 /* If not already recovering from an error, report this error. */
5912531f 457 if (!parser->yyerrstatus) {
07a06489 458 yyerror ("syntax error");
93a17b20 459 }
0de566d7
DM
460
461
5912531f 462 if (parser->yyerrstatus == 3) {
0de566d7
DM
463 /* If just tried and failed to reuse lookahead token after an
464 error, discard it. */
465
466 /* Return failure if at end of input. */
5912531f 467 if (parser->yychar == YYEOF) {
0de566d7 468 /* Pop the error token. */
8c63ea58 469 SvREFCNT_dec(ps->compcv);
0de566d7
DM
470 YYPOPSTACK;
471 /* Pop the rest of the stack. */
22735491 472 while (ps > parser->stack) {
1654d593 473 YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
503de470 474 LEAVE_SCOPE(ps->savestack_ix);
1654d593
DM
475 if (yy_type_tab[yystos[ps->state]] == toketype_opval
476 && ps->val.opval)
670f3923 477 {
0539ab63 478 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
8c63ea58
GG
479 if (ps->compcv != PL_compcv) {
480 PL_compcv = ps->compcv;
481 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
718a7425 482 }
1654d593 483 op_free(ps->val.opval);
0539ab63 484 }
8c63ea58 485 SvREFCNT_dec(ps->compcv);
0de566d7
DM
486 YYPOPSTACK;
487 }
488 YYABORT;
489 }
490
5912531f
DM
491 YYDSYMPRINTF ("Error: discarding", yytoken, &parser->yylval);
492 parser->yychar = YYEMPTY;
0de566d7 493
93a17b20 494 }
0de566d7
DM
495
496 /* Else will try to reuse lookahead token after shifting the error
497 token. */
498 goto yyerrlab1;
499
500
501 /*----------------------------------------------------.
502 | yyerrlab1 -- error raised explicitly by an action. |
503 `----------------------------------------------------*/
504 yyerrlab1:
5912531f 505 parser->yyerrstatus = 3; /* Each real token shifted decrements this. */
0de566d7
DM
506
507 for (;;) {
508 yyn = yypact[yystate];
509 if (yyn != YYPACT_NINF) {
510 yyn += YYTERROR;
511 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
512 yyn = yytable[yyn];
513 if (0 < yyn)
514 break;
515 }
516 }
517
518 /* Pop the current state because it cannot handle the error token. */
22735491 519 if (ps == parser->stack)
0de566d7
DM
520 YYABORT;
521
1654d593 522 YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
503de470 523 LEAVE_SCOPE(ps->savestack_ix);
1654d593 524 if (yy_type_tab[yystos[ps->state]] == toketype_opval && ps->val.opval) {
0539ab63 525 YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
8c63ea58
GG
526 if (ps->compcv != PL_compcv) {
527 PL_compcv = ps->compcv;
528 PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
718a7425 529 }
1654d593 530 op_free(ps->val.opval);
0539ab63 531 }
8c63ea58 532 SvREFCNT_dec(ps->compcv);
1654d593
DM
533 YYPOPSTACK;
534 yystate = ps->state;
0de566d7 535
1654d593 536 YY_STACK_PRINT(parser);
93a17b20 537 }
0de566d7
DM
538
539 if (yyn == YYFINAL)
540 YYACCEPT;
541
542 YYDPRINTF ((Perl_debug_log, "Shifting error token, "));
543
1654d593
DM
544 YYPUSHSTACK;
545 ps->state = yyn;
5912531f 546 ps->val = parser->yylval;
ec8ec19f 547 ps->compcv = (CV*)SvREFCNT_inc(PL_compcv);
503de470 548 ps->savestack_ix = PL_savestack_ix;
9388183f 549#ifdef DEBUGGING
1654d593 550 ps->name ="<err>";
9388183f 551#endif
0de566d7 552
0de566d7
DM
553 goto yynewstate;
554
555
556 /*-------------------------------------.
557 | yyacceptlab -- YYACCEPT comes here. |
558 `-------------------------------------*/
559 yyacceptlab:
560 yyresult = 0;
8c63ea58
GG
561 for (ps=parser->ps; ps > parser->stack; ps--) {
562 SvREFCNT_dec(ps->compcv);
563 }
22735491 564 parser->ps = parser->stack; /* disable cleanup */
0de566d7
DM
565 goto yyreturn;
566
567 /*-----------------------------------.
568 | yyabortlab -- YYABORT comes here. |
569 `-----------------------------------*/
570 yyabortlab:
571 yyresult = 1;
572 goto yyreturn;
573
0de566d7 574 yyreturn:
e3abe207 575 LEAVE; /* force parser stack cleanup before we return */
0de566d7 576 return yyresult;
e1f15930 577}
66610fdd
RGS
578
579/*
580 * Local variables:
581 * c-indentation-style: bsd
582 * c-basic-offset: 4
14d04a33 583 * indent-tabs-mode: nil
66610fdd
RGS
584 * End:
585 *
14d04a33 586 * ex: set ts=8 sts=4 sw=4 et:
37442d52 587 */