3 * Copyright (c) 1991-2002, 2003, 2004, 2005, 2006 Larry Wall
4 * Copyright (c) 2007, 2008, 2009, 2010, 2011 by Larry Wall and others
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.
12 * 'I see,' laughed Strider. 'I look foul and feel fair. Is that it?
13 * All that is gold does not glitter, not all those who wander are lost.'
15 * [p.171 of _The Lord of the Rings_, I/x: "Strider"]
19 * This file holds the grammar for the Perl language. If edited, you need
20 * to run regen_perly.pl, which re-creates the files perly.h, perly.tab
21 * and perly.act which are derived from this.
23 * The main job of this grammar is to call the various newFOO()
24 * functions in op.c to build a syntax tree of OP structs.
25 * It relies on the lexer in toke.c to do the tokenizing.
27 * Note: due to the way that the cleanup code works WRT to freeing ops on
28 * the parse stack, it is dangerous to assign to the $n variables within
32 /* Make the parser re-entrant. */
39 I32 ival; /* __DEFAULT__ (marker for regen_perly.pl;
40 must always be 1st union member) */
46 %token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ GRAMSUBSIGNATURE
48 /* Tokens emitted by toke.c for simple punctiation characters - &, {, }, etc... */
49 %token <ival> PERLY_AMPERSAND
50 %token <ival> PERLY_BRACE_OPEN
51 %token <ival> PERLY_BRACE_CLOSE
52 %token <ival> PERLY_BRACKET_OPEN
53 %token <ival> PERLY_BRACKET_CLOSE
54 %token <ival> PERLY_COMMA
55 %token <ival> PERLY_DOLLAR
56 %token <ival> PERLY_DOT
57 %token <ival> PERLY_EQUAL_SIGN
58 %token <ival> PERLY_MINUS
59 %token <ival> PERLY_PERCENT_SIGN
60 %token <ival> PERLY_PLUS
61 %token <ival> PERLY_SEMICOLON
62 %token <ival> PERLY_SLASH
63 %token <ival> PERLY_SNAIL
64 %token <ival> PERLY_STAR
66 /* Tokens emitted by toke.c on simple keywords */
67 %token <ival> KW_FORMAT KW_PACKAGE KW_CLASS
68 %token <ival> KW_LOCAL KW_MY KW_FIELD
69 %token <ival> KW_IF KW_ELSE KW_ELSIF KW_UNLESS
70 %token <ival> KW_FOR KW_UNTIL KW_WHILE KW_CONTINUE
71 %token <ival> KW_GIVEN KW_WHEN KW_DEFAULT
72 %token <ival> KW_TRY KW_CATCH KW_FINALLY KW_DEFER
73 %token <ival> KW_REQUIRE KW_DO
75 /* The 'use' and 'no' keywords both emit this */
76 %token <ival> KW_USE_or_NO
78 /* The 'sub' keyword is a bit special; four different tokens depending on
79 * named-vs-anon, and whether signatures are in effect */
80 %token <ival> KW_SUB_named KW_SUB_named_sig KW_SUB_anon KW_SUB_anon_sig
81 %token <ival> KW_METHOD_named KW_METHOD_anon
83 /* Tokens emitted in other situations */
84 %token <opval> BAREWORD METHCALL0 METHCALL THING PMFUNC PRIVATEREF QWLIST
85 %token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
86 %token <opval> PLUGEXPR PLUGSTMT
88 %token <ival> LOOPEX DOTDOT YADAYADA
89 %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
90 %token <ival> POWOP MULOP ADDOP
91 %token <ival> DOLSHARP HASHBRACK NOAMP
92 %token <ival> COLONATTR FORMLBRACK FORMRBRACK
93 %token <ival> SUBLEXSTART SUBLEXEND
96 %type <ival> grammar remember mremember
97 %type <ival> startsub startanonsub startanonmethod startformsub
101 %type <ival> sigsub_or_method_named
102 %type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else finally
103 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
104 %type <opval> condition
105 %type <opval> catch_paren
107 %type <opval> sliceme kvslice gelem
108 %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
109 %type <opval> optlistexpr optexpr optrepl indirob listop methodname
110 %type <opval> formname subname proto cont my_scalar my_var
111 %type <opval> list_of_scalars my_list_of_scalars refgen_topic formblock
112 %type <opval> subattrlist myattrlist myattrterm myterm
113 %type <pval> fieldvar /* pval is PADNAME */
114 %type <opval> optfieldattrlist fielddecl
115 %type <opval> termbinop termunop anonymous termdo
116 %type <opval> termrelop relopchain termeqop eqopchain
117 %type <ival> sigslurpsigil
118 %type <opval> sigvarname sigdefault sigscalarelem sigslurpelem
119 %type <opval> sigelem siglist optsiglist subsigguts subsignature optsubsignature
120 %type <opval> subbody optsubbody sigsubbody optsigsubbody
121 %type <opval> formstmtseq formline formarg
123 %nonassoc <ival> PREC_LOW
126 %nonassoc <pval> PLUGIN_LOW_OP
127 %left <ival> OROP <pval> PLUGIN_LOGICAL_OR_LOW_OP
128 %left <ival> ANDOP <pval> PLUGIN_LOGICAL_AND_LOW_OP
130 %nonassoc LSTOP LSTOPSUB
132 %right <ival> ASSIGNOP <pval> PLUGIN_ASSIGN_OP
133 %right <ival> PERLY_QUESTION_MARK PERLY_COLON
135 %left <ival> OROR DORDOR <pval> PLUGIN_LOGICAL_OR_OP
136 %left <ival> ANDAND <pval> PLUGIN_LOGICAL_AND_OP
138 %left <ival> BITANDOP
139 %left <ival> CHEQOP NCEQOP
140 %left <ival> CHRELOP NCRELOP
141 %nonassoc <pval> PLUGIN_REL_OP
142 %nonassoc UNIOP UNIOPSUB
145 %left ADDOP <pval> PLUGIN_ADD_OP
146 %left MULOP <pval> PLUGIN_MUL_OP
148 %right <ival> PERLY_EXCLAMATION_MARK PERLY_TILDE UMINUS REFGEN
149 %right POWOP <pval> PLUGIN_POW_OP
150 %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
151 %nonassoc <pval> PLUGIN_HIGH_OP
153 %nonassoc <ival> PERLY_PAREN_CLOSE
154 %left <ival> PERLY_PAREN_OPEN
155 %left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN
159 /* Top-level choice of what kind of thing yyparse was called to parse */
162 parser->expect = XSTATE;
167 newPROG(block_end($remember,$stmtseq));
168 PL_compiling.cop_seq = 0;
173 parser->expect = XTERM;
178 PL_eval_root = $optexpr;
183 parser->expect = XBLOCK;
188 PL_pad_reset_pending = TRUE;
189 PL_eval_root = $block;
192 parser->yychar = yytoken = YYEOF;
196 parser->expect = XSTATE;
201 PL_pad_reset_pending = TRUE;
202 PL_eval_root = $barestmt;
205 parser->yychar = yytoken = YYEOF;
209 parser->expect = XSTATE;
214 PL_pad_reset_pending = TRUE;
215 PL_eval_root = $fullstmt;
218 parser->yychar = yytoken = YYEOF;
222 parser->expect = XSTATE;
227 PL_eval_root = $stmtseq;
232 parser->expect = XSTATE;
237 PL_eval_root = $subsigguts;
242 /* Either a signatured 'sub' or 'method' keyword */
243 sigsub_or_method_named
245 { $$ = KW_SUB_named_sig; }
247 { $$ = KW_METHOD_named; }
250 /* An ordinary block */
251 block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE
252 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
253 parser->copline = (line_t)$PERLY_BRACE_OPEN;
254 $$ = block_end($remember, $stmtseq);
259 : %empty { $$ = NULL; }
263 formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT
264 { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN)
265 parser->copline = (line_t)$PERLY_EQUAL_SIGN;
266 $$ = block_end($remember, $formstmtseq);
270 remember: %empty /* start a full lexical scope */
271 { $$ = block_start(TRUE);
272 parser->parsed_sub = 0; }
275 mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE
276 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
277 parser->copline = (line_t)$PERLY_BRACE_OPEN;
278 $$ = block_end($mremember, $stmtseq);
282 mremember: %empty /* start a partial lexical scope */
283 { $$ = block_start(FALSE);
284 parser->parsed_sub = 0; }
287 /* The parenthesized variable of a catch block */
289 /* not really valid grammar but we detect it in the
290 * action block to throw a nicer error message */
292 { parser->in_my = 1; }
294 { parser->in_my = 0; intro_my(); }
299 /* A sequence of statements in the program */
302 | stmtseq[list] fullstmt
303 { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt);
304 PL_pad_reset_pending = TRUE;
305 if ($list && $fullstmt)
306 PL_hints |= HINT_BLOCK_SCOPE;
310 /* A sequence of format lines */
313 | formstmtseq[list] formline
314 { $$ = op_append_list(OP_LINESEQ, $list, $formline);
315 PL_pad_reset_pending = TRUE;
316 if ($list && $formline)
317 PL_hints |= HINT_BLOCK_SCOPE;
321 /* A statement in the program, including optional labels */
324 $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL;
327 { $$ = $labfullstmt; }
330 labfullstmt: LABEL barestmt
332 SV *label = cSVOPx_sv($LABEL);
333 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
334 savepv(SvPVX_const(label)), $barestmt);
337 | LABEL labfullstmt[list]
339 SV *label = cSVOPx_sv($LABEL);
340 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
341 savepv(SvPVX_const(label)), $list);
346 /* A bare statement, lacking label and other aspects of state op */
349 | KW_FORMAT startformsub formname formblock
351 CV *fmtcv = PL_compcv;
352 newFORM($startformsub, $formname, $formblock);
354 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
355 pad_add_weakref(fmtcv);
357 parser->parsed_sub = 1;
359 | KW_SUB_named subname startsub
360 /* sub declaration or definition not within scope
361 of 'use feature "signatures"'*/
363 init_named_cv(PL_compcv, $subname);
365 parser->in_my_stash = NULL;
367 proto subattrlist optsubbody
369 SvREFCNT_inc_simple_void(PL_compcv);
370 $subname->op_type == OP_CONST
371 ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
372 : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
376 parser->parsed_sub = 1;
378 | sigsub_or_method_named subname startsub
379 /* sub declaration or definition under 'use feature
380 * "signatures"'. (Note that a signature isn't
381 * allowed in a declaration)
384 init_named_cv(PL_compcv, $subname);
385 if($sigsub_or_method_named == KW_METHOD_named) {
386 croak_kw_unless_class("method");
387 class_prepare_method_parse(PL_compcv);
390 parser->in_my_stash = NULL;
392 subattrlist optsigsubbody
394 OP *body = $optsigsubbody;
396 SvREFCNT_inc_simple_void(PL_compcv);
397 $subname->op_type == OP_CONST
398 ? newATTRSUB($startsub, $subname, NULL, $subattrlist, body)
399 : newMYSUB( $startsub, $subname, NULL, $subattrlist, body)
403 parser->parsed_sub = 1;
409 croak_kw_unless_class("ADJUST");
410 class_prepare_method_parse(PL_compcv);
418 OP *body = $optsubbody;
419 SvREFCNT_inc_simple_void(PL_compcv);
425 cv = newATTRSUB($startsub, NULL, NULL, NULL, body);
426 class_add_ADJUST(PL_curstash, cv);
431 | KW_PACKAGE BAREWORD[version] BAREWORD[package] PERLY_SEMICOLON
432 /* version and package appear in the reverse order to what may be
433 * expected, because toke.c has already pushed both of them to a stack
434 * by calling force_next() from within force_version().
435 * When the parser pops them back out again they appear swapped */
439 package_version($version);
442 | KW_CLASS BAREWORD[version] BAREWORD[package] subattrlist PERLY_SEMICOLON
446 package_version($version);
448 class_setup_stash(PL_curstash);
450 class_apply_attributes(PL_curstash, $subattrlist);
453 | KW_USE_or_NO startsub
454 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
455 BAREWORD[version] BAREWORD[module] optlistexpr PERLY_SEMICOLON
456 /* version and package appear in reverse order for the same reason as
457 * KW_PACKAGE; see comment above */
459 SvREFCNT_inc_simple_void(PL_compcv);
460 utilize($KW_USE_or_NO, $startsub, $version, $module, $optlistexpr);
461 parser->parsed_sub = 1;
464 | KW_IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
466 $$ = block_end($remember,
467 newCONDOP(0, $mexpr, op_scope($mblock), $else));
468 parser->copline = (line_t)$KW_IF;
470 | KW_UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
472 $$ = block_end($remember,
473 newCONDOP(0, $mexpr, $else, op_scope($mblock)));
474 parser->copline = (line_t)$KW_UNLESS;
476 | KW_GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
478 $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0));
479 parser->copline = (line_t)$KW_GIVEN;
481 | KW_WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
482 { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); }
484 { $$ = newWHENOP(0, op_scope($block)); }
485 | KW_WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont
487 $$ = block_end($remember,
488 newWHILEOP(0, 1, NULL,
489 $texpr, $mblock, $cont, $mintro));
490 parser->copline = (line_t)$KW_WHILE;
492 | KW_UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont
494 $$ = block_end($remember,
495 newWHILEOP(0, 1, NULL,
496 $iexpr, $mblock, $cont, $mintro));
497 parser->copline = (line_t)$KW_UNTIL;
499 | KW_FOR PERLY_PAREN_OPEN remember mnexpr[init_mnexpr] PERLY_SEMICOLON
500 { parser->expect = XTERM; }
501 texpr PERLY_SEMICOLON
502 { parser->expect = XTERM; }
503 mintro mnexpr[iterate_mnexpr] PERLY_PAREN_CLOSE
506 OP *initop = $init_mnexpr;
507 OP *forop = newWHILEOP(0, 1, NULL,
508 scalar($texpr), $mblock, $iterate_mnexpr, $mintro);
510 forop = op_prepend_elem(OP_LINESEQ, initop,
511 op_append_elem(OP_LINESEQ,
512 newOP(OP_UNSTACK, OPf_SPECIAL),
515 PL_hints |= HINT_BLOCK_SCOPE;
516 $$ = block_end($remember, forop);
517 parser->copline = (line_t)$KW_FOR;
519 | KW_FOR KW_MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
521 $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont));
522 parser->copline = (line_t)$KW_FOR;
524 | KW_FOR KW_MY remember PERLY_PAREN_OPEN my_list_of_scalars PERLY_PAREN_CLOSE PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
526 if ($my_list_of_scalars->op_type == OP_PADSV)
527 /* degenerate case of 1 var: for my ($x) ....
528 Flag it so it can be special-cased in newFOROP */
529 $my_list_of_scalars->op_flags |= OPf_PARENS;
530 $$ = block_end($remember, newFOROP(0, $my_list_of_scalars, $mexpr, $mblock, $cont));
531 parser->copline = (line_t)$KW_FOR;
533 | KW_FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
535 $$ = block_end($remember, newFOROP(0,
536 op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont));
537 parser->copline = (line_t)$KW_FOR;
539 | KW_FOR my_refgen remember my_var
540 { parser->in_my = 0; $<opval>$ = my($my_var); }[variable]
541 PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
547 newUNOP(OP_REFGEN, 0,
550 $mexpr, $mblock, $cont)
552 parser->copline = (line_t)$KW_FOR;
554 | KW_FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
556 $$ = block_end($remember, newFOROP(
557 0, op_lvalue(newUNOP(OP_REFGEN, 0,
559 OP_ENTERLOOP), $mexpr, $mblock, $cont));
560 parser->copline = (line_t)$KW_FOR;
562 | KW_FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
564 $$ = block_end($remember,
565 newFOROP(0, NULL, $mexpr, $mblock, $cont));
566 parser->copline = (line_t)$KW_FOR;
568 | KW_TRY mblock[try] KW_CATCH remember catch_paren[scalar]
571 yyerror("catch block requires a (VAR)");
575 mblock[catch] finally
577 $$ = newTRYCATCHOP(0,
578 $try, $scalar, block_end($remember, op_scope($catch)));
580 $$ = op_wrap_finally($$, $finally);
581 parser->copline = (line_t)$KW_TRY;
585 /* a block is a loop that happens once */
586 $$ = newWHILEOP(0, 1, NULL,
587 NULL, $block, $cont, 0);
589 | KW_PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember
593 package_version($version);
596 stmtseq PERLY_BRACE_CLOSE
598 /* a block is a loop that happens once */
599 $$ = newWHILEOP(0, 1, NULL,
600 NULL, block_end($remember, $stmtseq), NULL, 0);
601 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
602 parser->copline = (line_t)$PERLY_BRACE_OPEN;
604 | KW_CLASS BAREWORD[version] BAREWORD[package] subattrlist PERLY_BRACE_OPEN remember
609 package_version($version);
611 class_setup_stash(PL_curstash);
613 class_apply_attributes(PL_curstash, $subattrlist);
616 stmtseq PERLY_BRACE_CLOSE
618 /* a block is a loop that happens once */
619 $$ = newWHILEOP(0, 1, NULL,
620 NULL, block_end($remember, $stmtseq), NULL, 0);
621 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
622 parser->copline = (line_t)$PERLY_BRACE_OPEN;
624 | fielddecl PERLY_SEMICOLON
628 | sideff PERLY_SEMICOLON
634 $$ = newDEFEROP(0, op_scope($2));
636 | YADAYADA PERLY_SEMICOLON
638 /* diag_listed_as: Unimplemented */
639 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
640 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
645 parser->copline = NOLINE;
650 formline: THING formarg
654 list = op_append_elem(OP_LIST, $THING, term);
659 if (parser->copline == NOLINE)
660 parser->copline = CopLINE(PL_curcop)-1;
661 else parser->copline--;
662 $$ = newSTATEOP(0, NULL,
663 op_convert_list(OP_FORMLINE, 0, list));
669 | FORMLBRACK stmtseq FORMRBRACK
670 { $$ = op_unscope($stmtseq); }
676 /* An expression which may have a side-effect */
681 | expr[body] KW_IF condition
682 { $$ = newLOGOP(OP_AND, 0, $condition, $body); }
683 | expr[body] KW_UNLESS condition
684 { $$ = newLOGOP(OP_OR, 0, $condition, $body); }
685 | expr[body] KW_WHILE condition
686 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); }
687 | expr[body] KW_UNTIL iexpr
688 { $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); }
689 | expr[body] KW_FOR condition
690 { $$ = newFOROP(0, NULL, $condition, $body, NULL);
691 parser->copline = (line_t)$KW_FOR; }
692 | expr[body] KW_WHEN condition
693 { $$ = newWHENOP($condition, op_scope($body)); }
696 /* else and elsif blocks */
701 ($mblock)->op_flags |= OPf_PARENS;
702 $$ = op_scope($mblock);
704 | KW_ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else[else.recurse]
705 { parser->copline = (line_t)$KW_ELSIF;
707 newSTATEOP(OPf_SPECIAL,NULL,$mexpr),
708 op_scope($mblock), $[else.recurse]);
709 PL_hints |= HINT_BLOCK_SCOPE;
713 /* Continue blocks */
717 { $$ = op_scope($block); }
724 { $$ = op_scope($block); }
727 /* determine whether there are any new my declarations */
729 { $$ = (PL_min_intro_pending &&
730 PL_max_intro_pending >= PL_min_intro_pending);
733 /* Normal expression */
739 /* Boolean expression */
740 texpr : %empty /* NULL means true */
742 (void)scan_num("1", &tmplval);
743 $$ = tmplval.opval; }
747 /* Inverted boolean expression */
749 { $$ = invert(scalar($expr)); }
752 /* Expression with its own lexical scope */
754 { $$ = $expr; intro_my(); }
758 { $$ = $nexpr; intro_my(); }
761 formname: BAREWORD { $$ = $BAREWORD; }
765 startsub: %empty /* start a regular subroutine scope */
766 { $$ = start_subparse(FALSE, 0);
767 SAVEFREESV(PL_compcv); }
771 startanonsub: %empty /* start an anonymous subroutine scope */
772 { $$ = start_subparse(FALSE, CVf_ANON);
773 SAVEFREESV(PL_compcv); }
776 startanonmethod: %empty /* start an anonymous method scope */
777 { $$ = start_subparse(FALSE, CVf_ANON|CVf_IsMETHOD);
778 SAVEFREESV(PL_compcv); }
781 startformsub: %empty /* start a format subroutine scope */
782 { $$ = start_subparse(TRUE, 0);
783 SAVEFREESV(PL_compcv); }
786 /* Name of a subroutine - must be a bareword, could be special */
791 /* Subroutine prototype */
797 /* Optional list of subroutine attributes */
802 OP *attrlist = $THING;
803 if(attrlist && !PL_parser->sig_seen)
804 attrlist = apply_builtin_cv_attributes(PL_compcv, attrlist);
811 /* List of attributes for a "my" variable declaration */
812 myattrlist: COLONATTR THING
820 /* --------------------------------------
821 * subroutine signature parsing
824 /* the '' or 'foo' part of a '$' or '@foo' etc signature variable */
826 { parser->in_my = 0; $$ = NULL; }
828 { parser->in_my = 0; $$ = $PRIVATEREF; }
837 /* @, %, @foo, %foo */
838 sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
840 I32 sigil = $sigslurpsigil;
841 OP *var = $sigvarname;
842 OP *defop = $sigdefault;
844 if (parser->sig_slurpy)
845 yyerror("Multiple slurpy parameters not allowed");
846 parser->sig_slurpy = (char)sigil;
849 yyerror("A slurpy parameter may not have "
852 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
856 /* default part of sub signature scalar element: i.e. '= default_expr' */
860 { $$ = newARGDEFELEMOP(0, newOP(OP_NULL, 0), parser->sig_elems); }
864 if ($ASSIGNOP == OP_DORASSIGN)
865 flags |= OPpARG_IF_UNDEF << 8;
866 if ($ASSIGNOP == OP_ORASSIGN)
867 flags |= OPpARG_IF_FALSE << 8;
868 $$ = newARGDEFELEMOP(flags, $term, parser->sig_elems);
872 /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
874 PERLY_DOLLAR sigvarname sigdefault
876 OP *var = $sigvarname;
877 OP *defop = $sigdefault;
879 if (parser->sig_slurpy)
880 yyerror("Slurpy parameter not last");
885 parser->sig_optelems++;
887 OP *defexpr = cLOGOPx(defop)->op_first;
889 if ( defexpr->op_type == OP_NULL
890 && !(defexpr->op_flags & OPf_KIDS))
892 /* handle '$=' special case */
894 yyerror("Optional parameter "
895 "lacks default expression");
899 /* a normal '=default' expression */
901 var->op_flags |= OPf_STACKED;
902 (void)op_sibling_splice(var,
907 var = newUNOP(OP_NULL, 0, defop);
910 /* NB: normally the first child of a
911 * logop is executed before the logop,
912 * and it pushes a boolean result
913 * ready for the logop. For ARGDEFELEM,
914 * the op itself does the boolean
915 * calculation, so set the first op to
918 var->op_next = defop;
919 defexpr->op_next = var;
923 if (parser->sig_optelems)
924 yyerror("Mandatory parameter "
925 "follows optional parameter");
928 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
933 /* subroutine signature element: e.g. '$x = $default' or '%h' */
934 sigelem: sigscalarelem
935 { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; }
937 { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; }
940 /* list of subroutine signature elements */
942 siglist[list] PERLY_COMMA
944 | siglist[list] PERLY_COMMA sigelem[element]
946 $$ = op_append_list(OP_LINESEQ, $list, $element);
948 | sigelem[element] %prec PREC_LOW
958 /* optional subroutine signature */
964 /* Subroutine signature */
965 subsignature: PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE
966 { $$ = $subsigguts; }
971 SAVEIV(parser->sig_elems);
972 SAVEIV(parser->sig_optelems);
973 SAVEI8(parser->sig_slurpy);
974 parser->sig_elems = 0;
975 parser->sig_optelems = 0;
976 parser->sig_slurpy = 0;
977 parser->in_my = KEY_sigvar;
981 OP *sigops = $optsiglist;
982 struct op_argcheck_aux *aux;
985 if (!FEATURE_SIGNATURES_IS_ENABLED && !CvIsMETHOD(PL_compcv))
986 Perl_croak(aTHX_ "Experimental "
987 "subroutine signatures not enabled");
989 /* We shouldn't get here otherwise */
990 aux = (struct op_argcheck_aux*)
991 PerlMemShared_malloc(
992 sizeof(struct op_argcheck_aux));
993 aux->params = parser->sig_elems;
994 aux->opt_params = parser->sig_optelems;
995 aux->slurpy = parser->sig_slurpy;
996 check = newUNOP_AUX(OP_ARGCHECK, 0, NULL,
997 (UNOP_AUX_item *)aux);
998 sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
999 sigops = op_prepend_elem(OP_LINESEQ,
1000 newSTATEOP(0, NULL, NULL),
1002 /* a nextstate at the end handles context
1003 * correctly for an empty sub body */
1004 sigops = op_append_elem(OP_LINESEQ,
1006 newSTATEOP(0, NULL, NULL));
1007 /* wrap the list of arg ops in a NULL aux op.
1008 This serves two purposes. First, it makes
1009 the arg list a separate subtree from the
1010 body of the sub, and secondly the null op
1011 may in future be upgraded to an OP_SIGNATURE
1012 when implemented. For now leave it as
1014 $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL);
1017 CvSIGNATURE_on(PL_compcv);
1020 /* tell the toker that attrributes can follow
1021 * this sig, but only so that the toker
1022 * can skip through any (illegal) trailing
1023 * attribute text then give a useful error
1024 * message about "attributes before sig",
1025 * rather than falling over ina mess at
1026 * unrecognised syntax.
1028 parser->expect = XATTRBLOCK;
1029 parser->sig_seen = TRUE;
1034 /* Optional subroutine body (for named subroutine declaration) */
1037 | PERLY_SEMICOLON { $$ = NULL; }
1041 /* Subroutine body (without signature) */
1042 subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
1044 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
1045 parser->copline = (line_t)$PERLY_BRACE_OPEN;
1046 $$ = block_end($remember, $stmtseq);
1051 /* optional [ Subroutine body with optional signature ] (for named
1052 * subroutine declaration) */
1055 | PERLY_SEMICOLON { $$ = NULL; }
1058 /* Subroutine body with optional signature */
1059 sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
1061 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
1062 parser->copline = (line_t)$PERLY_BRACE_OPEN;
1063 $$ = block_end($remember,
1064 op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq));
1069 /* Ordinary expressions; logical combinations */
1070 expr : expr[lhs] ANDOP expr[rhs]
1071 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
1072 | expr[lhs] PLUGIN_LOGICAL_AND_LOW_OP[op] expr[rhs]
1073 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1074 | expr[lhs] OROP[operator] expr[rhs]
1075 { $$ = newLOGOP($operator, 0, $lhs, $rhs); }
1076 | expr[lhs] PLUGIN_LOGICAL_OR_LOW_OP[op] expr[rhs]
1077 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1078 | listexpr %prec PREC_LOW
1081 /* Expressions are a list of terms joined by commas */
1082 listexpr: listexpr[list] PERLY_COMMA
1084 | listexpr[list] PERLY_COMMA term
1087 $$ = op_append_elem(OP_LIST, $list, term);
1089 | term %prec PREC_LOW
1092 /* List operators */
1093 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
1094 { $$ = op_convert_list($LSTOP, OPf_STACKED,
1095 op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) );
1097 | FUNC PERLY_PAREN_OPEN indirob expr PERLY_PAREN_CLOSE /* print ($fh @args */
1098 { $$ = op_convert_list($FUNC, OPf_STACKED,
1099 op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) );
1101 | term ARROW methodname PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* $foo->bar(list) */
1102 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1103 op_append_elem(OP_LIST,
1104 op_prepend_elem(OP_LIST, scalar($term), $optexpr),
1105 newMETHOP(OP_METHOD, 0, $methodname)));
1107 | term ARROW methodname /* $foo->bar */
1108 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1109 op_append_elem(OP_LIST, scalar($term),
1110 newMETHOP(OP_METHOD, 0, $methodname)));
1112 | METHCALL0 indirob optlistexpr /* new Class @args */
1113 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1114 op_append_elem(OP_LIST,
1115 op_prepend_elem(OP_LIST, $indirob, $optlistexpr),
1116 newMETHOP(OP_METHOD, 0, $METHCALL0)));
1118 | METHCALL indirob PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* method $object (@args) */
1119 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1120 op_append_elem(OP_LIST,
1121 op_prepend_elem(OP_LIST, $indirob, $optexpr),
1122 newMETHOP(OP_METHOD, 0, $METHCALL)));
1124 | LSTOP optlistexpr /* print @args */
1125 { $$ = op_convert_list($LSTOP, 0, $optlistexpr); }
1126 | FUNC PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* print (@args) */
1127 { $$ = op_convert_list($FUNC, 0, $optexpr); }
1128 | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */
1129 { $$ = op_convert_list($FUNC, 0, $optexpr); }
1130 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
1131 { SvREFCNT_inc_simple_void(PL_compcv);
1132 $<opval>$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub]
1133 optlistexpr %prec LSTOP /* ... @bar */
1134 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1135 op_append_elem(OP_LIST,
1136 op_prepend_elem(OP_LIST, $<opval>anonattrsub, $optlistexpr), $LSTOPSUB));
1140 /* Names of methods. May use $object->$methodname */
1141 methodname: METHCALL0
1145 /* Some kind of subscripted expression */
1146 subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* *main::{something} */
1147 /* In this and all the hash accessors, PERLY_SEMICOLON is
1148 * provided by the tokeniser */
1149 { $$ = newBINOP(OP_GELEM, 0, $gelem, scalar($expr)); }
1150 | scalar[array] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $array[$element] */
1151 { $$ = newBINOP(OP_AELEM, 0, oopsAV($array), scalar($expr));
1153 | term[array_reference] ARROW PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* somearef->[$element] */
1154 { $$ = newBINOP(OP_AELEM, 0,
1155 ref(newAVREF($array_reference),OP_RV2AV),
1158 | subscripted[array_reference] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $foo->[$bar]->[$baz] */
1159 { $$ = newBINOP(OP_AELEM, 0,
1160 ref(newAVREF($array_reference),OP_RV2AV),
1163 | scalar[hash] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo{bar();} */
1164 { $$ = newBINOP(OP_HELEM, 0, oopsHV($hash), jmaybe($expr));
1166 | term[hash_reference] ARROW PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* somehref->{bar();} */
1167 { $$ = newBINOP(OP_HELEM, 0,
1168 ref(newHVREF($hash_reference),OP_RV2HV),
1170 | subscripted[hash_reference] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo->[bar]->{baz;} */
1171 { $$ = newBINOP(OP_HELEM, 0,
1172 ref(newHVREF($hash_reference),OP_RV2HV),
1174 | term[code_reference] ARROW PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $subref->() */
1175 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1176 newCVREF(0, scalar($code_reference)));
1177 if (parser->expect == XBLOCK)
1178 parser->expect = XOPERATOR;
1180 | term[code_reference] ARROW PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $subref->(@args) */
1181 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1182 op_append_elem(OP_LIST, $expr,
1183 newCVREF(0, scalar($code_reference))));
1184 if (parser->expect == XBLOCK)
1185 parser->expect = XOPERATOR;
1188 | subscripted[code_reference] PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $foo->{bar}->(@args) */
1189 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1190 op_append_elem(OP_LIST, $expr,
1191 newCVREF(0, scalar($code_reference))));
1192 if (parser->expect == XBLOCK)
1193 parser->expect = XOPERATOR;
1195 | subscripted[code_reference] PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $foo->{bar}->() */
1196 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1197 newCVREF(0, scalar($code_reference)));
1198 if (parser->expect == XBLOCK)
1199 parser->expect = XOPERATOR;
1201 | PERLY_PAREN_OPEN expr[list] PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE /* list slice */
1202 { $$ = newSLICEOP(0, $slice, $list); }
1203 | QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* list literal slice */
1204 { $$ = newSLICEOP(0, $expr, $QWLIST); }
1205 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* empty list slice! */
1206 { $$ = newSLICEOP(0, $expr, NULL); }
1209 /* Binary operators between terms */
1210 termbinop: term[lhs] PLUGIN_HIGH_OP[op] term[rhs]
1211 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1212 | term[lhs] ASSIGNOP term[rhs] /* $x = $y, $x += $y */
1213 { $$ = newASSIGNOP(OPf_STACKED, $lhs, $ASSIGNOP, $rhs); }
1214 | term[lhs] PLUGIN_ASSIGN_OP[op] term[rhs]
1215 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1216 | term[lhs] POWOP term[rhs] /* $x ** $y */
1217 { $$ = newBINOP($POWOP, 0, scalar($lhs), scalar($rhs)); }
1218 | term[lhs] PLUGIN_POW_OP[op] term[rhs]
1219 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1220 | term[lhs] MULOP term[rhs] /* $x * $y, $x x $y */
1221 { if ($MULOP != OP_REPEAT)
1223 $$ = newBINOP($MULOP, 0, $lhs, scalar($rhs));
1225 | term[lhs] PLUGIN_MUL_OP[op] term[rhs]
1226 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1227 | term[lhs] ADDOP term[rhs] /* $x + $y */
1228 { $$ = newBINOP($ADDOP, 0, scalar($lhs), scalar($rhs)); }
1229 | term[lhs] PLUGIN_ADD_OP[op] term[rhs]
1230 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1231 | term[lhs] SHIFTOP term[rhs] /* $x >> $y, $x << $y */
1232 { $$ = newBINOP($SHIFTOP, 0, scalar($lhs), scalar($rhs)); }
1233 | termrelop %prec PREC_LOW /* $x > $y, etc. */
1234 { $$ = $termrelop; }
1235 | termeqop %prec PREC_LOW /* $x == $y, $x cmp $y */
1237 | term[lhs] BITANDOP term[rhs] /* $x & $y */
1238 { $$ = newBINOP($BITANDOP, 0, scalar($lhs), scalar($rhs)); }
1239 | term[lhs] BITOROP term[rhs] /* $x | $y */
1240 { $$ = newBINOP($BITOROP, 0, scalar($lhs), scalar($rhs)); }
1241 | term[lhs] DOTDOT term[rhs] /* $x..$y, $x...$y */
1242 { $$ = newRANGE($DOTDOT, scalar($lhs), scalar($rhs)); }
1243 | term[lhs] ANDAND term[rhs] /* $x && $y */
1244 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
1245 | term[lhs] PLUGIN_LOGICAL_AND_OP[op] term[rhs]
1246 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1247 | term[lhs] OROR term[rhs] /* $x || $y */
1248 { $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); }
1249 | term[lhs] PLUGIN_LOGICAL_OR_OP[op] term[rhs]
1250 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1251 | term[lhs] DORDOR term[rhs] /* $x // $y */
1252 { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
1253 | term[lhs] MATCHOP term[rhs] /* $x =~ /$y/ */
1254 { $$ = bind_match($MATCHOP, $lhs, $rhs); }
1255 | term[lhs] PLUGIN_LOW_OP[op] term[rhs]
1256 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1259 termrelop: relopchain %prec PREC_LOW
1260 { $$ = cmpchain_finish($relopchain); }
1261 | term[lhs] NCRELOP term[rhs]
1262 { $$ = newBINOP($NCRELOP, 0, scalar($lhs), scalar($rhs)); }
1264 { yyerror("syntax error"); YYERROR; }
1266 { yyerror("syntax error"); YYERROR; }
1267 | term[lhs] PLUGIN_REL_OP[op] term[rhs]
1268 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1271 relopchain: term[lhs] CHRELOP term[rhs]
1272 { $$ = cmpchain_start($CHRELOP, $lhs, $rhs); }
1273 | relopchain[lhs] CHRELOP term[rhs]
1274 { $$ = cmpchain_extend($CHRELOP, $lhs, $rhs); }
1277 termeqop: eqopchain %prec PREC_LOW
1278 { $$ = cmpchain_finish($eqopchain); }
1279 | term[lhs] NCEQOP term[rhs]
1280 { $$ = newBINOP($NCEQOP, 0, scalar($lhs), scalar($rhs)); }
1282 { yyerror("syntax error"); YYERROR; }
1284 { yyerror("syntax error"); YYERROR; }
1287 eqopchain: term[lhs] CHEQOP term[rhs]
1288 { $$ = cmpchain_start($CHEQOP, $lhs, $rhs); }
1289 | eqopchain[lhs] CHEQOP term[rhs]
1290 { $$ = cmpchain_extend($CHEQOP, $lhs, $rhs); }
1293 /* Unary operators and terms */
1294 termunop : PERLY_MINUS term %prec UMINUS /* -$x */
1295 { $$ = newUNOP(OP_NEGATE, 0, scalar($term)); }
1296 | PERLY_PLUS term %prec UMINUS /* +$x */
1299 | PERLY_EXCLAMATION_MARK term /* !$x */
1300 { $$ = newUNOP(OP_NOT, 0, scalar($term)); }
1301 | PERLY_TILDE term /* ~$x */
1302 { $$ = newUNOP($PERLY_TILDE, 0, scalar($term)); }
1303 | term POSTINC /* $x++ */
1304 { $$ = newUNOP(OP_POSTINC, 0,
1305 op_lvalue(scalar($term), OP_POSTINC)); }
1306 | term POSTDEC /* $x-- */
1307 { $$ = newUNOP(OP_POSTDEC, 0,
1308 op_lvalue(scalar($term), OP_POSTDEC));}
1309 | term POSTJOIN /* implicit join after interpolated ->@ */
1310 { $$ = op_convert_list(OP_JOIN, 0,
1320 | PREINC term /* ++$x */
1321 { $$ = newUNOP(OP_PREINC, 0,
1322 op_lvalue(scalar($term), OP_PREINC)); }
1323 | PREDEC term /* --$x */
1324 { $$ = newUNOP(OP_PREDEC, 0,
1325 op_lvalue(scalar($term), OP_PREDEC)); }
1329 /* Constructors for anonymous data */
1331 : PERLY_BRACKET_OPEN optexpr PERLY_BRACKET_CLOSE
1332 { $$ = newANONLIST($optexpr); }
1333 | HASHBRACK optexpr PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { foo => "Bar" } */
1334 { $$ = newANONHASH($optexpr); }
1335 | KW_SUB_anon startanonsub proto subattrlist subbody %prec PERLY_PAREN_OPEN
1336 { SvREFCNT_inc_simple_void(PL_compcv);
1337 $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); }
1338 | KW_SUB_anon_sig startanonsub subattrlist sigsubbody %prec PERLY_PAREN_OPEN
1339 { SvREFCNT_inc_simple_void(PL_compcv);
1340 $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); }
1341 | KW_METHOD_anon startanonmethod subattrlist sigsubbody %prec PERLY_PAREN_OPEN
1343 SvREFCNT_inc_simple_void(PL_compcv);
1344 $$ = newANONATTRSUB($startanonmethod, NULL, $subattrlist, $sigsubbody);
1348 /* Things called with "do" */
1349 termdo : KW_DO term %prec UNIOP /* do $filename */
1350 { $$ = dofile($term, $KW_DO);}
1351 | KW_DO block %prec PERLY_PAREN_OPEN /* do { code */
1352 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));}
1355 term[product] : termbinop
1359 | term[condition] PERLY_QUESTION_MARK term[then] PERLY_COLON term[else]
1360 { $$ = newCONDOP(0, $condition, $then, $else); }
1361 | REFGEN term[operand] /* \$x, \@y, \%z */
1362 { $$ = newUNOP(OP_REFGEN, 0, $operand); }
1363 | myattrterm %prec UNIOP
1364 { $$ = $myattrterm; }
1365 | KW_LOCAL term[operand] %prec UNIOP
1366 { $$ = localize($operand,0); }
1367 | PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1368 { $$ = sawparens($expr); }
1371 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1372 { $$ = sawparens(newNULLLIST()); }
1373 | scalar %prec PERLY_PAREN_OPEN
1375 | star %prec PERLY_PAREN_OPEN
1377 | hsh %prec PERLY_PAREN_OPEN
1379 | ary %prec PERLY_PAREN_OPEN
1381 | arylen %prec PERLY_PAREN_OPEN /* $#x, $#{ something } */
1382 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));}
1384 { $$ = $subscripted; }
1385 | sliceme PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array slice */
1386 { $$ = op_prepend_elem(OP_ASLICE,
1387 newOP(OP_PUSHMARK, 0),
1388 newLISTOP(OP_ASLICE, 0,
1390 ref($sliceme, OP_ASLICE)));
1393 $sliceme->op_private & OPpSLICEWARNING;
1395 | kvslice PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array key/value slice */
1396 { $$ = op_prepend_elem(OP_KVASLICE,
1397 newOP(OP_PUSHMARK, 0),
1398 newLISTOP(OP_KVASLICE, 0,
1400 ref(oopsAV($kvslice), OP_KVASLICE)));
1403 $kvslice->op_private & OPpSLICEWARNING;
1405 | sliceme PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* @hash{@keys} */
1406 { $$ = op_prepend_elem(OP_HSLICE,
1407 newOP(OP_PUSHMARK, 0),
1408 newLISTOP(OP_HSLICE, 0,
1410 ref(oopsHV($sliceme), OP_HSLICE)));
1413 $sliceme->op_private & OPpSLICEWARNING;
1415 | kvslice PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* %hash{@keys} */
1416 { $$ = op_prepend_elem(OP_KVHSLICE,
1417 newOP(OP_PUSHMARK, 0),
1418 newLISTOP(OP_KVHSLICE, 0,
1420 ref($kvslice, OP_KVHSLICE)));
1423 $kvslice->op_private & OPpSLICEWARNING;
1425 | THING %prec PERLY_PAREN_OPEN
1428 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); }
1429 | amper PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* &foo() or foo() */
1430 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper));
1432 | amper PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* &foo(@args) or foo(@args) */
1434 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1435 op_append_elem(OP_LIST, $expr, scalar($amper)));
1437 | NOAMP subname optlistexpr /* foo @args (no parens) */
1438 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1439 op_append_elem(OP_LIST, $optlistexpr, scalar($subname)));
1441 | term[operand] ARROW PERLY_DOLLAR PERLY_STAR
1442 { $$ = newSVREF($operand); }
1443 | term[operand] ARROW PERLY_SNAIL PERLY_STAR
1444 { $$ = newAVREF($operand); }
1445 | term[operand] ARROW PERLY_PERCENT_SIGN PERLY_STAR
1446 { $$ = newHVREF($operand); }
1447 | term[operand] ARROW PERLY_AMPERSAND PERLY_STAR
1448 { $$ = newUNOP(OP_ENTERSUB, 0,
1449 scalar(newCVREF($PERLY_AMPERSAND,$operand))); }
1450 | term[operand] ARROW PERLY_STAR PERLY_STAR %prec PERLY_PAREN_OPEN
1451 { $$ = newGVREF(0,$operand); }
1452 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
1453 { $$ = newOP($LOOPEX, OPf_SPECIAL);
1454 PL_hints |= HINT_BLOCK_SCOPE; }
1455 | LOOPEX term[operand]
1456 { $$ = newLOOPEX($LOOPEX,$operand); }
1457 | NOTOP listexpr /* not $foo */
1458 { $$ = newUNOP(OP_NOT, 0, scalar($listexpr)); }
1459 | UNIOP /* Unary op, $_ implied */
1460 { $$ = newOP($UNIOP, 0); }
1461 | UNIOP block /* eval { foo }* */
1462 { $$ = newUNOP($UNIOP, 0, $block); }
1463 | UNIOP term[operand] /* Unary op */
1464 { $$ = newUNOP($UNIOP, 0, $operand); }
1465 | KW_REQUIRE /* require, $_ implied */
1466 { $$ = newOP(OP_REQUIRE, $KW_REQUIRE ? OPf_SPECIAL : 0); }
1467 | KW_REQUIRE term[operand] /* require Foo */
1468 { $$ = newUNOP(OP_REQUIRE, $KW_REQUIRE ? OPf_SPECIAL : 0, $operand); }
1470 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($UNIOPSUB)); }
1471 | UNIOPSUB term[operand] /* Sub treated as unop */
1472 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1473 op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); }
1474 | FUNC0 /* Nullary operator */
1475 { $$ = newOP($FUNC0, 0); }
1476 | FUNC0 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1477 { $$ = newOP($FUNC0, 0);}
1478 | FUNC0OP /* Same as above, but op created in toke.c */
1480 | FUNC0OP PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1482 | FUNC0SUB /* Sub treated as nullop */
1483 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); }
1484 | FUNC1 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* not () */
1485 { $$ = ($FUNC1 == OP_NOT)
1486 ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1487 : newOP($FUNC1, OPf_SPECIAL); }
1488 | FUNC1 PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* not($foo) */
1489 { $$ = newUNOP($FUNC1, 0, $expr); }
1490 | PMFUNC /* m//, s///, qr//, tr/// */
1492 if ( $PMFUNC->op_type != OP_TRANS
1493 && $PMFUNC->op_type != OP_TRANSR
1494 && (((PMOP*)$PMFUNC)->op_pmflags & PMf_HAS_CV))
1496 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1497 SAVEFREESV(PL_compcv);
1501 SUBLEXSTART listexpr optrepl SUBLEXEND
1502 { $$ = pmruntime($PMFUNC, $listexpr, $optrepl, 1, $<ival>2); }
1508 /* "my" declarations, with optional attributes */
1510 : KW_MY myterm myattrlist
1511 { $$ = my_attrs($myterm,$myattrlist); }
1513 { $$ = localize($myterm,1); }
1514 | KW_MY REFGEN myterm myattrlist
1515 { $$ = newUNOP(OP_REFGEN, 0, my_attrs($myterm,$myattrlist)); }
1516 | KW_MY REFGEN term[operand]
1517 { $$ = newUNOP(OP_REFGEN, 0, localize($operand,1)); }
1520 /* Things that can be "my"'d */
1521 myterm : PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1522 { $$ = sawparens($expr); }
1523 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1524 { $$ = sawparens(newNULLLIST()); }
1526 | scalar %prec PERLY_PAREN_OPEN
1528 | hsh %prec PERLY_PAREN_OPEN
1530 | ary %prec PERLY_PAREN_OPEN
1534 /* "field" declarations */
1535 fieldvar: scalar %prec PERLY_PAREN_OPEN
1537 $$ = PadnamelistARRAY(PL_comppad_name)[$scalar->op_targ];
1540 | hsh %prec PERLY_PAREN_OPEN
1542 $$ = PadnamelistARRAY(PL_comppad_name)[$hsh->op_targ];
1545 | ary %prec PERLY_PAREN_OPEN
1547 $$ = PadnamelistARRAY(PL_comppad_name)[$ary->op_targ];
1561 : KW_FIELD fieldvar optfieldattrlist
1564 if($optfieldattrlist)
1565 class_apply_field_attributes((PADNAME *)$fieldvar, $optfieldattrlist);
1566 $$ = newOP(OP_NULL, 0);
1568 | KW_FIELD fieldvar optfieldattrlist ASSIGNOP
1571 if($optfieldattrlist)
1572 class_apply_field_attributes((PADNAME *)$fieldvar, $optfieldattrlist);
1574 class_prepare_initfield_parse();
1578 class_set_field_defop((PADNAME *)$fieldvar, $ASSIGNOP, $term);
1580 $$ = newOP(OP_NULL, 0);
1584 /* Basic list expressions */
1586 : empty %prec PREC_LOW
1587 | listexpr %prec PREC_LOW
1597 | PERLY_SLASH expr { $$ = $expr; }
1600 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1603 { parser->in_my = 0; $$ = my($scalar); }
1606 /* A list of scalars for "for my ($foo, $bar) (@baz)" */
1607 list_of_scalars: list_of_scalars[list] PERLY_COMMA
1609 | list_of_scalars[list] PERLY_COMMA scalar
1611 $$ = op_append_elem(OP_LIST, $list, $scalar);
1613 | scalar %prec PREC_LOW
1616 my_list_of_scalars: list_of_scalars
1617 { parser->in_my = 0; $$ = $list_of_scalars; }
1625 refgen_topic: my_var
1629 my_refgen: KW_MY REFGEN
1633 amper : PERLY_AMPERSAND indirob
1634 { $$ = newCVREF($PERLY_AMPERSAND,$indirob); }
1637 scalar : PERLY_DOLLAR indirob
1638 { $$ = newSVREF($indirob); }
1641 ary : PERLY_SNAIL indirob
1642 { $$ = newAVREF($indirob);
1643 if ($$) $$->op_private |= $PERLY_SNAIL;
1647 hsh : PERLY_PERCENT_SIGN indirob
1648 { $$ = newHVREF($indirob);
1649 if ($$) $$->op_private |= $PERLY_PERCENT_SIGN;
1653 arylen : DOLSHARP indirob
1654 { $$ = newAVREF($indirob); }
1655 | term ARROW DOLSHARP PERLY_STAR
1656 { $$ = newAVREF($term); }
1659 star : PERLY_STAR indirob
1660 { $$ = newGVREF(0,$indirob); }
1664 | term ARROW PERLY_SNAIL
1665 { $$ = newAVREF($term); }
1669 | term ARROW PERLY_PERCENT_SIGN
1670 { $$ = newHVREF($term); }
1674 | term ARROW PERLY_STAR
1675 { $$ = newGVREF(0,$term); }
1678 /* Indirect objects */
1680 { $$ = scalar($BAREWORD); }
1681 | scalar %prec PREC_LOW
1682 { $$ = scalar($scalar); }
1684 { $$ = op_scope($block); }
1687 { $$ = $PRIVATEREF; }