This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Distinguish C- and perly- literals - PERLY_DOLLAR
[perl5.git] / perly.y
CommitLineData
a0d0e21e 1/* perly.y
a687059c 2 *
f05e27e5 3 * Copyright (c) 1991-2002, 2003, 2004, 2005, 2006 Larry Wall
2eee27d7 4 * Copyright (c) 2007, 2008, 2009, 2010, 2011 by Larry Wall and others
a687059c 5 *
9ef589d8
LW
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.
8d063cd8 8 *
a0d0e21e
LW
9 */
10
11/*
12 * 'I see,' laughed Strider. 'I look foul and feel fair. Is that it?
4ac71550 13 * All that is gold does not glitter, not all those who wander are lost.'
f05e27e5 14 *
4ac71550
TC
15 * [p.171 of _The Lord of the Rings_, I/x: "Strider"]
16 */
17
18/*
f05e27e5 19 * This file holds the grammar for the Perl language. If edited, you need
166f8a29
DM
20 * to run regen_perly.pl, which re-creates the files perly.h, perly.tab
21 * and perly.act which are derived from this.
22 *
a3815e44 23 * The main job of this grammar is to call the various newFOO()
166f8a29 24 * functions in op.c to build a syntax tree of OP structs.
61296642 25 * It relies on the lexer in toke.c to do the tokenizing.
29522234
DM
26 *
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
29 * an action.
166f8a29
DM
30 */
31
0de566d7 32/* Make the parser re-entrant. */
8d063cd8 33
0a2b3d88 34%define api.pure
8d063cd8 35
28ac2b49 36%start grammar
9d116dd7 37
8d063cd8 38%union {
d5c6462e
DM
39 I32 ival; /* __DEFAULT__ (marker for regen_perly.pl;
40 must always be 1st union member) */
79072805
LW
41 char *pval;
42 OP *opval;
43 GV *gvval;
8d063cd8
LW
44}
45
996b0cb8 46%token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ GRAMSUBSIGNATURE
28ac2b49 47
25a50500 48%token <ival> PERLY_AMPERSAND
c588171e 49%token <ival> PERLY_BRACE_OPEN
d0a6a9c7 50%token <ival> PERLY_BRACE_CLOSE
669dd22c 51%token <ival> PERLY_BRACKET_OPEN
fceeeb77 52%token <ival> PERLY_BRACKET_CLOSE
581f9a7a 53%token <ival> PERLY_COMMA
bfa838cc 54%token <ival> PERLY_DOLLAR
da4bce7d 55%token <ival> PERLY_DOT
db83e45c 56%token <ival> PERLY_EQUAL_SIGN
68a66a8b 57%token <ival> PERLY_MINUS
0ba95c59 58%token <ival> PERLY_PERCENT_SIGN
5776f3e5 59%token <ival> PERLY_PLUS
5adeeefb 60%token <ival> PERLY_SEMICOLON
77b0379f 61%token <ival> PERLY_SLASH
9086c946 62%token <ival> PERLY_SNAIL
d02b2fbf 63%token <ival> PERLY_STAR
f0fcb552 64
185c2e96 65%token <opval> BAREWORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST
7eb971ee 66%token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
88e1f1a2 67%token <opval> PLUGEXPR PLUGSTMT
01719201 68%token <opval> LABEL
436ddf68 69%token <ival> FORMAT SUB SIGSUB ANONSUB ANON_SIGSUB PACKAGE USE
b5bbe64a 70%token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
7896dde7 71%token <ival> GIVEN WHEN DEFAULT
b5bbe64a
JH
72%token <ival> LOOPEX DOTDOT YADAYADA
73%token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
02b85d3d 74%token <ival> MULOP ADDOP
b5bbe64a
JH
75%token <ival> DOLSHARP DO HASHBRACK NOAMP
76%token <ival> LOCAL MY REQUIRE
77%token <ival> COLONATTR FORMLBRACK FORMRBRACK
69afcc21 78%token <ival> SUBLEXSTART SUBLEXEND
f05e27e5 79
727a8fe5 80%type <ival> grammar remember mremember
f05e27e5 81%type <ival> startsub startanonsub startformsub
b5bbe64a 82
b5a64814 83%type <ival> mintro
f05e27e5 84
8e720305 85%type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
fad39ff1 86%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
53443c95 87%type <opval> condition
76eba8ab 88%type <opval> sliceme kvslice gelem
08b3e84f 89%type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
9b6b7be8 90%type <opval> optlistexpr optexpr optrepl indirob listop method
75230cc1 91%type <opval> formname subname proto cont my_scalar my_var
d39c26a6 92%type <opval> refgen_topic formblock
f05e27e5 93%type <opval> subattrlist myattrlist myattrterm myterm
75230cc1 94%type <opval> termbinop termunop anonymous termdo
02b85d3d 95%type <opval> termrelop relopchain termeqop eqopchain
d3d9da4a
DM
96%type <ival> sigslurpsigil
97%type <opval> sigvarname sigdefault sigscalarelem sigslurpelem
996b0cb8 98%type <opval> sigelem siglist siglistornull subsigguts subsignature optsubsignature
75230cc1 99%type <opval> subbody optsubbody sigsubbody optsigsubbody
705fe0e5 100%type <opval> formstmtseq formline formarg
79072805 101
b5bbe64a 102%nonassoc <ival> PREC_LOW
fad39ff1
SM
103%nonassoc LOOPEX
104
b5bbe64a
JH
105%left <ival> OROP DOROP
106%left <ival> ANDOP
107%right <ival> NOTOP
36477c24 108%nonassoc LSTOP LSTOPSUB
581f9a7a 109%left PERLY_COMMA
b5bbe64a 110%right <ival> ASSIGNOP
a1ad62bf 111%right <ival> PERLY_QUESTION_MARK PERLY_COLON
29d69c3c 112%nonassoc DOTDOT
b5bbe64a
JH
113%left <ival> OROR DORDOR
114%left <ival> ANDAND
115%left <ival> BITOROP
116%left <ival> BITANDOP
02b85d3d
Z
117%left <ival> CHEQOP NCEQOP
118%left <ival> CHRELOP NCRELOP
36477c24 119%nonassoc UNIOP UNIOPSUB
20515881 120%nonassoc REQUIRE
b5bbe64a 121%left <ival> SHIFTOP
a687059c
LW
122%left ADDOP
123%left MULOP
b5bbe64a 124%left <ival> MATCHOP
3d92c6b8 125%right <ival> PERLY_EXCLAMATION_MARK PERLY_TILDE UMINUS REFGEN
b5bbe64a
JH
126%right <ival> POWOP
127%nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
128%left <ival> ARROW
04884b68 129%nonassoc <ival> PERLY_PAREN_CLOSE
ee67f254 130%left <ival> PERLY_PAREN_OPEN
669dd22c 131%left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN
8d063cd8
LW
132
133%% /* RULES */
134
28ac2b49 135/* Top-level choice of what kind of thing yyparse was called to parse */
727a8fe5
Z
136grammar : GRAMPROG
137 {
624fa8bd 138 parser->expect = XSTATE;
5a2060e2 139 $<ival>$ = 0;
727a8fe5
Z
140 }
141 remember stmtseq
142 {
53443c95 143 newPROG(block_end($remember,$stmtseq));
8635e3c2 144 PL_compiling.cop_seq = 0;
727a8fe5
Z
145 $$ = 0;
146 }
78cdf107
Z
147 | GRAMEXPR
148 {
149 parser->expect = XTERM;
5a2060e2 150 $<ival>$ = 0;
78cdf107 151 }
09b1cffe 152 optexpr
78cdf107 153 {
53443c95 154 PL_eval_root = $optexpr;
78cdf107
Z
155 $$ = 0;
156 }
e53d8f76
Z
157 | GRAMBLOCK
158 {
159 parser->expect = XBLOCK;
5a2060e2 160 $<ival>$ = 0;
e53d8f76
Z
161 }
162 block
163 {
5f211341 164 PL_pad_reset_pending = TRUE;
53443c95 165 PL_eval_root = $block;
8359b381
Z
166 $$ = 0;
167 yyunlex();
0f8490d1 168 parser->yychar = yytoken = YYEOF;
8359b381
Z
169 }
170 | GRAMBARESTMT
171 {
172 parser->expect = XSTATE;
5a2060e2 173 $<ival>$ = 0;
8359b381
Z
174 }
175 barestmt
176 {
177 PL_pad_reset_pending = TRUE;
53443c95 178 PL_eval_root = $barestmt;
e53d8f76
Z
179 $$ = 0;
180 yyunlex();
0f8490d1 181 parser->yychar = yytoken = YYEOF;
e53d8f76 182 }
9eb5c532 183 | GRAMFULLSTMT
28ac2b49 184 {
9eb5c532 185 parser->expect = XSTATE;
5a2060e2 186 $<ival>$ = 0;
9eb5c532
Z
187 }
188 fullstmt
189 {
5f211341 190 PL_pad_reset_pending = TRUE;
53443c95 191 PL_eval_root = $fullstmt;
28ac2b49
Z
192 $$ = 0;
193 yyunlex();
0f8490d1 194 parser->yychar = yytoken = YYEOF;
28ac2b49 195 }
07ffcb73
Z
196 | GRAMSTMTSEQ
197 {
198 parser->expect = XSTATE;
5a2060e2 199 $<ival>$ = 0;
07ffcb73 200 }
5f211341 201 stmtseq
07ffcb73 202 {
53443c95 203 PL_eval_root = $stmtseq;
07ffcb73
Z
204 $$ = 0;
205 }
996b0cb8
PLE
206 | GRAMSUBSIGNATURE
207 {
208 parser->expect = XSTATE;
209 $<ival>$ = 0;
210 }
211 subsigguts
212 {
53443c95 213 PL_eval_root = $subsigguts;
996b0cb8
PLE
214 $$ = 0;
215 }
07ffcb73
Z
216 ;
217
891be019 218/* An ordinary block */
d0a6a9c7 219block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE
c588171e
BZ
220 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
221 parser->copline = (line_t)$PERLY_BRACE_OPEN;
53443c95 222 $$ = block_end($remember, $stmtseq);
f05e27e5 223 }
a0d0e21e
LW
224 ;
225
7c70caa5 226/* format body */
db83e45c
BZ
227formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT
228 { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN)
229 parser->copline = (line_t)$PERLY_EQUAL_SIGN;
53443c95 230 $$ = block_end($remember, $formstmtseq);
7c70caa5
FC
231 }
232 ;
233
55497cff 234remember: /* NULL */ /* start a full lexical scope */
34b54951
FC
235 { $$ = block_start(TRUE);
236 parser->parsed_sub = 0; }
55497cff
PP
237 ;
238
d0a6a9c7 239mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE
c588171e
BZ
240 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
241 parser->copline = (line_t)$PERLY_BRACE_OPEN;
53443c95 242 $$ = block_end($mremember, $stmtseq);
f05e27e5 243 }
55497cff
PP
244 ;
245
246mremember: /* NULL */ /* start a partial lexical scope */
34b54951
FC
247 { $$ = block_start(FALSE);
248 parser->parsed_sub = 0; }
8d063cd8
LW
249 ;
250
eae48c89 251/* A sequence of statements in the program */
5f211341 252stmtseq : /* NULL */
a9f5ab8d 253 { $$ = NULL; }
53443c95
BZ
254 | stmtseq[list] fullstmt
255 { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt);
3280af22 256 PL_pad_reset_pending = TRUE;
53443c95 257 if ($list && $fullstmt)
503de470
DM
258 PL_hints |= HINT_BLOCK_SCOPE;
259 }
8d063cd8
LW
260 ;
261
705fe0e5
FC
262/* A sequence of format lines */
263formstmtseq: /* NULL */
a9f5ab8d 264 { $$ = NULL; }
53443c95
BZ
265 | formstmtseq[list] formline
266 { $$ = op_append_list(OP_LINESEQ, $list, $formline);
705fe0e5 267 PL_pad_reset_pending = TRUE;
53443c95 268 if ($list && $formline)
705fe0e5
FC
269 PL_hints |= HINT_BLOCK_SCOPE;
270 }
271 ;
272
8e720305
Z
273/* A statement in the program, including optional labels */
274fullstmt: barestmt
eae48c89 275 {
53443c95 276 $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL;
eae48c89 277 }
8e720305 278 | labfullstmt
53443c95 279 { $$ = $labfullstmt; }
8e720305
Z
280 ;
281
282labfullstmt: LABEL barestmt
283 {
53443c95 284 SV *label = cSVOPx_sv($LABEL);
01719201 285 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
53443c95
BZ
286 savepv(SvPVX_const(label)), $barestmt);
287 op_free($LABEL);
8e720305 288 }
53443c95 289 | LABEL labfullstmt[list]
8e720305 290 {
53443c95 291 SV *label = cSVOPx_sv($LABEL);
01719201 292 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
53443c95
BZ
293 savepv(SvPVX_const(label)), $list);
294 op_free($LABEL);
8e720305 295 }
eae48c89
Z
296 ;
297
298/* A bare statement, lacking label and other aspects of state op */
299barestmt: PLUGSTMT
53443c95 300 { $$ = $PLUGSTMT; }
7c70caa5 301 | FORMAT startformsub formname formblock
f05e27e5 302 {
eae48c89 303 CV *fmtcv = PL_compcv;
53443c95 304 newFORM($startformsub, $formname, $formblock);
a9f5ab8d 305 $$ = NULL;
4a273b91 306 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
74a9453a 307 pad_add_weakref(fmtcv);
f05e27e5 308 }
8b9fb2f9 309 parser->parsed_sub = 1;
eae48c89 310 }
50278755 311 | SUB subname startsub
75230cc1
DM
312 /* sub declaration or definition not within scope
313 of 'use feature "signatures"'*/
50278755 314 {
53443c95 315 init_named_cv(PL_compcv, $subname);
624fa8bd
FC
316 parser->in_my = 0;
317 parser->in_my_stash = NULL;
764212cf 318 }
75230cc1 319 proto subattrlist optsubbody
eae48c89
Z
320 {
321 SvREFCNT_inc_simple_void(PL_compcv);
53443c95
BZ
322 $subname->op_type == OP_CONST
323 ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
324 : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
50278755 325 ;
a9f5ab8d 326 $$ = NULL;
764212cf 327 intro_my();
34b54951 328 parser->parsed_sub = 1;
f05e27e5 329 }
436ddf68 330 | SIGSUB subname startsub
75230cc1
DM
331 /* sub declaration or definition under 'use feature
332 * "signatures"'. (Note that a signature isn't
333 * allowed in a declaration)
334 */
436ddf68 335 {
53443c95 336 init_named_cv(PL_compcv, $subname);
436ddf68
DM
337 parser->in_my = 0;
338 parser->in_my_stash = NULL;
339 }
75230cc1 340 subattrlist optsigsubbody
436ddf68
DM
341 {
342 SvREFCNT_inc_simple_void(PL_compcv);
53443c95
BZ
343 $subname->op_type == OP_CONST
344 ? newATTRSUB($startsub, $subname, NULL, $subattrlist, $optsigsubbody)
345 : newMYSUB( $startsub, $subname, NULL, $subattrlist, $optsigsubbody)
436ddf68
DM
346 ;
347 $$ = NULL;
348 intro_my();
349 parser->parsed_sub = 1;
350 }
5adeeefb 351 | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_SEMICOLON
5f211341 352 {
53443c95
BZ
353 package($package);
354 if ($version)
355 package_version($version);
a9f5ab8d 356 $$ = NULL;
eae48c89
Z
357 }
358 | USE startsub
359 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
5adeeefb 360 BAREWORD[version] BAREWORD[module] optlistexpr PERLY_SEMICOLON
eae48c89
Z
361 {
362 SvREFCNT_inc_simple_void(PL_compcv);
53443c95 363 utilize($USE, $startsub, $version, $module, $optlistexpr);
34b54951 364 parser->parsed_sub = 1;
a9f5ab8d 365 $$ = NULL;
eae48c89 366 }
04884b68 367 | IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
eae48c89 368 {
53443c95
BZ
369 $$ = block_end($remember,
370 newCONDOP(0, $mexpr, op_scope($mblock), $else));
371 parser->copline = (line_t)$IF;
eae48c89 372 }
04884b68 373 | UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
eae48c89 374 {
53443c95
BZ
375 $$ = block_end($remember,
376 newCONDOP(0, $mexpr, $else, op_scope($mblock)));
377 parser->copline = (line_t)$UNLESS;
eae48c89 378 }
04884b68 379 | GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
eae48c89 380 {
53443c95
BZ
381 $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0));
382 parser->copline = (line_t)$GIVEN;
eae48c89 383 }
04884b68 384 | WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
53443c95 385 { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); }
7896dde7 386 | DEFAULT block
53443c95 387 { $$ = newWHENOP(0, op_scope($block)); }
04884b68 388 | WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont
eae48c89 389 {
53443c95 390 $$ = block_end($remember,
a9f5ab8d 391 newWHILEOP(0, 1, NULL,
53443c95
BZ
392 $texpr, $mblock, $cont, $mintro));
393 parser->copline = (line_t)$WHILE;
eae48c89 394 }
04884b68 395 | UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont
eae48c89 396 {
53443c95 397 $$ = block_end($remember,
a9f5ab8d 398 newWHILEOP(0, 1, NULL,
53443c95
BZ
399 $iexpr, $mblock, $cont, $mintro));
400 parser->copline = (line_t)$UNTIL;
eae48c89 401 }
ee67f254 402 | FOR PERLY_PAREN_OPEN remember mnexpr[init_mnexpr] PERLY_SEMICOLON
2d0e3c96 403 { parser->expect = XTERM; }
5adeeefb 404 texpr PERLY_SEMICOLON
2d0e3c96 405 { parser->expect = XTERM; }
04884b68 406 mintro mnexpr[iterate_mnexpr] PERLY_PAREN_CLOSE
eae48c89
Z
407 mblock
408 {
53443c95 409 OP *initop = $init_mnexpr;
a9f5ab8d 410 OP *forop = newWHILEOP(0, 1, NULL,
53443c95 411 scalar($texpr), $mblock, $iterate_mnexpr, $mintro);
eae48c89
Z
412 if (initop) {
413 forop = op_prepend_elem(OP_LINESEQ, initop,
414 op_append_elem(OP_LINESEQ,
415 newOP(OP_UNSTACK, OPf_SPECIAL),
416 forop));
5f211341 417 }
0f602692 418 PL_hints |= HINT_BLOCK_SCOPE;
53443c95
BZ
419 $$ = block_end($remember, forop);
420 parser->copline = (line_t)$FOR;
eae48c89 421 }
04884b68 422 | FOR MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
eae48c89 423 {
53443c95
BZ
424 $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont));
425 parser->copline = (line_t)$FOR;
eae48c89 426 }
04884b68 427 | FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
eae48c89 428 {
53443c95
BZ
429 $$ = block_end($remember, newFOROP(0,
430 op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont));
431 parser->copline = (line_t)$FOR;
eae48c89 432 }
e118fea3 433 | FOR my_refgen remember my_var
53443c95 434 { parser->in_my = 0; $<opval>$ = my($my_var); }[variable]
04884b68 435 PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
d39c26a6
FC
436 {
437 $$ = block_end(
53443c95 438 $remember,
d39c26a6
FC
439 newFOROP(0,
440 op_lvalue(
441 newUNOP(OP_REFGEN, 0,
53443c95 442 $<opval>variable),
d39c26a6 443 OP_ENTERLOOP),
53443c95 444 $mexpr, $mblock, $cont)
d39c26a6 445 );
53443c95 446 parser->copline = (line_t)$FOR;
d39c26a6 447 }
04884b68 448 | FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
d39c26a6 449 {
53443c95 450 $$ = block_end($remember, newFOROP(
d39c26a6 451 0, op_lvalue(newUNOP(OP_REFGEN, 0,
53443c95
BZ
452 $refgen_topic),
453 OP_ENTERLOOP), $mexpr, $mblock, $cont));
454 parser->copline = (line_t)$FOR;
d39c26a6 455 }
04884b68 456 | FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
eae48c89 457 {
53443c95
BZ
458 $$ = block_end($remember,
459 newFOROP(0, NULL, $mexpr, $mblock, $cont));
460 parser->copline = (line_t)$FOR;
eae48c89
Z
461 }
462 | block cont
463 {
464 /* a block is a loop that happens once */
a9f5ab8d 465 $$ = newWHILEOP(0, 1, NULL,
53443c95 466 NULL, $block, $cont, 0);
eae48c89 467 }
c588171e 468 | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember
eae48c89 469 {
53443c95
BZ
470 package($package);
471 if ($version) {
472 package_version($version);
eae48c89
Z
473 }
474 }
d0a6a9c7 475 stmtseq PERLY_BRACE_CLOSE
eae48c89
Z
476 {
477 /* a block is a loop that happens once */
a9f5ab8d 478 $$ = newWHILEOP(0, 1, NULL,
53443c95 479 NULL, block_end($remember, $stmtseq), NULL, 0);
c588171e
BZ
480 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
481 parser->copline = (line_t)$PERLY_BRACE_OPEN;
eae48c89 482 }
5adeeefb 483 | sideff PERLY_SEMICOLON
eae48c89 484 {
53443c95 485 $$ = $sideff;
eae48c89 486 }
5adeeefb 487 | YADAYADA PERLY_SEMICOLON
29d69c3c
Z
488 {
489 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
490 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
491 }
5adeeefb 492 | PERLY_SEMICOLON
eae48c89 493 {
a9f5ab8d 494 $$ = NULL;
624fa8bd 495 parser->copline = NOLINE;
5f211341 496 }
8d063cd8
LW
497 ;
498
705fe0e5
FC
499/* Format line */
500formline: THING formarg
501 { OP *list;
53443c95
BZ
502 if ($formarg) {
503 OP *term = $formarg;
504 list = op_append_elem(OP_LIST, $THING, term);
705fe0e5
FC
505 }
506 else {
53443c95 507 list = $THING;
705fe0e5 508 }
624fa8bd
FC
509 if (parser->copline == NOLINE)
510 parser->copline = CopLINE(PL_curcop)-1;
511 else parser->copline--;
705fe0e5 512 $$ = newSTATEOP(0, NULL,
03d05f6e 513 op_convert_list(OP_FORMLINE, 0, list));
705fe0e5
FC
514 }
515 ;
516
517formarg : /* NULL */
518 { $$ = NULL; }
519 | FORMLBRACK stmtseq FORMRBRACK
53443c95 520 { $$ = op_unscope($stmtseq); }
705fe0e5
FC
521 ;
522
53443c95
BZ
523condition: expr
524;
525
891be019 526/* An expression which may have a side-effect */
a687059c 527sideff : error
a9f5ab8d 528 { $$ = NULL; }
53443c95
BZ
529 | expr[body]
530 { $$ = $body; }
531 | expr[body] IF condition
532 { $$ = newLOGOP(OP_AND, 0, $condition, $body); }
533 | expr[body] UNLESS condition
534 { $$ = newLOGOP(OP_OR, 0, $condition, $body); }
535 | expr[body] WHILE condition
536 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); }
537 | expr[body] UNTIL iexpr
538 { $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); }
539 | expr[body] FOR condition
540 { $$ = newFOROP(0, NULL, $condition, $body, NULL);
541 parser->copline = (line_t)$FOR; }
542 | expr[body] WHEN condition
543 { $$ = newWHENOP($condition, op_scope($body)); }
79072805
LW
544 ;
545
891be019 546/* else and elsif blocks */
79072805 547else : /* NULL */
a9f5ab8d 548 { $$ = NULL; }
55497cff 549 | ELSE mblock
3ad73efd 550 {
53443c95
BZ
551 ($mblock)->op_flags |= OPf_PARENS;
552 $$ = op_scope($mblock);
f05e27e5 553 }
04884b68 554 | ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else[else.recurse]
53443c95 555 { parser->copline = (line_t)$ELSIF;
3ad73efd 556 $$ = newCONDOP(0,
53443c95
BZ
557 newSTATEOP(OPf_SPECIAL,NULL,$mexpr),
558 op_scope($mblock), $[else.recurse]);
3ad73efd 559 PL_hints |= HINT_BLOCK_SCOPE;
f05e27e5 560 }
79072805
LW
561 ;
562
891be019 563/* Continue blocks */
79072805 564cont : /* NULL */
a9f5ab8d 565 { $$ = NULL; }
79072805 566 | CONTINUE block
53443c95 567 { $$ = op_scope($block); }
79072805
LW
568 ;
569
a034e688
DM
570/* determine whether there are any new my declarations */
571mintro : /* NULL */
572 { $$ = (PL_min_intro_pending &&
573 PL_max_intro_pending >= PL_min_intro_pending);
574 intro_my(); }
575
891be019 576/* Normal expression */
8d063cd8 577nexpr : /* NULL */
a9f5ab8d 578 { $$ = NULL; }
8d063cd8
LW
579 | sideff
580 ;
581
891be019 582/* Boolean expression */
8d063cd8 583texpr : /* NULL means true */
f05e27e5
DM
584 { YYSTYPE tmplval;
585 (void)scan_num("1", &tmplval);
586 $$ = tmplval.opval; }
8d063cd8
LW
587 | expr
588 ;
589
891be019 590/* Inverted boolean expression */
55497cff 591iexpr : expr
53443c95 592 { $$ = invert(scalar($expr)); }
55497cff
PP
593 ;
594
891be019 595/* Expression with its own lexical scope */
55497cff 596mexpr : expr
53443c95 597 { $$ = $expr; intro_my(); }
bbce6d69
PP
598 ;
599
600mnexpr : nexpr
53443c95 601 { $$ = $nexpr; intro_my(); }
55497cff
PP
602 ;
603
53443c95 604formname: BAREWORD { $$ = $BAREWORD; }
a9f5ab8d 605 | /* NULL */ { $$ = NULL; }
8d063cd8
LW
606 ;
607
fa83b5b6 608startsub: /* NULL */ /* start a regular subroutine scope */
a8ff2fa6
DM
609 { $$ = start_subparse(FALSE, 0);
610 SAVEFREESV(PL_compcv); }
f05e27e5 611
28757baa
PP
612 ;
613
614startanonsub: /* NULL */ /* start an anonymous subroutine scope */
a8ff2fa6
DM
615 { $$ = start_subparse(FALSE, CVf_ANON);
616 SAVEFREESV(PL_compcv); }
28757baa
PP
617 ;
618
44a8e56a 619startformsub: /* NULL */ /* start a format subroutine scope */
a8ff2fa6
DM
620 { $$ = start_subparse(TRUE, 0);
621 SAVEFREESV(PL_compcv); }
44a8e56a
PP
622 ;
623
891be019 624/* Name of a subroutine - must be a bareword, could be special */
185c2e96 625subname : BAREWORD
4210d3f1 626 | PRIVATEREF
a0d0e21e
LW
627 ;
628
891be019 629/* Subroutine prototype */
4633a7c4 630proto : /* NULL */
a9f5ab8d 631 { $$ = NULL; }
4633a7c4
LW
632 | THING
633 ;
28757baa 634
891be019 635/* Optional list of subroutine attributes */
09bef843 636subattrlist: /* NULL */
a9f5ab8d 637 { $$ = NULL; }
09bef843 638 | COLONATTR THING
53443c95 639 { $$ = $THING; }
09bef843 640 | COLONATTR
a9f5ab8d 641 { $$ = NULL; }
09bef843
SB
642 ;
643
891be019 644/* List of attributes for a "my" variable declaration */
09bef843 645myattrlist: COLONATTR THING
53443c95 646 { $$ = $THING; }
09bef843 647 | COLONATTR
a9f5ab8d 648 { $$ = NULL; }
09bef843
SB
649 ;
650
abcf453d 651
d3d9da4a
DM
652
653/* --------------------------------------
654 * subroutine signature parsing
655 */
656
657/* the '' or 'foo' part of a '$' or '@foo' etc signature variable */
49fb8620 658sigvarname: /* NULL */
a9f5ab8d 659 { parser->in_my = 0; $$ = NULL; }
d3d9da4a 660 | PRIVATEREF
53443c95 661 { parser->in_my = 0; $$ = $PRIVATEREF; }
d3d9da4a
DM
662 ;
663
664sigslurpsigil:
9086c946 665 PERLY_SNAIL
d3d9da4a 666 { $$ = '@'; }
0ba95c59 667 | PERLY_PERCENT_SIGN
d3d9da4a
DM
668 { $$ = '%'; }
669
670/* @, %, @foo, %foo */
671sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
672 {
53443c95
BZ
673 I32 sigil = $sigslurpsigil;
674 OP *var = $sigvarname;
675 OP *defexpr = $sigdefault;
d3d9da4a 676
036bbc13 677 if (parser->sig_slurpy)
d3d9da4a 678 yyerror("Multiple slurpy parameters not allowed");
036bbc13 679 parser->sig_slurpy = (char)sigil;
d3d9da4a
DM
680
681 if (defexpr)
bb6b75cd 682 yyerror("A slurpy parameter may not have "
d3d9da4a
DM
683 "a default value");
684
a9f5ab8d 685 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
d3d9da4a
DM
686 }
687 ;
688
689/* default part of sub signature scalar element: i.e. '= default_expr' */
690sigdefault: /* NULL */
a9f5ab8d 691 { $$ = NULL; }
d3d9da4a
DM
692 | ASSIGNOP
693 { $$ = newOP(OP_NULL, 0); }
694 | ASSIGNOP term
53443c95 695 { $$ = $term; }
d3d9da4a
DM
696
697
698/* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
699sigscalarelem:
bfa838cc 700 PERLY_DOLLAR sigvarname sigdefault
d3d9da4a 701 {
53443c95
BZ
702 OP *var = $sigvarname;
703 OP *defexpr = $sigdefault;
d3d9da4a 704
036bbc13 705 if (parser->sig_slurpy)
d3d9da4a
DM
706 yyerror("Slurpy parameter not last");
707
036bbc13 708 parser->sig_elems++;
d3d9da4a 709
d3d9da4a 710 if (defexpr) {
036bbc13 711 parser->sig_optelems++;
4fa06845
DM
712
713 if ( defexpr->op_type == OP_NULL
d3d9da4a
DM
714 && !(defexpr->op_flags & OPf_KIDS))
715 {
4fa06845
DM
716 /* handle '$=' special case */
717 if (var)
718 yyerror("Optional parameter "
719 "lacks default expression");
d3d9da4a
DM
720 op_free(defexpr);
721 }
4fa06845
DM
722 else {
723 /* a normal '=default' expression */
724 OP *defop = (OP*)alloc_LOGOP(OP_ARGDEFELEM,
725 defexpr,
726 LINKLIST(defexpr));
727 /* re-purpose op_targ to hold @_ index */
6daeaaa3 728 defop->op_targ =
036bbc13 729 (PADOFFSET)(parser->sig_elems - 1);
4fa06845
DM
730
731 if (var) {
732 var->op_flags |= OPf_STACKED;
733 (void)op_sibling_splice(var,
734 NULL, 0, defop);
735 scalar(defop);
736 }
737 else
738 var = newUNOP(OP_NULL, 0, defop);
739
740 LINKLIST(var);
741 /* NB: normally the first child of a
742 * logop is executed before the logop,
743 * and it pushes a boolean result
744 * ready for the logop. For ARGDEFELEM,
745 * the op itself does the boolean
746 * calculation, so set the first op to
747 * it instead.
748 */
749 var->op_next = defop;
750 defexpr->op_next = var;
d3d9da4a
DM
751 }
752 }
753 else {
036bbc13 754 if (parser->sig_optelems)
d3d9da4a
DM
755 yyerror("Mandatory parameter "
756 "follows optional parameter");
d3d9da4a
DM
757 }
758
a9f5ab8d 759 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
d3d9da4a
DM
760 }
761 ;
762
763
764/* subroutine signature element: e.g. '$x = $default' or '%h' */
765sigelem: sigscalarelem
53443c95 766 { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; }
d3d9da4a 767 | sigslurpelem
53443c95 768 { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; }
d3d9da4a
DM
769 ;
770
771/* list of subroutine signature elements */
772siglist:
581f9a7a 773 siglist[list] PERLY_COMMA
53443c95 774 { $$ = $list; }
581f9a7a 775 | siglist[list] PERLY_COMMA sigelem[element]
30d9c59b 776 {
53443c95 777 $$ = op_append_list(OP_LINESEQ, $list, $element);
30d9c59b 778 }
53443c95
BZ
779 | sigelem[element] %prec PREC_LOW
780 { $$ = $element; }
30d9c59b
Z
781 ;
782
d3d9da4a
DM
783/* () or (....) */
784siglistornull: /* NULL */
a9f5ab8d 785 { $$ = NULL; }
d3d9da4a 786 | siglist
53443c95 787 { $$ = $siglist; }
d3d9da4a 788
75230cc1
DM
789/* optional subroutine signature */
790optsubsignature: /* NULL */
791 { $$ = NULL; }
792 | subsignature
53443c95 793 { $$ = $subsignature; }
75230cc1 794
d3d9da4a 795/* Subroutine signature */
04884b68 796subsignature: PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE
53443c95 797 { $$ = $subsigguts; }
996b0cb8
PLE
798
799subsigguts:
d3d9da4a
DM
800 {
801 ENTER;
036bbc13
FC
802 SAVEIV(parser->sig_elems);
803 SAVEIV(parser->sig_optelems);
804 SAVEI8(parser->sig_slurpy);
805 parser->sig_elems = 0;
806 parser->sig_optelems = 0;
807 parser->sig_slurpy = 0;
49fb8620 808 parser->in_my = KEY_sigvar;
d3d9da4a
DM
809 }
810 siglistornull
d3d9da4a 811 {
53443c95 812 OP *sigops = $siglistornull;
f417cfa9 813 struct op_argcheck_aux *aux;
4fa06845 814 OP *check;
d3d9da4a 815
894f226e
DM
816 if (!FEATURE_SIGNATURES_IS_ENABLED)
817 Perl_croak(aTHX_ "Experimental "
818 "subroutine signatures not enabled");
d3d9da4a
DM
819
820 /* We shouldn't get here otherwise */
821 Perl_ck_warner_d(aTHX_
822 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
823 "The signatures feature is experimental");
824
f417cfa9
DM
825 aux = (struct op_argcheck_aux*)
826 PerlMemShared_malloc(
827 sizeof(struct op_argcheck_aux));
828 aux->params = parser->sig_elems;
829 aux->opt_params = parser->sig_optelems;
830 aux->slurpy = parser->sig_slurpy;
831 check = newUNOP_AUX(OP_ARGCHECK, 0, NULL,
832 (UNOP_AUX_item *)aux);
4fa06845
DM
833 sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
834 sigops = op_prepend_elem(OP_LINESEQ,
835 newSTATEOP(0, NULL, NULL),
836 sigops);
837 /* a nextstate at the end handles context
838 * correctly for an empty sub body */
4df85778 839 sigops = op_append_elem(OP_LINESEQ,
4fa06845
DM
840 sigops,
841 newSTATEOP(0, NULL, NULL));
4df85778
DM
842 /* wrap the list of arg ops in a NULL aux op.
843 This serves two purposes. First, it makes
844 the arg list a separate subtree from the
845 body of the sub, and secondly the null op
846 may in future be upgraded to an OP_SIGNATURE
847 when implemented. For now leave it as
848 ex-argcheck */
849 $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL);
850 op_null($$);
d3d9da4a 851
49fb8620 852 parser->in_my = 0;
a8c56356
DM
853 /* tell the toker that attrributes can follow
854 * this sig, but only so that the toker
855 * can skip through any (illegal) trailing
856 * attribute text then give a useful error
857 * message about "attributes before sig",
858 * rather than falling over ina mess at
859 * unrecognised syntax.
860 */
861 parser->expect = XATTRBLOCK;
862 parser->sig_seen = TRUE;
d3d9da4a
DM
863 LEAVE;
864 }
865 ;
866
75230cc1 867/* Optional subroutine body (for named subroutine declaration) */
53443c95 868optsubbody: subbody { $$ = $subbody; }
5adeeefb 869 | PERLY_SEMICOLON { $$ = NULL; }
75230cc1
DM
870 ;
871
872
873/* Subroutine body (without signature) */
d0a6a9c7 874subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
75230cc1 875 {
c588171e
BZ
876 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
877 parser->copline = (line_t)$PERLY_BRACE_OPEN;
53443c95 878 $$ = block_end($remember, $stmtseq);
75230cc1
DM
879 }
880 ;
881
882
883/* optional [ Subroutine body with optional signature ] (for named
884 * subroutine declaration) */
53443c95 885optsigsubbody: sigsubbody { $$ = $sigsubbody; }
5adeeefb 886 | PERLY_SEMICOLON { $$ = NULL; }
d3d9da4a 887
75230cc1 888/* Subroutine body with optional signature */
d0a6a9c7 889sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
894f226e 890 {
c588171e
BZ
891 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
892 parser->copline = (line_t)$PERLY_BRACE_OPEN;
53443c95
BZ
893 $$ = block_end($remember,
894 op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq));
894f226e
DM
895 }
896 ;
897
d3d9da4a 898
891be019 899/* Ordinary expressions; logical combinations */
53443c95
BZ
900expr : expr[lhs] ANDOP expr[rhs]
901 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
902 | expr[lhs] OROP[operator] expr[rhs]
903 { $$ = newLOGOP($operator, 0, $lhs, $rhs); }
904 | expr[lhs] DOROP expr[rhs]
905 { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
09b1cffe 906 | listexpr %prec PREC_LOW
a0d0e21e
LW
907 ;
908
891be019 909/* Expressions are a list of terms joined by commas */
581f9a7a 910listexpr: listexpr[list] PERLY_COMMA
53443c95 911 { $$ = $list; }
581f9a7a 912 | listexpr[list] PERLY_COMMA term
abcf453d 913 {
53443c95
BZ
914 OP* term = $term;
915 $$ = op_append_elem(OP_LIST, $list, term);
f05e27e5 916 }
fad39ff1 917 | term %prec PREC_LOW
8d063cd8
LW
918 ;
919
891be019 920/* List operators */
09b1cffe 921listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
53443c95
BZ
922 { $$ = op_convert_list($LSTOP, OPf_STACKED,
923 op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) );
f05e27e5 924 }
04884b68 925 | FUNC PERLY_PAREN_OPEN indirob expr PERLY_PAREN_CLOSE /* print ($fh @args */
53443c95
BZ
926 { $$ = op_convert_list($FUNC, OPf_STACKED,
927 op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) );
f05e27e5 928 }
04884b68 929 | term ARROW method PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* $foo->bar(list) */
03d05f6e 930 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757 931 op_append_elem(OP_LIST,
53443c95
BZ
932 op_prepend_elem(OP_LIST, scalar($term), $optexpr),
933 newMETHOP(OP_METHOD, 0, $method)));
f05e27e5 934 }
891be019 935 | term ARROW method /* $foo->bar */
03d05f6e 936 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
53443c95
BZ
937 op_append_elem(OP_LIST, scalar($term),
938 newMETHOP(OP_METHOD, 0, $method)));
f05e27e5 939 }
09b1cffe 940 | METHOD indirob optlistexpr /* new Class @args */
03d05f6e 941 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757 942 op_append_elem(OP_LIST,
53443c95
BZ
943 op_prepend_elem(OP_LIST, $indirob, $optlistexpr),
944 newMETHOP(OP_METHOD, 0, $METHOD)));
f05e27e5 945 }
04884b68 946 | FUNCMETH indirob PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* method $object (@args) */
03d05f6e 947 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757 948 op_append_elem(OP_LIST,
53443c95
BZ
949 op_prepend_elem(OP_LIST, $indirob, $optexpr),
950 newMETHOP(OP_METHOD, 0, $FUNCMETH)));
f05e27e5 951 }
09b1cffe 952 | LSTOP optlistexpr /* print @args */
53443c95 953 { $$ = op_convert_list($LSTOP, 0, $optlistexpr); }
04884b68 954 | FUNC PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* print (@args) */
53443c95 955 { $$ = op_convert_list($FUNC, 0, $optexpr); }
69afcc21 956 | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */
53443c95 957 { $$ = op_convert_list($FUNC, 0, $optexpr); }
718a7425 958 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
5a5094bd 959 { SvREFCNT_inc_simple_void(PL_compcv);
53443c95 960 $<opval>$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub]
09b1cffe 961 optlistexpr %prec LSTOP /* ... @bar */
4633a7c4 962 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 963 op_append_elem(OP_LIST,
53443c95 964 op_prepend_elem(OP_LIST, $<opval>anonattrsub, $optlistexpr), $LSTOPSUB));
f05e27e5 965 }
a687059c
LW
966 ;
967
891be019 968/* Names of methods. May use $object->$methodname */
a0d0e21e
LW
969method : METHOD
970 | scalar
971 ;
972
891be019 973/* Some kind of subscripted expression */
5adeeefb
BZ
974subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* *main::{something} */
975 /* In this and all the hash accessors, PERLY_SEMICOLON is
891be019 976 * provided by the tokeniser */
53443c95 977 { $$ = newBINOP(OP_GELEM, 0, $gelem, scalar($expr)); }
fceeeb77 978 | scalar[array] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $array[$element] */
53443c95 979 { $$ = newBINOP(OP_AELEM, 0, oopsAV($array), scalar($expr));
f05e27e5 980 }
fceeeb77 981 | term[array_reference] ARROW PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* somearef->[$element] */
fad39ff1 982 { $$ = newBINOP(OP_AELEM, 0,
53443c95
BZ
983 ref(newAVREF($array_reference),OP_RV2AV),
984 scalar($expr));
f05e27e5 985 }
fceeeb77 986 | subscripted[array_reference] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $foo->[$bar]->[$baz] */
fad39ff1 987 { $$ = newBINOP(OP_AELEM, 0,
53443c95
BZ
988 ref(newAVREF($array_reference),OP_RV2AV),
989 scalar($expr));
f05e27e5 990 }
5adeeefb 991 | scalar[hash] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo{bar();} */
53443c95 992 { $$ = newBINOP(OP_HELEM, 0, oopsHV($hash), jmaybe($expr));
f05e27e5 993 }
5adeeefb 994 | term[hash_reference] ARROW PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* somehref->{bar();} */
fad39ff1 995 { $$ = newBINOP(OP_HELEM, 0,
53443c95
BZ
996 ref(newHVREF($hash_reference),OP_RV2HV),
997 jmaybe($expr)); }
5adeeefb 998 | subscripted[hash_reference] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo->[bar]->{baz;} */
fad39ff1 999 { $$ = newBINOP(OP_HELEM, 0,
53443c95
BZ
1000 ref(newHVREF($hash_reference),OP_RV2HV),
1001 jmaybe($expr)); }
04884b68 1002 | term[code_reference] ARROW PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $subref->() */
fad39ff1 1003 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
53443c95 1004 newCVREF(0, scalar($code_reference)));
097ff42c
Z
1005 if (parser->expect == XBLOCK)
1006 parser->expect = XOPERATOR;
1007 }
04884b68 1008 | term[code_reference] ARROW PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $subref->(@args) */
fad39ff1 1009 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
53443c95
BZ
1010 op_append_elem(OP_LIST, $expr,
1011 newCVREF(0, scalar($code_reference))));
097ff42c
Z
1012 if (parser->expect == XBLOCK)
1013 parser->expect = XOPERATOR;
1014 }
fad39ff1 1015
04884b68 1016 | subscripted[code_reference] PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $foo->{bar}->(@args) */
fad39ff1 1017 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
53443c95
BZ
1018 op_append_elem(OP_LIST, $expr,
1019 newCVREF(0, scalar($code_reference))));
097ff42c
Z
1020 if (parser->expect == XBLOCK)
1021 parser->expect = XOPERATOR;
1022 }
04884b68 1023 | subscripted[code_reference] PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $foo->{bar}->() */
fad39ff1 1024 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
53443c95 1025 newCVREF(0, scalar($code_reference)));
097ff42c
Z
1026 if (parser->expect == XBLOCK)
1027 parser->expect = XOPERATOR;
1028 }
04884b68 1029 | PERLY_PAREN_OPEN expr[list] PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE /* list slice */
53443c95 1030 { $$ = newSLICEOP(0, $slice, $list); }
fceeeb77 1031 | QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* list literal slice */
53443c95 1032 { $$ = newSLICEOP(0, $expr, $QWLIST); }
04884b68 1033 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* empty list slice! */
53443c95 1034 { $$ = newSLICEOP(0, $expr, NULL); }
891be019 1035 ;
fad39ff1 1036
891be019 1037/* Binary operators between terms */
53443c95
BZ
1038termbinop: term[lhs] ASSIGNOP term[rhs] /* $x = $y, $x += $y */
1039 { $$ = newASSIGNOP(OPf_STACKED, $lhs, $ASSIGNOP, $rhs); }
1040 | term[lhs] POWOP term[rhs] /* $x ** $y */
1041 { $$ = newBINOP($POWOP, 0, scalar($lhs), scalar($rhs)); }
1042 | term[lhs] MULOP term[rhs] /* $x * $y, $x x $y */
1043 { if ($MULOP != OP_REPEAT)
1044 scalar($lhs);
1045 $$ = newBINOP($MULOP, 0, $lhs, scalar($rhs));
1046 }
1047 | term[lhs] ADDOP term[rhs] /* $x + $y */
1048 { $$ = newBINOP($ADDOP, 0, scalar($lhs), scalar($rhs)); }
1049 | term[lhs] SHIFTOP term[rhs] /* $x >> $y, $x << $y */
1050 { $$ = newBINOP($SHIFTOP, 0, scalar($lhs), scalar($rhs)); }
02b85d3d 1051 | termrelop %prec PREC_LOW /* $x > $y, etc. */
53443c95 1052 { $$ = $termrelop; }
02b85d3d 1053 | termeqop %prec PREC_LOW /* $x == $y, $x cmp $y */
53443c95
BZ
1054 { $$ = $termeqop; }
1055 | term[lhs] BITANDOP term[rhs] /* $x & $y */
1056 { $$ = newBINOP($BITANDOP, 0, scalar($lhs), scalar($rhs)); }
1057 | term[lhs] BITOROP term[rhs] /* $x | $y */
1058 { $$ = newBINOP($BITOROP, 0, scalar($lhs), scalar($rhs)); }
1059 | term[lhs] DOTDOT term[rhs] /* $x..$y, $x...$y */
1060 { $$ = newRANGE($DOTDOT, scalar($lhs), scalar($rhs)); }
1061 | term[lhs] ANDAND term[rhs] /* $x && $y */
1062 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
1063 | term[lhs] OROR term[rhs] /* $x || $y */
1064 { $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); }
1065 | term[lhs] DORDOR term[rhs] /* $x // $y */
1066 { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
1067 | term[lhs] MATCHOP term[rhs] /* $x =~ /$y/ */
1068 { $$ = bind_match($MATCHOP, $lhs, $rhs); }
891be019 1069 ;
8d063cd8 1070
02b85d3d 1071termrelop: relopchain %prec PREC_LOW
53443c95
BZ
1072 { $$ = cmpchain_finish($relopchain); }
1073 | term[lhs] NCRELOP term[rhs]
1074 { $$ = newBINOP($NCRELOP, 0, scalar($lhs), scalar($rhs)); }
02b85d3d
Z
1075 | termrelop NCRELOP
1076 { yyerror("syntax error"); YYERROR; }
1077 | termrelop CHRELOP
1078 { yyerror("syntax error"); YYERROR; }
1079 ;
1080
53443c95
BZ
1081relopchain: term[lhs] CHRELOP term[rhs]
1082 { $$ = cmpchain_start($CHRELOP, $lhs, $rhs); }
1083 | relopchain[lhs] CHRELOP term[rhs]
1084 { $$ = cmpchain_extend($CHRELOP, $lhs, $rhs); }
02b85d3d
Z
1085 ;
1086
1087termeqop: eqopchain %prec PREC_LOW
53443c95
BZ
1088 { $$ = cmpchain_finish($eqopchain); }
1089 | term[lhs] NCEQOP term[rhs]
1090 { $$ = newBINOP($NCEQOP, 0, scalar($lhs), scalar($rhs)); }
02b85d3d
Z
1091 | termeqop NCEQOP
1092 { yyerror("syntax error"); YYERROR; }
1093 | termeqop CHEQOP
1094 { yyerror("syntax error"); YYERROR; }
1095 ;
1096
53443c95
BZ
1097eqopchain: term[lhs] CHEQOP term[rhs]
1098 { $$ = cmpchain_start($CHEQOP, $lhs, $rhs); }
1099 | eqopchain[lhs] CHEQOP term[rhs]
1100 { $$ = cmpchain_extend($CHEQOP, $lhs, $rhs); }
02b85d3d
Z
1101 ;
1102
891be019 1103/* Unary operators and terms */
68a66a8b 1104termunop : PERLY_MINUS term %prec UMINUS /* -$x */
53443c95 1105 { $$ = newUNOP(OP_NEGATE, 0, scalar($term)); }
5776f3e5 1106 | PERLY_PLUS term %prec UMINUS /* +$x */
53443c95 1107 { $$ = $term; }
b5bbe64a 1108
1c2e9449 1109 | PERLY_EXCLAMATION_MARK term /* !$x */
53443c95 1110 { $$ = newUNOP(OP_NOT, 0, scalar($term)); }
3d92c6b8
BZ
1111 | PERLY_TILDE term /* ~$x */
1112 { $$ = newUNOP($PERLY_TILDE, 0, scalar($term)); }
891be019 1113 | term POSTINC /* $x++ */
79072805 1114 { $$ = newUNOP(OP_POSTINC, 0,
53443c95 1115 op_lvalue(scalar($term), OP_POSTINC)); }
891be019 1116 | term POSTDEC /* $x-- */
79072805 1117 { $$ = newUNOP(OP_POSTDEC, 0,
53443c95 1118 op_lvalue(scalar($term), OP_POSTDEC));}
cc624add 1119 | term POSTJOIN /* implicit join after interpolated ->@ */
03d05f6e 1120 { $$ = op_convert_list(OP_JOIN, 0,
cc624add
FC
1121 op_append_elem(
1122 OP_LIST,
1123 newSVREF(scalar(
1124 newSVOP(OP_CONST,0,
1125 newSVpvs("\""))
1126 )),
53443c95 1127 $term
cc624add 1128 ));
cc624add 1129 }
891be019 1130 | PREINC term /* ++$x */
79072805 1131 { $$ = newUNOP(OP_PREINC, 0,
53443c95 1132 op_lvalue(scalar($term), OP_PREINC)); }
891be019 1133 | PREDEC term /* --$x */
79072805 1134 { $$ = newUNOP(OP_PREDEC, 0,
53443c95 1135 op_lvalue(scalar($term), OP_PREDEC)); }
891be019
SC
1136
1137 ;
1138
1139/* Constructors for anonymous data */
fceeeb77 1140anonymous: PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE
53443c95 1141 { $$ = newANONLIST($expr); }
fceeeb77 1142 | PERLY_BRACKET_OPEN PERLY_BRACKET_CLOSE
a9f5ab8d 1143 { $$ = newANONLIST(NULL);}
ee67f254 1144 | HASHBRACK expr PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { foo => "Bar" } */
53443c95 1145 { $$ = newANONHASH($expr); }
ee67f254 1146 | HASHBRACK PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { } (PERLY_SEMICOLON by tokener) */
a9f5ab8d 1147 { $$ = newANONHASH(NULL); }
ee67f254 1148 | ANONSUB startanonsub proto subattrlist subbody %prec PERLY_PAREN_OPEN
436ddf68 1149 { SvREFCNT_inc_simple_void(PL_compcv);
53443c95 1150 $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); }
ee67f254 1151 | ANON_SIGSUB startanonsub subattrlist sigsubbody %prec PERLY_PAREN_OPEN
5a5094bd 1152 { SvREFCNT_inc_simple_void(PL_compcv);
53443c95 1153 $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); }
891be019
SC
1154 ;
1155
1156/* Things called with "do" */
1157termdo : DO term %prec UNIOP /* do $filename */
53443c95 1158 { $$ = dofile($term, $DO);}
ee67f254 1159 | DO block %prec PERLY_PAREN_OPEN /* do { code */
53443c95 1160 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));}
891be019
SC
1161 ;
1162
53443c95 1163term[product] : termbinop
891be019
SC
1164 | termunop
1165 | anonymous
1166 | termdo
a1ad62bf 1167 | term[condition] PERLY_QUESTION_MARK term[then] PERLY_COLON term[else]
53443c95
BZ
1168 { $$ = newCONDOP(0, $condition, $then, $else); }
1169 | REFGEN term[operand] /* \$x, \@y, \%z */
1170 { $$ = newUNOP(OP_REFGEN, 0, $operand); }
1171 | MY REFGEN term[operand]
1172 { $$ = newUNOP(OP_REFGEN, 0, localize($operand,1)); }
09bef843 1173 | myattrterm %prec UNIOP
53443c95
BZ
1174 { $$ = $myattrterm; }
1175 | LOCAL term[operand] %prec UNIOP
1176 { $$ = localize($operand,0); }
04884b68 1177 | PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
53443c95 1178 { $$ = sawparens($expr); }
ea25a9b2 1179 | QWLIST
53443c95 1180 { $$ = $QWLIST; }
04884b68 1181 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
b5bbe64a 1182 { $$ = sawparens(newNULLLIST()); }
ee67f254 1183 | scalar %prec PERLY_PAREN_OPEN
53443c95 1184 { $$ = $scalar; }
ee67f254 1185 | star %prec PERLY_PAREN_OPEN
53443c95 1186 { $$ = $star; }
ee67f254 1187 | hsh %prec PERLY_PAREN_OPEN
53443c95 1188 { $$ = $hsh; }
ee67f254 1189 | ary %prec PERLY_PAREN_OPEN
53443c95 1190 { $$ = $ary; }
ee67f254 1191 | arylen %prec PERLY_PAREN_OPEN /* $#x, $#{ something } */
53443c95 1192 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));}
fad39ff1 1193 | subscripted
53443c95 1194 { $$ = $subscripted; }
fceeeb77 1195 | sliceme PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array slice */
2fcb4757 1196 { $$ = op_prepend_elem(OP_ASLICE,
79072805 1197 newOP(OP_PUSHMARK, 0),
79072805 1198 newLISTOP(OP_ASLICE, 0,
53443c95
BZ
1199 list($expr),
1200 ref($sliceme, OP_ASLICE)));
1201 if ($$ && $sliceme)
429a2555 1202 $$->op_private |=
53443c95 1203 $sliceme->op_private & OPpSLICEWARNING;
f05e27e5 1204 }
fceeeb77 1205 | kvslice PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array key/value slice */
6dd3e0f2
RZ
1206 { $$ = op_prepend_elem(OP_KVASLICE,
1207 newOP(OP_PUSHMARK, 0),
1208 newLISTOP(OP_KVASLICE, 0,
53443c95
BZ
1209 list($expr),
1210 ref(oopsAV($kvslice), OP_KVASLICE)));
1211 if ($$ && $kvslice)
95a31aad 1212 $$->op_private |=
53443c95 1213 $kvslice->op_private & OPpSLICEWARNING;
6dd3e0f2 1214 }
5adeeefb 1215 | sliceme PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* @hash{@keys} */
2fcb4757 1216 { $$ = op_prepend_elem(OP_HSLICE,
79072805 1217 newOP(OP_PUSHMARK, 0),
79072805 1218 newLISTOP(OP_HSLICE, 0,
53443c95
BZ
1219 list($expr),
1220 ref(oopsHV($sliceme), OP_HSLICE)));
1221 if ($$ && $sliceme)
429a2555 1222 $$->op_private |=
53443c95 1223 $sliceme->op_private & OPpSLICEWARNING;
f05e27e5 1224 }
5adeeefb 1225 | kvslice PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* %hash{@keys} */
5cae3edb
RZ
1226 { $$ = op_prepend_elem(OP_KVHSLICE,
1227 newOP(OP_PUSHMARK, 0),
1228 newLISTOP(OP_KVHSLICE, 0,
53443c95
BZ
1229 list($expr),
1230 ref($kvslice, OP_KVHSLICE)));
1231 if ($$ && $kvslice)
95a31aad 1232 $$->op_private |=
53443c95 1233 $kvslice->op_private & OPpSLICEWARNING;
5cae3edb 1234 }
ee67f254 1235 | THING %prec PERLY_PAREN_OPEN
53443c95 1236 { $$ = $THING; }
891be019 1237 | amper /* &foo; */
53443c95 1238 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); }
04884b68 1239 | amper PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* &foo() or foo() */
53443c95 1240 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper));
f05e27e5 1241 }
04884b68 1242 | amper PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* &foo(@args) or foo(@args) */
f05e27e5
DM
1243 {
1244 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
53443c95 1245 op_append_elem(OP_LIST, $expr, scalar($amper)));
f05e27e5 1246 }
fb602e32 1247 | NOAMP subname optlistexpr /* foo @args (no parens) */
a0d0e21e 1248 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
53443c95
BZ
1249 op_append_elem(OP_LIST, $optlistexpr, scalar($subname)));
1250 }
bfa838cc 1251 | term[operand] ARROW PERLY_DOLLAR PERLY_STAR
53443c95 1252 { $$ = newSVREF($operand); }
d02b2fbf 1253 | term[operand] ARROW PERLY_SNAIL PERLY_STAR
53443c95 1254 { $$ = newAVREF($operand); }
d02b2fbf 1255 | term[operand] ARROW PERLY_PERCENT_SIGN PERLY_STAR
53443c95 1256 { $$ = newHVREF($operand); }
d02b2fbf 1257 | term[operand] ARROW PERLY_AMPERSAND PERLY_STAR
89f35911 1258 { $$ = newUNOP(OP_ENTERSUB, 0,
25a50500 1259 scalar(newCVREF($PERLY_AMPERSAND,$operand))); }
d02b2fbf 1260 | term[operand] ARROW PERLY_STAR PERLY_STAR %prec PERLY_PAREN_OPEN
53443c95 1261 { $$ = newGVREF(0,$operand); }
891be019 1262 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
53443c95 1263 { $$ = newOP($LOOPEX, OPf_SPECIAL);
b5bbe64a 1264 PL_hints |= HINT_BLOCK_SCOPE; }
53443c95
BZ
1265 | LOOPEX term[operand]
1266 { $$ = newLOOPEX($LOOPEX,$operand); }
09b1cffe 1267 | NOTOP listexpr /* not $foo */
53443c95 1268 { $$ = newUNOP(OP_NOT, 0, scalar($listexpr)); }
891be019 1269 | UNIOP /* Unary op, $_ implied */
53443c95 1270 { $$ = newOP($UNIOP, 0); }
f05e27e5 1271 | UNIOP block /* eval { foo }* */
53443c95
BZ
1272 { $$ = newUNOP($UNIOP, 0, $block); }
1273 | UNIOP term[operand] /* Unary op */
1274 { $$ = newUNOP($UNIOP, 0, $operand); }
d2fdf8fd 1275 | REQUIRE /* require, $_ implied */
53443c95
BZ
1276 { $$ = newOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0); }
1277 | REQUIRE term[operand] /* require Foo */
1278 { $$ = newUNOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0, $operand); }
3cd0a11a 1279 | UNIOPSUB
53443c95
BZ
1280 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($UNIOPSUB)); }
1281 | UNIOPSUB term[operand] /* Sub treated as unop */
4633a7c4 1282 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
53443c95 1283 op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); }
891be019 1284 | FUNC0 /* Nullary operator */
53443c95 1285 { $$ = newOP($FUNC0, 0); }
04884b68 1286 | FUNC0 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
53443c95 1287 { $$ = newOP($FUNC0, 0);}
7eb971ee 1288 | FUNC0OP /* Same as above, but op created in toke.c */
53443c95 1289 { $$ = $FUNC0OP; }
04884b68 1290 | FUNC0OP PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
53443c95 1291 { $$ = $FUNC0OP; }
891be019 1292 | FUNC0SUB /* Sub treated as nullop */
53443c95 1293 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); }
04884b68 1294 | FUNC1 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* not () */
53443c95
BZ
1295 { $$ = ($FUNC1 == OP_NOT)
1296 ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1297 : newOP($FUNC1, OPf_SPECIAL); }
04884b68 1298 | FUNC1 PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* not($foo) */
53443c95 1299 { $$ = newUNOP($FUNC1, 0, $expr); }
d63c20f2
DM
1300 | PMFUNC /* m//, s///, qr//, tr/// */
1301 {
53443c95
BZ
1302 if ( $PMFUNC->op_type != OP_TRANS
1303 && $PMFUNC->op_type != OP_TRANSR
1304 && (((PMOP*)$PMFUNC)->op_pmflags & PMf_HAS_CV))
d63c20f2
DM
1305 {
1306 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1307 SAVEFREESV(PL_compcv);
1308 } else
1309 $<ival>$ = 0;
1310 }
69afcc21 1311 SUBLEXSTART listexpr optrepl SUBLEXEND
53443c95 1312 { $$ = pmruntime($PMFUNC, $listexpr, $optrepl, 1, $<ival>2); }
185c2e96 1313 | BAREWORD
378cc40b 1314 | listop
88e1f1a2 1315 | PLUGEXPR
8d063cd8
LW
1316 ;
1317
891be019 1318/* "my" declarations, with optional attributes */
09bef843 1319myattrterm: MY myterm myattrlist
53443c95 1320 { $$ = my_attrs($myterm,$myattrlist); }
09bef843 1321 | MY myterm
53443c95 1322 { $$ = localize($myterm,1); }
e118fea3 1323 | MY REFGEN myterm myattrlist
53443c95 1324 { $$ = newUNOP(OP_REFGEN, 0, my_attrs($myterm,$myattrlist)); }
09bef843
SB
1325 ;
1326
891be019 1327/* Things that can be "my"'d */
04884b68 1328myterm : PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
53443c95 1329 { $$ = sawparens($expr); }
04884b68 1330 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
b5bbe64a
JH
1331 { $$ = sawparens(newNULLLIST()); }
1332
ee67f254 1333 | scalar %prec PERLY_PAREN_OPEN
53443c95 1334 { $$ = $scalar; }
ee67f254 1335 | hsh %prec PERLY_PAREN_OPEN
53443c95 1336 { $$ = $hsh; }
ee67f254 1337 | ary %prec PERLY_PAREN_OPEN
53443c95 1338 { $$ = $ary; }
09bef843
SB
1339 ;
1340
891be019 1341/* Basic list expressions */
09b1cffe 1342optlistexpr: /* NULL */ %prec PREC_LOW
a9f5ab8d 1343 { $$ = NULL; }
09b1cffe 1344 | listexpr %prec PREC_LOW
53443c95 1345 { $$ = $listexpr; }
a0d0e21e
LW
1346 ;
1347
09b1cffe 1348optexpr: /* NULL */
a9f5ab8d 1349 { $$ = NULL; }
79072805 1350 | expr
53443c95 1351 { $$ = $expr; }
79072805
LW
1352 ;
1353
9b6b7be8 1354optrepl: /* NULL */
a9f5ab8d 1355 { $$ = NULL; }
77b0379f 1356 | PERLY_SLASH expr
53443c95 1357 { $$ = $expr; }
9b6b7be8
FC
1358 ;
1359
891be019
SC
1360/* A little bit of trickery to make "for my $foo (@bar)" actually be
1361 lexical */
55497cff 1362my_scalar: scalar
53443c95 1363 { parser->in_my = 0; $$ = my($scalar); }
55497cff
PP
1364 ;
1365
d39c26a6
FC
1366my_var : scalar
1367 | ary
1368 | hsh
1369 ;
1370
1371refgen_topic: my_var
1372 | amper
1373 ;
1374
e118fea3
FC
1375my_refgen: MY REFGEN
1376 | REFGEN MY
1377 ;
1378
25a50500
BZ
1379amper : PERLY_AMPERSAND indirob
1380 { $$ = newCVREF($PERLY_AMPERSAND,$indirob); }
a687059c
LW
1381 ;
1382
bfa838cc 1383scalar : PERLY_DOLLAR indirob
53443c95 1384 { $$ = newSVREF($indirob); }
a687059c
LW
1385 ;
1386
9086c946 1387ary : PERLY_SNAIL indirob
53443c95 1388 { $$ = newAVREF($indirob);
9086c946 1389 if ($$) $$->op_private |= $PERLY_SNAIL;
f05e27e5 1390 }
79072805
LW
1391 ;
1392
0ba95c59 1393hsh : PERLY_PERCENT_SIGN indirob
53443c95 1394 { $$ = newHVREF($indirob);
0ba95c59 1395 if ($$) $$->op_private |= $PERLY_PERCENT_SIGN;
f05e27e5 1396 }
79072805
LW
1397 ;
1398
1399arylen : DOLSHARP indirob
53443c95 1400 { $$ = newAVREF($indirob); }
d02b2fbf 1401 | term ARROW DOLSHARP PERLY_STAR
53443c95 1402 { $$ = newAVREF($term); }
79072805
LW
1403 ;
1404
d02b2fbf 1405star : PERLY_STAR indirob
53443c95 1406 { $$ = newGVREF(0,$indirob); }
79072805
LW
1407 ;
1408
89f35911 1409sliceme : ary
9086c946 1410 | term ARROW PERLY_SNAIL
53443c95 1411 { $$ = newAVREF($term); }
89f35911
FC
1412 ;
1413
76eba8ab 1414kvslice : hsh
0ba95c59 1415 | term ARROW PERLY_PERCENT_SIGN
53443c95 1416 { $$ = newHVREF($term); }
76eba8ab
FC
1417 ;
1418
89f35911 1419gelem : star
d02b2fbf 1420 | term ARROW PERLY_STAR
53443c95 1421 { $$ = newGVREF(0,$term); }
89f35911
FC
1422 ;
1423
891be019 1424/* Indirect objects */
185c2e96 1425indirob : BAREWORD
53443c95 1426 { $$ = scalar($BAREWORD); }
fad39ff1 1427 | scalar %prec PREC_LOW
53443c95 1428 { $$ = scalar($scalar); }
79072805 1429 | block
53443c95 1430 { $$ = op_scope($block); }
79072805 1431
93a17b20 1432 | PRIVATEREF
53443c95 1433 { $$ = $PRIVATEREF; }
8d063cd8 1434 ;