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 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 %token <ival> '{' '}' '[' ']' '-' '+' '@' '%' '&' '=' '.'
50 %token <opval> BAREWORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST
51 %token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
52 %token <opval> PLUGEXPR PLUGSTMT
54 %token <ival> FORMAT SUB SIGSUB ANONSUB ANON_SIGSUB PACKAGE USE
55 %token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
56 %token <ival> GIVEN WHEN DEFAULT
57 %token <ival> LOOPEX DOTDOT YADAYADA
58 %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
59 %token <ival> RELOP EQOP MULOP ADDOP
60 %token <ival> DOLSHARP DO HASHBRACK NOAMP
61 %token <ival> LOCAL MY REQUIRE
62 %token <ival> COLONATTR FORMLBRACK FORMRBRACK
63 %token <ival> SUBLEXSTART SUBLEXEND
65 %type <ival> grammar remember mremember
66 %type <ival> startsub startanonsub startformsub
70 %type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
71 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
72 %type <opval> sliceme kvslice gelem
73 %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
74 %type <opval> optlistexpr optexpr optrepl indirob listop method
75 %type <opval> formname subname proto cont my_scalar my_var
76 %type <opval> refgen_topic formblock
77 %type <opval> subattrlist myattrlist myattrterm myterm
78 %type <opval> termbinop termunop anonymous termdo
79 %type <ival> sigslurpsigil
80 %type <opval> sigvarname sigdefault sigscalarelem sigslurpelem
81 %type <opval> sigelem siglist siglistornull subsigguts subsignature optsubsignature
82 %type <opval> subbody optsubbody sigsubbody optsigsubbody
83 %type <opval> formstmtseq formline formarg
85 %nonassoc <ival> PREC_LOW
88 %left <ival> OROP DOROP
91 %nonassoc LSTOP LSTOPSUB
93 %right <ival> ASSIGNOP
96 %left <ival> OROR DORDOR
102 %nonassoc UNIOP UNIOPSUB
108 %right <ival> '!' '~' UMINUS REFGEN
110 %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
118 /* Top-level choice of what kind of thing yyparse was called to parse */
121 parser->expect = XSTATE;
126 newPROG(block_end($3,$4));
127 PL_compiling.cop_seq = 0;
132 parser->expect = XTERM;
142 parser->expect = XBLOCK;
147 PL_pad_reset_pending = TRUE;
151 parser->yychar = yytoken = YYEOF;
155 parser->expect = XSTATE;
160 PL_pad_reset_pending = TRUE;
164 parser->yychar = yytoken = YYEOF;
168 parser->expect = XSTATE;
173 PL_pad_reset_pending = TRUE;
177 parser->yychar = yytoken = YYEOF;
181 parser->expect = XSTATE;
191 parser->expect = XSTATE;
201 /* An ordinary block */
202 block : '{' remember stmtseq '}'
203 { if (parser->copline > (line_t)$1)
204 parser->copline = (line_t)$1;
205 $$ = block_end($2, $3);
210 formblock: '=' remember ';' FORMRBRACK formstmtseq ';' '.'
211 { if (parser->copline > (line_t)$1)
212 parser->copline = (line_t)$1;
213 $$ = block_end($2, $5);
217 remember: /* NULL */ /* start a full lexical scope */
218 { $$ = block_start(TRUE);
219 parser->parsed_sub = 0; }
222 mblock : '{' mremember stmtseq '}'
223 { if (parser->copline > (line_t)$1)
224 parser->copline = (line_t)$1;
225 $$ = block_end($2, $3);
229 mremember: /* NULL */ /* start a partial lexical scope */
230 { $$ = block_start(FALSE);
231 parser->parsed_sub = 0; }
234 /* A sequence of statements in the program */
238 { $$ = op_append_list(OP_LINESEQ, $1, $2);
239 PL_pad_reset_pending = TRUE;
241 PL_hints |= HINT_BLOCK_SCOPE;
245 /* A sequence of format lines */
246 formstmtseq: /* NULL */
248 | formstmtseq formline
249 { $$ = op_append_list(OP_LINESEQ, $1, $2);
250 PL_pad_reset_pending = TRUE;
252 PL_hints |= HINT_BLOCK_SCOPE;
256 /* A statement in the program, including optional labels */
259 $$ = $1 ? newSTATEOP(0, NULL, $1) : NULL;
265 labfullstmt: LABEL barestmt
267 SV *label = cSVOPx_sv($1);
268 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
269 savepv(SvPVX_const(label)), $2);
274 SV *label = cSVOPx_sv($1);
275 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
276 savepv(SvPVX_const(label)), $2);
281 /* A bare statement, lacking label and other aspects of state op */
284 | FORMAT startformsub formname formblock
286 CV *fmtcv = PL_compcv;
289 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
290 pad_add_weakref(fmtcv);
292 parser->parsed_sub = 1;
294 | SUB subname startsub
295 /* sub declaration or definition not within scope
296 of 'use feature "signatures"'*/
298 init_named_cv(PL_compcv, $2);
300 parser->in_my_stash = NULL;
302 proto subattrlist optsubbody
304 SvREFCNT_inc_simple_void(PL_compcv);
305 $2->op_type == OP_CONST
306 ? newATTRSUB($3, $2, $5, $6, $7)
307 : newMYSUB($3, $2, $5, $6, $7)
311 parser->parsed_sub = 1;
313 | SIGSUB subname startsub
314 /* sub declaration or definition under 'use feature
315 * "signatures"'. (Note that a signature isn't
316 * allowed in a declaration)
319 init_named_cv(PL_compcv, $2);
321 parser->in_my_stash = NULL;
323 subattrlist optsigsubbody
325 SvREFCNT_inc_simple_void(PL_compcv);
326 $2->op_type == OP_CONST
327 ? newATTRSUB($3, $2, NULL, $5, $6)
328 : newMYSUB( $3, $2, NULL, $5, $6)
332 parser->parsed_sub = 1;
334 | PACKAGE BAREWORD BAREWORD ';'
342 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
343 BAREWORD BAREWORD optlistexpr ';'
345 SvREFCNT_inc_simple_void(PL_compcv);
346 utilize($1, $2, $4, $5, $6);
347 parser->parsed_sub = 1;
350 | IF '(' remember mexpr ')' mblock else
353 newCONDOP(0, $4, op_scope($6), $7));
354 parser->copline = (line_t)$1;
356 | UNLESS '(' remember mexpr ')' mblock else
359 newCONDOP(0, $4, $7, op_scope($6)));
360 parser->copline = (line_t)$1;
362 | GIVEN '(' remember mexpr ')' mblock
364 $$ = block_end($3, newGIVENOP($4, op_scope($6), 0));
365 parser->copline = (line_t)$1;
367 | WHEN '(' remember mexpr ')' mblock
368 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
370 { $$ = newWHENOP(0, op_scope($2)); }
371 | WHILE '(' remember texpr ')' mintro mblock cont
374 newWHILEOP(0, 1, NULL,
376 parser->copline = (line_t)$1;
378 | UNTIL '(' remember iexpr ')' mintro mblock cont
381 newWHILEOP(0, 1, NULL,
383 parser->copline = (line_t)$1;
385 | FOR '(' remember mnexpr ';'
386 { parser->expect = XTERM; }
388 { parser->expect = XTERM; }
393 OP *forop = newWHILEOP(0, 1, NULL,
394 scalar($7), $13, $11, $10);
396 forop = op_prepend_elem(OP_LINESEQ, initop,
397 op_append_elem(OP_LINESEQ,
398 newOP(OP_UNSTACK, OPf_SPECIAL),
401 PL_hints |= HINT_BLOCK_SCOPE;
402 $$ = block_end($3, forop);
403 parser->copline = (line_t)$1;
405 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
407 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
408 parser->copline = (line_t)$1;
410 | FOR scalar '(' remember mexpr ')' mblock cont
412 $$ = block_end($4, newFOROP(0,
413 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
414 parser->copline = (line_t)$1;
416 | FOR my_refgen remember my_var
417 { parser->in_my = 0; $<opval>$ = my($4); }
418 '(' mexpr ')' mblock cont
424 newUNOP(OP_REFGEN, 0,
429 parser->copline = (line_t)$1;
431 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
433 $$ = block_end($5, newFOROP(
434 0, op_lvalue(newUNOP(OP_REFGEN, 0,
436 OP_ENTERLOOP), $6, $8, $9));
437 parser->copline = (line_t)$1;
439 | FOR '(' remember mexpr ')' mblock cont
442 newFOROP(0, NULL, $4, $6, $7));
443 parser->copline = (line_t)$1;
447 /* a block is a loop that happens once */
448 $$ = newWHILEOP(0, 1, NULL,
451 | PACKAGE BAREWORD BAREWORD '{' remember
460 /* a block is a loop that happens once */
461 $$ = newWHILEOP(0, 1, NULL,
462 NULL, block_end($5, $7), NULL, 0);
463 if (parser->copline > (line_t)$4)
464 parser->copline = (line_t)$4;
472 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
473 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
478 parser->copline = NOLINE;
483 formline: THING formarg
487 list = op_append_elem(OP_LIST, $1, term);
492 if (parser->copline == NOLINE)
493 parser->copline = CopLINE(PL_curcop)-1;
494 else parser->copline--;
495 $$ = newSTATEOP(0, NULL,
496 op_convert_list(OP_FORMLINE, 0, list));
502 | FORMLBRACK stmtseq FORMRBRACK
503 { $$ = op_unscope($2); }
506 /* An expression which may have a side-effect */
512 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
514 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
516 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
518 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
520 { $$ = newFOROP(0, NULL, $3, $1, NULL);
521 parser->copline = (line_t)$2; }
523 { $$ = newWHENOP($3, op_scope($1)); }
526 /* else and elsif blocks */
531 ($2)->op_flags |= OPf_PARENS;
534 | ELSIF '(' mexpr ')' mblock else
535 { parser->copline = (line_t)$1;
537 newSTATEOP(OPf_SPECIAL,NULL,$3),
539 PL_hints |= HINT_BLOCK_SCOPE;
543 /* Continue blocks */
547 { $$ = op_scope($2); }
550 /* determine whether there are any new my declarations */
552 { $$ = (PL_min_intro_pending &&
553 PL_max_intro_pending >= PL_min_intro_pending);
556 /* Normal expression */
562 /* Boolean expression */
563 texpr : /* NULL means true */
565 (void)scan_num("1", &tmplval);
566 $$ = tmplval.opval; }
570 /* Inverted boolean expression */
572 { $$ = invert(scalar($1)); }
575 /* Expression with its own lexical scope */
577 { $$ = $1; intro_my(); }
581 { $$ = $1; intro_my(); }
584 formname: BAREWORD { $$ = $1; }
585 | /* NULL */ { $$ = NULL; }
588 startsub: /* NULL */ /* start a regular subroutine scope */
589 { $$ = start_subparse(FALSE, 0);
590 SAVEFREESV(PL_compcv); }
594 startanonsub: /* NULL */ /* start an anonymous subroutine scope */
595 { $$ = start_subparse(FALSE, CVf_ANON);
596 SAVEFREESV(PL_compcv); }
599 startformsub: /* NULL */ /* start a format subroutine scope */
600 { $$ = start_subparse(TRUE, 0);
601 SAVEFREESV(PL_compcv); }
604 /* Name of a subroutine - must be a bareword, could be special */
609 /* Subroutine prototype */
615 /* Optional list of subroutine attributes */
616 subattrlist: /* NULL */
624 /* List of attributes for a "my" variable declaration */
625 myattrlist: COLONATTR THING
633 /* --------------------------------------
634 * subroutine signature parsing
637 /* the '' or 'foo' part of a '$' or '@foo' etc signature variable */
638 sigvarname: /* NULL */
639 { parser->in_my = 0; $$ = NULL; }
641 { parser->in_my = 0; $$ = $1; }
650 /* @, %, @foo, %foo */
651 sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
657 if (parser->sig_slurpy)
658 yyerror("Multiple slurpy parameters not allowed");
659 parser->sig_slurpy = (char)sigil;
662 yyerror("A slurpy parameter may not have "
665 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
669 /* default part of sub signature scalar element: i.e. '= default_expr' */
670 sigdefault: /* NULL */
673 { $$ = newOP(OP_NULL, 0); }
678 /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
680 '$' sigvarname sigdefault
685 if (parser->sig_slurpy)
686 yyerror("Slurpy parameter not last");
691 parser->sig_optelems++;
693 if ( defexpr->op_type == OP_NULL
694 && !(defexpr->op_flags & OPf_KIDS))
696 /* handle '$=' special case */
698 yyerror("Optional parameter "
699 "lacks default expression");
703 /* a normal '=default' expression */
704 OP *defop = (OP*)alloc_LOGOP(OP_ARGDEFELEM,
707 /* re-purpose op_targ to hold @_ index */
709 (PADOFFSET)(parser->sig_elems - 1);
712 var->op_flags |= OPf_STACKED;
713 (void)op_sibling_splice(var,
718 var = newUNOP(OP_NULL, 0, defop);
721 /* NB: normally the first child of a
722 * logop is executed before the logop,
723 * and it pushes a boolean result
724 * ready for the logop. For ARGDEFELEM,
725 * the op itself does the boolean
726 * calculation, so set the first op to
729 var->op_next = defop;
730 defexpr->op_next = var;
734 if (parser->sig_optelems)
735 yyerror("Mandatory parameter "
736 "follows optional parameter");
739 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
744 /* subroutine signature element: e.g. '$x = $default' or '%h' */
745 sigelem: sigscalarelem
746 { parser->in_my = KEY_sigvar; $$ = $1; }
748 { parser->in_my = KEY_sigvar; $$ = $1; }
751 /* list of subroutine signature elements */
755 | siglist ',' sigelem
757 $$ = op_append_list(OP_LINESEQ, $1, $3);
759 | sigelem %prec PREC_LOW
764 siglistornull: /* NULL */
769 /* optional subroutine signature */
770 optsubsignature: /* NULL */
775 /* Subroutine signature */
776 subsignature: '(' subsigguts ')'
782 SAVEIV(parser->sig_elems);
783 SAVEIV(parser->sig_optelems);
784 SAVEI8(parser->sig_slurpy);
785 parser->sig_elems = 0;
786 parser->sig_optelems = 0;
787 parser->sig_slurpy = 0;
788 parser->in_my = KEY_sigvar;
796 if (!FEATURE_SIGNATURES_IS_ENABLED)
797 Perl_croak(aTHX_ "Experimental "
798 "subroutine signatures not enabled");
800 /* We shouldn't get here otherwise */
801 Perl_ck_warner_d(aTHX_
802 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
803 "The signatures feature is experimental");
805 aux = (UNOP_AUX_item*)PerlMemShared_malloc(
806 sizeof(UNOP_AUX_item) * 3);
807 aux[0].iv = parser->sig_elems;
808 aux[1].iv = parser->sig_optelems;
809 aux[2].iv = parser->sig_slurpy;
810 check = newUNOP_AUX(OP_ARGCHECK, 0, NULL, aux);
811 sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
812 sigops = op_prepend_elem(OP_LINESEQ,
813 newSTATEOP(0, NULL, NULL),
815 /* a nextstate at the end handles context
816 * correctly for an empty sub body */
817 $$ = op_append_elem(OP_LINESEQ,
819 newSTATEOP(0, NULL, NULL));
822 /* tell the toker that attrributes can follow
823 * this sig, but only so that the toker
824 * can skip through any (illegal) trailing
825 * attribute text then give a useful error
826 * message about "attributes before sig",
827 * rather than falling over ina mess at
828 * unrecognised syntax.
830 parser->expect = XATTRBLOCK;
831 parser->sig_seen = TRUE;
836 /* Optional subroutine body (for named subroutine declaration) */
837 optsubbody: subbody { $$ = $1; }
842 /* Subroutine body (without signature) */
843 subbody: remember '{' stmtseq '}'
845 if (parser->copline > (line_t)$2)
846 parser->copline = (line_t)$2;
847 $$ = block_end($1, $3);
852 /* optional [ Subroutine body with optional signature ] (for named
853 * subroutine declaration) */
854 optsigsubbody: sigsubbody { $$ = $1; }
857 /* Subroutine body with optional signature */
858 sigsubbody: remember optsubsignature '{' stmtseq '}'
860 if (parser->copline > (line_t)$3)
861 parser->copline = (line_t)$3;
863 op_append_list(OP_LINESEQ, $2, $4));
868 /* Ordinary expressions; logical combinations */
869 expr : expr ANDOP expr
870 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
872 { $$ = newLOGOP($2, 0, $1, $3); }
874 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
875 | listexpr %prec PREC_LOW
878 /* Expressions are a list of terms joined by commas */
879 listexpr: listexpr ','
884 $$ = op_append_elem(OP_LIST, $1, term);
886 | term %prec PREC_LOW
890 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
891 { $$ = op_convert_list($1, OPf_STACKED,
892 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
894 | FUNC '(' indirob expr ')' /* print ($fh @args */
895 { $$ = op_convert_list($1, OPf_STACKED,
896 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
898 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
899 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
900 op_append_elem(OP_LIST,
901 op_prepend_elem(OP_LIST, scalar($1), $5),
902 newMETHOP(OP_METHOD, 0, $3)));
904 | term ARROW method /* $foo->bar */
905 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
906 op_append_elem(OP_LIST, scalar($1),
907 newMETHOP(OP_METHOD, 0, $3)));
909 | METHOD indirob optlistexpr /* new Class @args */
910 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
911 op_append_elem(OP_LIST,
912 op_prepend_elem(OP_LIST, $2, $3),
913 newMETHOP(OP_METHOD, 0, $1)));
915 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
916 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
917 op_append_elem(OP_LIST,
918 op_prepend_elem(OP_LIST, $2, $4),
919 newMETHOP(OP_METHOD, 0, $1)));
921 | LSTOP optlistexpr /* print @args */
922 { $$ = op_convert_list($1, 0, $2); }
923 | FUNC '(' optexpr ')' /* print (@args) */
924 { $$ = op_convert_list($1, 0, $3); }
925 | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */
926 { $$ = op_convert_list($1, 0, $3); }
927 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
928 { SvREFCNT_inc_simple_void(PL_compcv);
929 $<opval>$ = newANONATTRSUB($2, 0, NULL, $3); }
930 optlistexpr %prec LSTOP /* ... @bar */
931 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
932 op_append_elem(OP_LIST,
933 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
937 /* Names of methods. May use $object->$methodname */
942 /* Some kind of subscripted expression */
943 subscripted: gelem '{' expr ';' '}' /* *main::{something} */
944 /* In this and all the hash accessors, ';' is
945 * provided by the tokeniser */
946 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
947 | scalar '[' expr ']' /* $array[$element] */
948 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
950 | term ARROW '[' expr ']' /* somearef->[$element] */
951 { $$ = newBINOP(OP_AELEM, 0,
952 ref(newAVREF($1),OP_RV2AV),
955 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
956 { $$ = newBINOP(OP_AELEM, 0,
957 ref(newAVREF($1),OP_RV2AV),
960 | scalar '{' expr ';' '}' /* $foo{bar();} */
961 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
963 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
964 { $$ = newBINOP(OP_HELEM, 0,
965 ref(newHVREF($1),OP_RV2HV),
967 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
968 { $$ = newBINOP(OP_HELEM, 0,
969 ref(newHVREF($1),OP_RV2HV),
971 | term ARROW '(' ')' /* $subref->() */
972 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
973 newCVREF(0, scalar($1)));
974 if (parser->expect == XBLOCK)
975 parser->expect = XOPERATOR;
977 | term ARROW '(' expr ')' /* $subref->(@args) */
978 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
979 op_append_elem(OP_LIST, $4,
980 newCVREF(0, scalar($1))));
981 if (parser->expect == XBLOCK)
982 parser->expect = XOPERATOR;
985 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
986 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
987 op_append_elem(OP_LIST, $3,
988 newCVREF(0, scalar($1))));
989 if (parser->expect == XBLOCK)
990 parser->expect = XOPERATOR;
992 | subscripted '(' ')' /* $foo->{bar}->() */
993 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
994 newCVREF(0, scalar($1)));
995 if (parser->expect == XBLOCK)
996 parser->expect = XOPERATOR;
998 | '(' expr ')' '[' expr ']' /* list slice */
999 { $$ = newSLICEOP(0, $5, $2); }
1000 | QWLIST '[' expr ']' /* list literal slice */
1001 { $$ = newSLICEOP(0, $3, $1); }
1002 | '(' ')' '[' expr ']' /* empty list slice! */
1003 { $$ = newSLICEOP(0, $4, NULL); }
1006 /* Binary operators between terms */
1007 termbinop: term ASSIGNOP term /* $x = $y, $x += $y */
1008 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
1009 | term POWOP term /* $x ** $y */
1010 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1011 | term MULOP term /* $x * $y, $x x $y */
1012 { if ($2 != OP_REPEAT)
1014 $$ = newBINOP($2, 0, $1, scalar($3));
1016 | term ADDOP term /* $x + $y */
1017 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1018 | term SHIFTOP term /* $x >> $y, $x << $y */
1019 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1020 | term RELOP term /* $x > $y, etc. */
1021 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1022 | term EQOP term /* $x == $y, $x eq $y */
1023 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1024 | term BITANDOP term /* $x & $y */
1025 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1026 | term BITOROP term /* $x | $y */
1027 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1028 | term DOTDOT term /* $x..$y, $x...$y */
1029 { $$ = newRANGE($2, scalar($1), scalar($3)); }
1030 | term ANDAND term /* $x && $y */
1031 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
1032 | term OROR term /* $x || $y */
1033 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
1034 | term DORDOR term /* $x // $y */
1035 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
1036 | term MATCHOP term /* $x =~ /$y/ */
1037 { $$ = bind_match($2, $1, $3); }
1040 /* Unary operators and terms */
1041 termunop : '-' term %prec UMINUS /* -$x */
1042 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
1043 | '+' term %prec UMINUS /* +$x */
1046 | '!' term /* !$x */
1047 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
1048 | '~' term /* ~$x */
1049 { $$ = newUNOP($1, 0, scalar($2)); }
1050 | term POSTINC /* $x++ */
1051 { $$ = newUNOP(OP_POSTINC, 0,
1052 op_lvalue(scalar($1), OP_POSTINC)); }
1053 | term POSTDEC /* $x-- */
1054 { $$ = newUNOP(OP_POSTDEC, 0,
1055 op_lvalue(scalar($1), OP_POSTDEC));}
1056 | term POSTJOIN /* implicit join after interpolated ->@ */
1057 { $$ = op_convert_list(OP_JOIN, 0,
1067 | PREINC term /* ++$x */
1068 { $$ = newUNOP(OP_PREINC, 0,
1069 op_lvalue(scalar($2), OP_PREINC)); }
1070 | PREDEC term /* --$x */
1071 { $$ = newUNOP(OP_PREDEC, 0,
1072 op_lvalue(scalar($2), OP_PREDEC)); }
1076 /* Constructors for anonymous data */
1077 anonymous: '[' expr ']'
1078 { $$ = newANONLIST($2); }
1080 { $$ = newANONLIST(NULL);}
1081 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
1082 { $$ = newANONHASH($2); }
1083 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
1084 { $$ = newANONHASH(NULL); }
1085 | ANONSUB startanonsub proto subattrlist subbody %prec '('
1086 { SvREFCNT_inc_simple_void(PL_compcv);
1087 $$ = newANONATTRSUB($2, $3, $4, $5); }
1088 | ANON_SIGSUB startanonsub subattrlist sigsubbody %prec '('
1089 { SvREFCNT_inc_simple_void(PL_compcv);
1090 $$ = newANONATTRSUB($2, NULL, $3, $4); }
1093 /* Things called with "do" */
1094 termdo : DO term %prec UNIOP /* do $filename */
1095 { $$ = dofile($2, $1);}
1096 | DO block %prec '(' /* do { code */
1097 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
1104 | term '?' term ':' term
1105 { $$ = newCONDOP(0, $1, $3, $5); }
1106 | REFGEN term /* \$x, \@y, \%z */
1107 { $$ = newUNOP(OP_REFGEN, 0, $2); }
1109 { $$ = newUNOP(OP_REFGEN, 0, localize($3,1)); }
1110 | myattrterm %prec UNIOP
1112 | LOCAL term %prec UNIOP
1113 { $$ = localize($2,0); }
1115 { $$ = sawparens($2); }
1119 { $$ = sawparens(newNULLLIST()); }
1128 | arylen %prec '(' /* $#x, $#{ something } */
1129 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
1132 | sliceme '[' expr ']' /* array slice */
1133 { $$ = op_prepend_elem(OP_ASLICE,
1134 newOP(OP_PUSHMARK, 0),
1135 newLISTOP(OP_ASLICE, 0,
1137 ref($1, OP_ASLICE)));
1140 $1->op_private & OPpSLICEWARNING;
1142 | kvslice '[' expr ']' /* array key/value slice */
1143 { $$ = op_prepend_elem(OP_KVASLICE,
1144 newOP(OP_PUSHMARK, 0),
1145 newLISTOP(OP_KVASLICE, 0,
1147 ref(oopsAV($1), OP_KVASLICE)));
1150 $1->op_private & OPpSLICEWARNING;
1152 | sliceme '{' expr ';' '}' /* @hash{@keys} */
1153 { $$ = op_prepend_elem(OP_HSLICE,
1154 newOP(OP_PUSHMARK, 0),
1155 newLISTOP(OP_HSLICE, 0,
1157 ref(oopsHV($1), OP_HSLICE)));
1160 $1->op_private & OPpSLICEWARNING;
1162 | kvslice '{' expr ';' '}' /* %hash{@keys} */
1163 { $$ = op_prepend_elem(OP_KVHSLICE,
1164 newOP(OP_PUSHMARK, 0),
1165 newLISTOP(OP_KVHSLICE, 0,
1167 ref($1, OP_KVHSLICE)));
1170 $1->op_private & OPpSLICEWARNING;
1175 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
1176 | amper '(' ')' /* &foo() or foo() */
1177 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
1179 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
1181 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1182 op_append_elem(OP_LIST, $3, scalar($1)));
1184 | NOAMP subname optlistexpr /* foo @args (no parens) */
1185 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1186 op_append_elem(OP_LIST, $3, scalar($2)));
1188 | term ARROW '$' '*'
1189 { $$ = newSVREF($1); }
1190 | term ARROW '@' '*'
1191 { $$ = newAVREF($1); }
1192 | term ARROW '%' '*'
1193 { $$ = newHVREF($1); }
1194 | term ARROW '&' '*'
1195 { $$ = newUNOP(OP_ENTERSUB, 0,
1196 scalar(newCVREF($3,$1))); }
1197 | term ARROW '*' '*' %prec '('
1198 { $$ = newGVREF(0,$1); }
1199 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
1200 { $$ = newOP($1, OPf_SPECIAL);
1201 PL_hints |= HINT_BLOCK_SCOPE; }
1203 { $$ = newLOOPEX($1,$2); }
1204 | NOTOP listexpr /* not $foo */
1205 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
1206 | UNIOP /* Unary op, $_ implied */
1207 { $$ = newOP($1, 0); }
1208 | UNIOP block /* eval { foo }* */
1209 { $$ = newUNOP($1, 0, $2); }
1210 | UNIOP term /* Unary op */
1211 { $$ = newUNOP($1, 0, $2); }
1212 | REQUIRE /* require, $_ implied */
1213 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
1214 | REQUIRE term /* require Foo */
1215 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
1217 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
1218 | UNIOPSUB term /* Sub treated as unop */
1219 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1220 op_append_elem(OP_LIST, $2, scalar($1))); }
1221 | FUNC0 /* Nullary operator */
1222 { $$ = newOP($1, 0); }
1224 { $$ = newOP($1, 0);}
1225 | FUNC0OP /* Same as above, but op created in toke.c */
1229 | FUNC0SUB /* Sub treated as nullop */
1230 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
1231 | FUNC1 '(' ')' /* not () */
1232 { $$ = ($1 == OP_NOT)
1233 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1234 : newOP($1, OPf_SPECIAL); }
1235 | FUNC1 '(' expr ')' /* not($foo) */
1236 { $$ = newUNOP($1, 0, $3); }
1237 | PMFUNC /* m//, s///, qr//, tr/// */
1239 if ( $1->op_type != OP_TRANS
1240 && $1->op_type != OP_TRANSR
1241 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
1243 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1244 SAVEFREESV(PL_compcv);
1248 SUBLEXSTART listexpr optrepl SUBLEXEND
1249 { $$ = pmruntime($1, $4, $5, 1, $<ival>2); }
1255 /* "my" declarations, with optional attributes */
1256 myattrterm: MY myterm myattrlist
1257 { $$ = my_attrs($2,$3); }
1259 { $$ = localize($2,1); }
1260 | MY REFGEN myterm myattrlist
1261 { $$ = newUNOP(OP_REFGEN, 0, my_attrs($3,$4)); }
1264 /* Things that can be "my"'d */
1265 myterm : '(' expr ')'
1266 { $$ = sawparens($2); }
1268 { $$ = sawparens(newNULLLIST()); }
1278 /* Basic list expressions */
1279 optlistexpr: /* NULL */ %prec PREC_LOW
1281 | listexpr %prec PREC_LOW
1297 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1300 { parser->in_my = 0; $$ = my($1); }
1308 refgen_topic: my_var
1312 my_refgen: MY REFGEN
1317 { $$ = newCVREF($1,$2); }
1320 scalar : '$' indirob
1321 { $$ = newSVREF($2); }
1325 { $$ = newAVREF($2);
1326 if ($$) $$->op_private |= $1;
1331 { $$ = newHVREF($2);
1332 if ($$) $$->op_private |= $1;
1336 arylen : DOLSHARP indirob
1337 { $$ = newAVREF($2); }
1338 | term ARROW DOLSHARP '*'
1339 { $$ = newAVREF($1); }
1343 { $$ = newGVREF(0,$2); }
1348 { $$ = newAVREF($1); }
1353 { $$ = newHVREF($1); }
1358 { $$ = newGVREF(0,$1); }
1361 /* Indirect objects */
1363 { $$ = scalar($1); }
1364 | scalar %prec PREC_LOW
1365 { $$ = scalar($1); }
1367 { $$ = op_scope($1); }