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