This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
handy.h Cast to unsigned before doing xor
[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 *
23 * The main job of of this grammar is to call the various newFOO()
24 * functions in op.c to build a syntax tree of OP structs.
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
0de566d7 34%pure_parser
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
78cdf107 46%token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ
28ac2b49 47
b5bbe64a 48%token <ival> '{' '}' '[' ']' '-' '+' '$' '@' '%' '*' '&' ';' '=' '.'
f0fcb552 49
ea25a9b2 50%token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST
7eb971ee 51%token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
88e1f1a2 52%token <opval> PLUGEXPR PLUGSTMT
b5bbe64a
JH
53%token <pval> LABEL
54%token <ival> FORMAT SUB ANONSUB PACKAGE USE
55%token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
56%token <ival> GIVEN WHEN DEFAULT
57%token <ival> LOOPEX DOTDOT YADAYADA
58%token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
59%token <ival> RELOP EQOP MULOP ADDOP
60%token <ival> DOLSHARP DO HASHBRACK NOAMP
61%token <ival> LOCAL MY REQUIRE
62%token <ival> COLONATTR FORMLBRACK FORMRBRACK
f05e27e5 63
727a8fe5 64%type <ival> grammar remember mremember
f05e27e5 65%type <ival> startsub startanonsub startformsub
b5bbe64a 66
b5a64814 67%type <ival> mintro
f05e27e5 68
8e720305 69%type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
fad39ff1 70%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
76eba8ab 71%type <opval> sliceme kvslice gelem
09b1cffe
Z
72%type <opval> listexpr nexpr texpr iexpr mexpr mnexpr miexpr
73%type <opval> optlistexpr optexpr indirob listop method
d39c26a6
FC
74%type <opval> formname subname proto optsubbody cont my_scalar my_var
75%type <opval> refgen_topic formblock
f05e27e5 76%type <opval> subattrlist myattrlist myattrterm myterm
30d9c59b 77%type <opval> realsubbody subsignature termbinop termunop anonymous termdo
705fe0e5 78%type <opval> formstmtseq formline formarg
79072805 79
b5bbe64a 80%nonassoc <ival> PREC_LOW
fad39ff1
SM
81%nonassoc LOOPEX
82
b5bbe64a
JH
83%left <ival> OROP DOROP
84%left <ival> ANDOP
85%right <ival> NOTOP
36477c24 86%nonassoc LSTOP LSTOPSUB
b5bbe64a
JH
87%left <ival> ','
88%right <ival> ASSIGNOP
89%right <ival> '?' ':'
be25f609 90%nonassoc DOTDOT YADAYADA
b5bbe64a
JH
91%left <ival> OROR DORDOR
92%left <ival> ANDAND
93%left <ival> BITOROP
94%left <ival> BITANDOP
a687059c
LW
95%nonassoc EQOP
96%nonassoc RELOP
36477c24 97%nonassoc UNIOP UNIOPSUB
20515881 98%nonassoc REQUIRE
b5bbe64a 99%left <ival> SHIFTOP
a687059c
LW
100%left ADDOP
101%left MULOP
b5bbe64a
JH
102%left <ival> MATCHOP
103%right <ival> '!' '~' UMINUS REFGEN
104%right <ival> POWOP
105%nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
106%left <ival> ARROW
107%nonassoc <ival> ')'
108%left <ival> '('
fad39ff1 109%left '[' '{'
8d063cd8
LW
110
111%% /* RULES */
112
28ac2b49 113/* Top-level choice of what kind of thing yyparse was called to parse */
727a8fe5
Z
114grammar : GRAMPROG
115 {
624fa8bd 116 parser->expect = XSTATE;
727a8fe5
Z
117 }
118 remember stmtseq
119 {
120 newPROG(block_end($3,$4));
8635e3c2 121 PL_compiling.cop_seq = 0;
727a8fe5
Z
122 $$ = 0;
123 }
78cdf107
Z
124 | GRAMEXPR
125 {
126 parser->expect = XTERM;
127 }
09b1cffe 128 optexpr
78cdf107
Z
129 {
130 PL_eval_root = $3;
131 $$ = 0;
132 }
e53d8f76
Z
133 | GRAMBLOCK
134 {
135 parser->expect = XBLOCK;
136 }
137 block
138 {
5f211341 139 PL_pad_reset_pending = TRUE;
8359b381
Z
140 PL_eval_root = $3;
141 $$ = 0;
142 yyunlex();
143 parser->yychar = YYEOF;
144 }
145 | GRAMBARESTMT
146 {
147 parser->expect = XSTATE;
148 }
149 barestmt
150 {
151 PL_pad_reset_pending = TRUE;
e53d8f76
Z
152 PL_eval_root = $3;
153 $$ = 0;
154 yyunlex();
155 parser->yychar = YYEOF;
156 }
9eb5c532 157 | GRAMFULLSTMT
28ac2b49 158 {
9eb5c532
Z
159 parser->expect = XSTATE;
160 }
161 fullstmt
162 {
5f211341 163 PL_pad_reset_pending = TRUE;
9eb5c532 164 PL_eval_root = $3;
28ac2b49
Z
165 $$ = 0;
166 yyunlex();
167 parser->yychar = YYEOF;
168 }
07ffcb73
Z
169 | GRAMSTMTSEQ
170 {
171 parser->expect = XSTATE;
172 }
5f211341 173 stmtseq
07ffcb73
Z
174 {
175 PL_eval_root = $3;
176 $$ = 0;
177 }
178 ;
179
891be019 180/* An ordinary block */
5f211341 181block : '{' remember stmtseq '}'
624fa8bd
FC
182 { if (parser->copline > (line_t)$1)
183 parser->copline = (line_t)$1;
f05e27e5 184 $$ = block_end($2, $3);
f05e27e5 185 }
a0d0e21e
LW
186 ;
187
7c70caa5 188/* format body */
705fe0e5 189formblock: '=' remember ';' FORMRBRACK formstmtseq ';' '.'
624fa8bd
FC
190 { if (parser->copline > (line_t)$1)
191 parser->copline = (line_t)$1;
705fe0e5 192 $$ = block_end($2, $5);
7c70caa5
FC
193 }
194 ;
195
55497cff 196remember: /* NULL */ /* start a full lexical scope */
34b54951
FC
197 { $$ = block_start(TRUE);
198 parser->parsed_sub = 0; }
55497cff 199 ;
200
5f211341 201mblock : '{' mremember stmtseq '}'
624fa8bd
FC
202 { if (parser->copline > (line_t)$1)
203 parser->copline = (line_t)$1;
f05e27e5 204 $$ = block_end($2, $3);
f05e27e5 205 }
55497cff 206 ;
207
208mremember: /* NULL */ /* start a partial lexical scope */
34b54951
FC
209 { $$ = block_start(FALSE);
210 parser->parsed_sub = 0; }
8d063cd8
LW
211 ;
212
eae48c89 213/* A sequence of statements in the program */
5f211341 214stmtseq : /* NULL */
bcabcc50 215 { $$ = (OP*)NULL; }
5f211341 216 | stmtseq fullstmt
2fcb4757 217 { $$ = op_append_list(OP_LINESEQ, $1, $2);
3280af22 218 PL_pad_reset_pending = TRUE;
503de470
DM
219 if ($1 && $2)
220 PL_hints |= HINT_BLOCK_SCOPE;
221 }
8d063cd8
LW
222 ;
223
705fe0e5
FC
224/* A sequence of format lines */
225formstmtseq: /* NULL */
226 { $$ = (OP*)NULL; }
227 | formstmtseq formline
228 { $$ = op_append_list(OP_LINESEQ, $1, $2);
229 PL_pad_reset_pending = TRUE;
230 if ($1 && $2)
231 PL_hints |= HINT_BLOCK_SCOPE;
232 }
233 ;
234
8e720305
Z
235/* A statement in the program, including optional labels */
236fullstmt: barestmt
eae48c89 237 {
b5bbe64a 238 $$ = $1 ? newSTATEOP(0, NULL, $1) : NULL;
eae48c89 239 }
8e720305
Z
240 | labfullstmt
241 { $$ = $1; }
242 ;
243
244labfullstmt: LABEL barestmt
245 {
b5bbe64a 246 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
8e720305
Z
247 }
248 | LABEL labfullstmt
249 {
b5bbe64a 250 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
8e720305 251 }
eae48c89
Z
252 ;
253
254/* A bare statement, lacking label and other aspects of state op */
255barestmt: PLUGSTMT
0d863452 256 { $$ = $1; }
7c70caa5 257 | FORMAT startformsub formname formblock
f05e27e5 258 {
eae48c89 259 CV *fmtcv = PL_compcv;
eae48c89
Z
260 newFORM($2, $3, $4);
261 $$ = (OP*)NULL;
4a273b91 262 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
74a9453a 263 pad_add_weakref(fmtcv);
f05e27e5 264 }
8b9fb2f9 265 parser->parsed_sub = 1;
eae48c89 266 }
50278755
FC
267 | SUB subname startsub
268 {
269 if ($2->op_type == OP_CONST) {
270 const char *const name =
271 SvPV_nolen_const(((SVOP*)$2)->op_sv);
272 if (strEQ(name, "BEGIN") || strEQ(name, "END")
764212cf
FC
273 || strEQ(name, "INIT") || strEQ(name, "CHECK")
274 || strEQ(name, "UNITCHECK"))
275 CvSPECIAL_on(PL_compcv);
50278755 276 }
e07561e6
FC
277 else
278 /* State subs inside anonymous subs need to be
279 clonable themselves. */
6d5c2147
FC
280 if (CvANON(CvOUTSIDE(PL_compcv))
281 || CvCLONE(CvOUTSIDE(PL_compcv))
282 || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
283 CvOUTSIDE(PL_compcv)
284 ))[$2->op_targ]))
e07561e6 285 CvCLONE_on(PL_compcv);
624fa8bd
FC
286 parser->in_my = 0;
287 parser->in_my_stash = NULL;
764212cf 288 }
30d9c59b 289 proto subattrlist optsubbody
eae48c89
Z
290 {
291 SvREFCNT_inc_simple_void(PL_compcv);
50278755
FC
292 $2->op_type == OP_CONST
293 ? newATTRSUB($3, $2, $5, $6, $7)
294 : newMYSUB($3, $2, $5, $6, $7)
50278755 295 ;
eae48c89 296 $$ = (OP*)NULL;
764212cf 297 intro_my();
34b54951 298 parser->parsed_sub = 1;
f05e27e5 299 }
eae48c89 300 | PACKAGE WORD WORD ';'
5f211341 301 {
eae48c89
Z
302 package($3);
303 if ($2)
304 package_version($2);
305 $$ = (OP*)NULL;
eae48c89
Z
306 }
307 | USE startsub
308 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
09b1cffe 309 WORD WORD optlistexpr ';'
eae48c89
Z
310 {
311 SvREFCNT_inc_simple_void(PL_compcv);
b5bbe64a 312 utilize($1, $2, $4, $5, $6);
34b54951 313 parser->parsed_sub = 1;
eae48c89 314 $$ = (OP*)NULL;
eae48c89 315 }
417a992d 316 | IF '(' remember mexpr ')' mblock else
eae48c89 317 {
3ad73efd
Z
318 $$ = block_end($3,
319 newCONDOP(0, $4, op_scope($6), $7));
624fa8bd 320 parser->copline = (line_t)$1;
eae48c89 321 }
417a992d 322 | UNLESS '(' remember miexpr ')' mblock else
eae48c89 323 {
3ad73efd
Z
324 $$ = block_end($3,
325 newCONDOP(0, $4, op_scope($6), $7));
624fa8bd 326 parser->copline = (line_t)$1;
eae48c89 327 }
b5a64814 328 | GIVEN '(' remember mexpr ')' mblock
eae48c89 329 {
b5a64814 330 const PADOFFSET offset = pad_findmy_pvs("$_", 0);
eae48c89 331 $$ = block_end($3,
b5a64814
FC
332 newGIVENOP($4, op_scope($6),
333 offset == NOT_IN_PAD
334 || PAD_COMPNAME_FLAGS_isOUR(offset)
335 ? 0
336 : offset));
624fa8bd 337 parser->copline = (line_t)$1;
eae48c89 338 }
417a992d 339 | WHEN '(' remember mexpr ')' mblock
3ad73efd 340 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
eae48c89 341 | DEFAULT block
3ad73efd 342 { $$ = newWHENOP(0, op_scope($2)); }
417a992d 343 | WHILE '(' remember texpr ')' mintro mblock cont
eae48c89
Z
344 {
345 $$ = block_end($3,
346 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
94bf0465 347 $4, $7, $8, $6));
624fa8bd 348 parser->copline = (line_t)$1;
eae48c89 349 }
417a992d 350 | UNTIL '(' remember iexpr ')' mintro mblock cont
eae48c89
Z
351 {
352 $$ = block_end($3,
94bf0465
Z
353 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
354 $4, $7, $8, $6));
624fa8bd 355 parser->copline = (line_t)$1;
eae48c89 356 }
2d0e3c96
FC
357 | FOR '(' remember mnexpr ';'
358 { parser->expect = XTERM; }
359 texpr ';'
360 { parser->expect = XTERM; }
361 mintro mnexpr ')'
eae48c89
Z
362 mblock
363 {
b5bbe64a 364 OP *initop = $4;
eae48c89 365 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
2d0e3c96 366 scalar($7), $13, $11, $10);
eae48c89
Z
367 if (initop) {
368 forop = op_prepend_elem(OP_LINESEQ, initop,
369 op_append_elem(OP_LINESEQ,
370 newOP(OP_UNSTACK, OPf_SPECIAL),
371 forop));
5f211341 372 }
0f602692 373 PL_hints |= HINT_BLOCK_SCOPE;
eae48c89 374 $$ = block_end($3, forop);
624fa8bd 375 parser->copline = (line_t)$1;
eae48c89 376 }
417a992d 377 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
eae48c89 378 {
94bf0465 379 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
624fa8bd 380 parser->copline = (line_t)$1;
eae48c89 381 }
417a992d 382 | FOR scalar '(' remember mexpr ')' mblock cont
eae48c89 383 {
94bf0465 384 $$ = block_end($4, newFOROP(0,
3ad73efd 385 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
624fa8bd 386 parser->copline = (line_t)$1;
eae48c89 387 }
d39c26a6
FC
388 | FOR REFGEN MY remember my_var
389 { parser->in_my = 0; $<opval>$ = my($5); }
390 '(' mexpr ')' mblock cont
391 {
392 $$ = block_end(
393 $4,
394 newFOROP(0,
395 op_lvalue(
396 newUNOP(OP_REFGEN, 0,
96801525 397 $<opval>6),
d39c26a6
FC
398 OP_ENTERLOOP),
399 $8, $10, $11)
400 );
401 parser->copline = (line_t)$1;
402 }
403 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
404 {
405 $$ = block_end($5, newFOROP(
406 0, op_lvalue(newUNOP(OP_REFGEN, 0,
96801525 407 $3),
d39c26a6
FC
408 OP_ENTERLOOP), $6, $8, $9));
409 parser->copline = (line_t)$1;
410 }
417a992d 411 | FOR '(' remember mexpr ')' mblock cont
eae48c89
Z
412 {
413 $$ = block_end($3,
94bf0465 414 newFOROP(0, (OP*)NULL, $4, $6, $7));
624fa8bd 415 parser->copline = (line_t)$1;
eae48c89
Z
416 }
417 | block cont
418 {
419 /* a block is a loop that happens once */
420 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
94bf0465 421 (OP*)NULL, $1, $2, 0);
eae48c89
Z
422 }
423 | PACKAGE WORD WORD '{' remember
424 {
eae48c89 425 package($3);
eae48c89 426 if ($2) {
eae48c89 427 package_version($2);
eae48c89
Z
428 }
429 }
430 stmtseq '}'
431 {
432 /* a block is a loop that happens once */
94bf0465 433 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
eae48c89 434 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
624fa8bd
FC
435 if (parser->copline > (line_t)$4)
436 parser->copline = (line_t)$4;
eae48c89
Z
437 }
438 | sideff ';'
439 {
eae48c89 440 $$ = $1;
eae48c89
Z
441 }
442 | ';'
443 {
b5bbe64a 444 $$ = (OP*)NULL;
624fa8bd 445 parser->copline = NOLINE;
5f211341 446 }
8d063cd8
LW
447 ;
448
705fe0e5
FC
449/* Format line */
450formline: THING formarg
451 { OP *list;
452 if ($2) {
453 OP *term = $2;
705fe0e5
FC
454 list = op_append_elem(OP_LIST, $1, term);
455 }
456 else {
705fe0e5 457 list = $1;
705fe0e5 458 }
624fa8bd
FC
459 if (parser->copline == NOLINE)
460 parser->copline = CopLINE(PL_curcop)-1;
461 else parser->copline--;
705fe0e5 462 $$ = newSTATEOP(0, NULL,
03d05f6e 463 op_convert_list(OP_FORMLINE, 0, list));
705fe0e5
FC
464 }
465 ;
466
467formarg : /* NULL */
468 { $$ = NULL; }
469 | FORMLBRACK stmtseq FORMRBRACK
470 { $$ = op_unscope($2); }
471 ;
472
891be019 473/* An expression which may have a side-effect */
a687059c 474sideff : error
bcabcc50 475 { $$ = (OP*)NULL; }
a687059c 476 | expr
79072805 477 { $$ = $1; }
a687059c 478 | expr IF expr
b5bbe64a 479 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
a687059c 480 | expr UNLESS expr
b5bbe64a 481 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
a687059c 482 | expr WHILE expr
b5bbe64a 483 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
55497cff 484 | expr UNTIL iexpr
b5bbe64a 485 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
ecca16b0 486 | expr FOR expr
94bf0465 487 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
624fa8bd 488 parser->copline = (line_t)$2; }
f20dcd76 489 | expr WHEN expr
3ad73efd 490 { $$ = newWHENOP($3, op_scope($1)); }
79072805
LW
491 ;
492
891be019 493/* else and elsif blocks */
79072805 494else : /* NULL */
bcabcc50 495 { $$ = (OP*)NULL; }
55497cff 496 | ELSE mblock
3ad73efd
Z
497 {
498 ($2)->op_flags |= OPf_PARENS;
499 $$ = op_scope($2);
f05e27e5 500 }
417a992d 501 | ELSIF '(' mexpr ')' mblock else
624fa8bd 502 { parser->copline = (line_t)$1;
3ad73efd
Z
503 $$ = newCONDOP(0,
504 newSTATEOP(OPf_SPECIAL,NULL,$3),
505 op_scope($5), $6);
506 PL_hints |= HINT_BLOCK_SCOPE;
f05e27e5 507 }
79072805
LW
508 ;
509
891be019 510/* Continue blocks */
79072805 511cont : /* NULL */
bcabcc50 512 { $$ = (OP*)NULL; }
79072805 513 | CONTINUE block
b5bbe64a 514 { $$ = op_scope($2); }
79072805
LW
515 ;
516
a034e688
DM
517/* determine whether there are any new my declarations */
518mintro : /* NULL */
519 { $$ = (PL_min_intro_pending &&
520 PL_max_intro_pending >= PL_min_intro_pending);
521 intro_my(); }
522
891be019 523/* Normal expression */
8d063cd8 524nexpr : /* NULL */
bcabcc50 525 { $$ = (OP*)NULL; }
8d063cd8
LW
526 | sideff
527 ;
528
891be019 529/* Boolean expression */
8d063cd8 530texpr : /* NULL means true */
f05e27e5
DM
531 { YYSTYPE tmplval;
532 (void)scan_num("1", &tmplval);
533 $$ = tmplval.opval; }
8d063cd8
LW
534 | expr
535 ;
536
891be019 537/* Inverted boolean expression */
55497cff 538iexpr : expr
539 { $$ = invert(scalar($1)); }
540 ;
541
891be019 542/* Expression with its own lexical scope */
55497cff 543mexpr : expr
bbce6d69 544 { $$ = $1; intro_my(); }
545 ;
546
547mnexpr : nexpr
548 { $$ = $1; intro_my(); }
55497cff 549 ;
550
55497cff 551miexpr : iexpr
bbce6d69 552 { $$ = $1; intro_my(); }
55497cff 553 ;
554
44a8e56a 555formname: WORD { $$ = $1; }
bcabcc50 556 | /* NULL */ { $$ = (OP*)NULL; }
8d063cd8
LW
557 ;
558
fa83b5b6 559startsub: /* NULL */ /* start a regular subroutine scope */
a8ff2fa6
DM
560 { $$ = start_subparse(FALSE, 0);
561 SAVEFREESV(PL_compcv); }
f05e27e5 562
28757baa 563 ;
564
565startanonsub: /* NULL */ /* start an anonymous subroutine scope */
a8ff2fa6
DM
566 { $$ = start_subparse(FALSE, CVf_ANON);
567 SAVEFREESV(PL_compcv); }
28757baa 568 ;
569
44a8e56a 570startformsub: /* NULL */ /* start a format subroutine scope */
a8ff2fa6
DM
571 { $$ = start_subparse(TRUE, 0);
572 SAVEFREESV(PL_compcv); }
44a8e56a 573 ;
574
891be019 575/* Name of a subroutine - must be a bareword, could be special */
50278755 576subname : WORD
4210d3f1 577 | PRIVATEREF
a0d0e21e
LW
578 ;
579
891be019 580/* Subroutine prototype */
4633a7c4 581proto : /* NULL */
bcabcc50 582 { $$ = (OP*)NULL; }
4633a7c4
LW
583 | THING
584 ;
28757baa 585
891be019 586/* Optional list of subroutine attributes */
09bef843 587subattrlist: /* NULL */
bcabcc50 588 { $$ = (OP*)NULL; }
09bef843 589 | COLONATTR THING
b5bbe64a 590 { $$ = $2; }
09bef843 591 | COLONATTR
b5bbe64a 592 { $$ = (OP*)NULL; }
09bef843
SB
593 ;
594
891be019 595/* List of attributes for a "my" variable declaration */
09bef843 596myattrlist: COLONATTR THING
b5bbe64a 597 { $$ = $2; }
09bef843 598 | COLONATTR
b5bbe64a 599 { $$ = (OP*)NULL; }
09bef843
SB
600 ;
601
30d9c59b
Z
602/* Optional subroutine signature */
603subsignature: /* NULL */ { $$ = (OP*)NULL; }
604 | '('
605 {
606 if (!FEATURE_SIGNATURES_IS_ENABLED)
607 Perl_croak(aTHX_ "Experimental "
608 "subroutine signatures not enabled");
609 Perl_ck_warner_d(aTHX_
610 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
611 "The signatures feature is experimental");
612 $<opval>$ = parse_subsignature();
613 }
614 ')'
615 {
616 $$ = op_append_list(OP_LINESEQ, $<opval>2,
617 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
624fa8bd 618 parser->expect = XBLOCK;
30d9c59b
Z
619 }
620 ;
621
622/* Subroutine body - block with optional signature */
623realsubbody: remember subsignature '{' stmtseq '}'
624 {
624fa8bd
FC
625 if (parser->copline > (line_t)$3)
626 parser->copline = (line_t)$3;
30d9c59b
Z
627 $$ = block_end($1,
628 op_append_list(OP_LINESEQ, $2, $4));
30d9c59b
Z
629 }
630 ;
631
632/* Optional subroutine body, for named subroutine declaration */
633optsubbody: realsubbody { $$ = $1; }
2d0e3c96 634 | ';' { $$ = (OP*)NULL; }
8d063cd8
LW
635 ;
636
891be019 637/* Ordinary expressions; logical combinations */
a0d0e21e 638expr : expr ANDOP expr
b5bbe64a 639 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
a0d0e21e 640 | expr OROP expr
b5bbe64a 641 { $$ = newLOGOP($2, 0, $1, $3); }
c963b151 642 | expr DOROP expr
b5bbe64a 643 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
09b1cffe 644 | listexpr %prec PREC_LOW
a0d0e21e
LW
645 ;
646
891be019 647/* Expressions are a list of terms joined by commas */
09b1cffe 648listexpr: listexpr ','
b5bbe64a 649 { $$ = $1; }
09b1cffe 650 | listexpr ',' term
f05e27e5 651 {
29522234 652 OP* term = $3;
2fcb4757 653 $$ = op_append_elem(OP_LIST, $1, term);
f05e27e5 654 }
fad39ff1 655 | term %prec PREC_LOW
8d063cd8
LW
656 ;
657
891be019 658/* List operators */
09b1cffe 659listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
03d05f6e 660 { $$ = op_convert_list($1, OPf_STACKED,
b5bbe64a 661 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
f05e27e5 662 }
891be019 663 | FUNC '(' indirob expr ')' /* print ($fh @args */
03d05f6e 664 { $$ = op_convert_list($1, OPf_STACKED,
b5bbe64a 665 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
f05e27e5 666 }
417a992d 667 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
03d05f6e 668 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
669 op_append_elem(OP_LIST,
670 op_prepend_elem(OP_LIST, scalar($1), $5),
b46e009d 671 newMETHOP(OP_METHOD, 0, $3)));
f05e27e5 672 }
891be019 673 | term ARROW method /* $foo->bar */
03d05f6e 674 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757 675 op_append_elem(OP_LIST, scalar($1),
b46e009d 676 newMETHOP(OP_METHOD, 0, $3)));
f05e27e5 677 }
09b1cffe 678 | METHOD indirob optlistexpr /* new Class @args */
03d05f6e 679 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
680 op_append_elem(OP_LIST,
681 op_prepend_elem(OP_LIST, $2, $3),
b46e009d 682 newMETHOP(OP_METHOD, 0, $1)));
f05e27e5 683 }
09b1cffe 684 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
03d05f6e 685 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
686 op_append_elem(OP_LIST,
687 op_prepend_elem(OP_LIST, $2, $4),
b46e009d 688 newMETHOP(OP_METHOD, 0, $1)));
f05e27e5 689 }
09b1cffe 690 | LSTOP optlistexpr /* print @args */
03d05f6e 691 { $$ = op_convert_list($1, 0, $2); }
09b1cffe 692 | FUNC '(' optexpr ')' /* print (@args) */
03d05f6e 693 { $$ = op_convert_list($1, 0, $3); }
718a7425 694 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
5a5094bd 695 { SvREFCNT_inc_simple_void(PL_compcv);
bcabcc50 696 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
09b1cffe 697 optlistexpr %prec LSTOP /* ... @bar */
4633a7c4 698 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
699 op_append_elem(OP_LIST,
700 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
f05e27e5 701 }
a687059c
LW
702 ;
703
891be019 704/* Names of methods. May use $object->$methodname */
a0d0e21e
LW
705method : METHOD
706 | scalar
707 ;
708
891be019 709/* Some kind of subscripted expression */
89f35911 710subscripted: gelem '{' expr ';' '}' /* *main::{something} */
891be019
SC
711 /* In this and all the hash accessors, ';' is
712 * provided by the tokeniser */
5c86b6df 713 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
891be019 714 | scalar '[' expr ']' /* $array[$element] */
f05e27e5 715 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
f05e27e5 716 }
891be019 717 | term ARROW '[' expr ']' /* somearef->[$element] */
fad39ff1
SM
718 { $$ = newBINOP(OP_AELEM, 0,
719 ref(newAVREF($1),OP_RV2AV),
f05e27e5 720 scalar($4));
f05e27e5 721 }
891be019 722 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
fad39ff1
SM
723 { $$ = newBINOP(OP_AELEM, 0,
724 ref(newAVREF($1),OP_RV2AV),
f05e27e5 725 scalar($3));
f05e27e5 726 }
5a63ceef 727 | scalar '{' expr ';' '}' /* $foo{bar();} */
fad39ff1 728 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
f05e27e5 729 }
891be019 730 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
fad39ff1
SM
731 { $$ = newBINOP(OP_HELEM, 0,
732 ref(newHVREF($1),OP_RV2HV),
5c86b6df 733 jmaybe($4)); }
891be019 734 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
fad39ff1
SM
735 { $$ = newBINOP(OP_HELEM, 0,
736 ref(newHVREF($1),OP_RV2HV),
5c86b6df 737 jmaybe($3)); }
891be019 738 | term ARROW '(' ')' /* $subref->() */
fad39ff1 739 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 740 newCVREF(0, scalar($1))); }
891be019 741 | term ARROW '(' expr ')' /* $subref->(@args) */
fad39ff1 742 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 743 op_append_elem(OP_LIST, $4,
b5bbe64a 744 newCVREF(0, scalar($1)))); }
fad39ff1 745
417a992d 746 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
fad39ff1 747 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 748 op_append_elem(OP_LIST, $3,
b5bbe64a 749 newCVREF(0, scalar($1)))); }
417a992d 750 | subscripted '(' ')' /* $foo->{bar}->() */
fad39ff1 751 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 752 newCVREF(0, scalar($1))); }
9a9798c2 753 | '(' expr ')' '[' expr ']' /* list slice */
b5bbe64a 754 { $$ = newSLICEOP(0, $5, $2); }
ea25a9b2 755 | QWLIST '[' expr ']' /* list literal slice */
b5bbe64a 756 { $$ = newSLICEOP(0, $3, $1); }
9a9798c2 757 | '(' ')' '[' expr ']' /* empty list slice! */
b5bbe64a 758 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
891be019 759 ;
fad39ff1 760
891be019 761/* Binary operators between terms */
f05e27e5 762termbinop: term ASSIGNOP term /* $x = $y */
b5bbe64a 763 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
891be019 764 | term POWOP term /* $x ** $y */
b5bbe64a 765 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 766 | term MULOP term /* $x * $y, $x x $y */
b5bbe64a 767 { if ($2 != OP_REPEAT)
79072805 768 scalar($1);
b5bbe64a 769 $$ = newBINOP($2, 0, $1, scalar($3));
f05e27e5 770 }
891be019 771 | term ADDOP term /* $x + $y */
b5bbe64a 772 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 773 | term SHIFTOP term /* $x >> $y, $x << $y */
b5bbe64a 774 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 775 | term RELOP term /* $x > $y, etc. */
b5bbe64a 776 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 777 | term EQOP term /* $x == $y, $x eq $y */
b5bbe64a 778 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 779 | term BITANDOP term /* $x & $y */
b5bbe64a 780 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 781 | term BITOROP term /* $x | $y */
b5bbe64a 782 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 783 | term DOTDOT term /* $x..$y, $x...$y */
b5bbe64a 784 { $$ = newRANGE($2, scalar($1), scalar($3)); }
891be019 785 | term ANDAND term /* $x && $y */
b5bbe64a 786 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
891be019 787 | term OROR term /* $x || $y */
b5bbe64a 788 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
c963b151 789 | term DORDOR term /* $x // $y */
b5bbe64a 790 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
891be019 791 | term MATCHOP term /* $x =~ /$y/ */
b5bbe64a 792 { $$ = bind_match($2, $1, $3); }
891be019 793 ;
8d063cd8 794
891be019
SC
795/* Unary operators and terms */
796termunop : '-' term %prec UMINUS /* -$x */
b5bbe64a 797 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
891be019 798 | '+' term %prec UMINUS /* +$x */
b5bbe64a
JH
799 { $$ = $2; }
800
891be019 801 | '!' term /* !$x */
b5bbe64a 802 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 803 | '~' term /* ~$x */
b5bbe64a 804 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
891be019 805 | term POSTINC /* $x++ */
79072805 806 { $$ = newUNOP(OP_POSTINC, 0,
b5bbe64a 807 op_lvalue(scalar($1), OP_POSTINC)); }
891be019 808 | term POSTDEC /* $x-- */
79072805 809 { $$ = newUNOP(OP_POSTDEC, 0,
b5bbe64a 810 op_lvalue(scalar($1), OP_POSTDEC));}
cc624add 811 | term POSTJOIN /* implicit join after interpolated ->@ */
03d05f6e 812 { $$ = op_convert_list(OP_JOIN, 0,
cc624add
FC
813 op_append_elem(
814 OP_LIST,
815 newSVREF(scalar(
816 newSVOP(OP_CONST,0,
817 newSVpvs("\""))
818 )),
819 $1
820 ));
cc624add 821 }
891be019 822 | PREINC term /* ++$x */
79072805 823 { $$ = newUNOP(OP_PREINC, 0,
b5bbe64a 824 op_lvalue(scalar($2), OP_PREINC)); }
891be019 825 | PREDEC term /* --$x */
79072805 826 { $$ = newUNOP(OP_PREDEC, 0,
b5bbe64a 827 op_lvalue(scalar($2), OP_PREDEC)); }
891be019
SC
828
829 ;
830
831/* Constructors for anonymous data */
832anonymous: '[' expr ']'
b5bbe64a 833 { $$ = newANONLIST($2); }
891be019 834 | '[' ']'
b5bbe64a 835 { $$ = newANONLIST((OP*)NULL);}
891be019 836 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
b5bbe64a 837 { $$ = newANONHASH($2); }
891be019 838 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
b5bbe64a 839 { $$ = newANONHASH((OP*)NULL); }
30d9c59b 840 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
5a5094bd 841 { SvREFCNT_inc_simple_void(PL_compcv);
b5bbe64a 842 $$ = newANONATTRSUB($2, $3, $4, $5); }
891be019
SC
843
844 ;
845
846/* Things called with "do" */
847termdo : DO term %prec UNIOP /* do $filename */
b5bbe64a 848 { $$ = dofile($2, $1);}
891be019 849 | DO block %prec '(' /* do { code */
b5bbe64a 850 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
891be019
SC
851 ;
852
853term : termbinop
854 | termunop
855 | anonymous
856 | termdo
e9bdcc27 857 | term '?' term ':' term
b5bbe64a 858 { $$ = newCONDOP(0, $1, $3, $5); }
891be019 859 | REFGEN term /* \$x, \@y, \%z */
b5bbe64a 860 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
09bef843
SB
861 | myattrterm %prec UNIOP
862 { $$ = $1; }
863 | LOCAL term %prec UNIOP
b5bbe64a 864 { $$ = localize($2,$1); }
a0d0e21e 865 | '(' expr ')'
b5bbe64a 866 { $$ = sawparens($2); }
ea25a9b2 867 | QWLIST
b5bbe64a 868 { $$ = $1; }
8d063cd8 869 | '(' ')'
b5bbe64a 870 { $$ = sawparens(newNULLLIST()); }
79072805 871 | scalar %prec '('
8d063cd8 872 { $$ = $1; }
79072805 873 | star %prec '('
8d063cd8 874 { $$ = $1; }
79072805 875 | hsh %prec '('
8d063cd8 876 { $$ = $1; }
79072805 877 | ary %prec '('
8d063cd8 878 { $$ = $1; }
891be019 879 | arylen %prec '(' /* $#x, $#{ something } */
79072805 880 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
fad39ff1
SM
881 | subscripted
882 { $$ = $1; }
89f35911 883 | sliceme '[' expr ']' /* array slice */
2fcb4757 884 { $$ = op_prepend_elem(OP_ASLICE,
79072805 885 newOP(OP_PUSHMARK, 0),
79072805
LW
886 newLISTOP(OP_ASLICE, 0,
887 list($3),
f05e27e5 888 ref($1, OP_ASLICE)));
429a2555
FC
889 if ($$ && $1)
890 $$->op_private |=
891 $1->op_private & OPpSLICEWARNING;
f05e27e5 892 }
76eba8ab 893 | kvslice '[' expr ']' /* array key/value slice */
6dd3e0f2
RZ
894 { $$ = op_prepend_elem(OP_KVASLICE,
895 newOP(OP_PUSHMARK, 0),
896 newLISTOP(OP_KVASLICE, 0,
897 list($3),
898 ref(oopsAV($1), OP_KVASLICE)));
95a31aad
FC
899 if ($$ && $1)
900 $$->op_private |=
901 $1->op_private & OPpSLICEWARNING;
6dd3e0f2 902 }
89f35911 903 | sliceme '{' expr ';' '}' /* @hash{@keys} */
2fcb4757 904 { $$ = op_prepend_elem(OP_HSLICE,
79072805 905 newOP(OP_PUSHMARK, 0),
79072805
LW
906 newLISTOP(OP_HSLICE, 0,
907 list($3),
a0d0e21e 908 ref(oopsHV($1), OP_HSLICE)));
429a2555
FC
909 if ($$ && $1)
910 $$->op_private |=
911 $1->op_private & OPpSLICEWARNING;
f05e27e5 912 }
76eba8ab 913 | kvslice '{' expr ';' '}' /* %hash{@keys} */
5cae3edb
RZ
914 { $$ = op_prepend_elem(OP_KVHSLICE,
915 newOP(OP_PUSHMARK, 0),
916 newLISTOP(OP_KVHSLICE, 0,
917 list($3),
918 ref($1, OP_KVHSLICE)));
95a31aad
FC
919 if ($$ && $1)
920 $$->op_private |=
921 $1->op_private & OPpSLICEWARNING;
5cae3edb 922 }
79072805
LW
923 | THING %prec '('
924 { $$ = $1; }
891be019 925 | amper /* &foo; */
c07a80fd 926 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
fb602e32 927 | amper '(' ')' /* &foo() or foo() */
f05e27e5 928 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
f05e27e5 929 }
fb602e32 930 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
f05e27e5
DM
931 {
932 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 933 op_append_elem(OP_LIST, $3, scalar($1)));
f05e27e5 934 }
fb602e32 935 | NOAMP subname optlistexpr /* foo @args (no parens) */
a0d0e21e 936 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 937 op_append_elem(OP_LIST, $3, scalar($2)));
f05e27e5 938 }
89f35911 939 | term ARROW '$' '*'
b5bbe64a 940 { $$ = newSVREF($1); }
89f35911 941 | term ARROW '@' '*'
b5bbe64a 942 { $$ = newAVREF($1); }
89f35911 943 | term ARROW '%' '*'
b5bbe64a 944 { $$ = newHVREF($1); }
89f35911
FC
945 | term ARROW '&' '*'
946 { $$ = newUNOP(OP_ENTERSUB, 0,
b5bbe64a 947 scalar(newCVREF($3,$1))); }
89f35911 948 | term ARROW '*' '*' %prec '('
b5bbe64a 949 { $$ = newGVREF(0,$1); }
891be019 950 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
b5bbe64a
JH
951 { $$ = newOP($1, OPf_SPECIAL);
952 PL_hints |= HINT_BLOCK_SCOPE; }
a0d0e21e 953 | LOOPEX term
b5bbe64a 954 { $$ = newLOOPEX($1,$2); }
09b1cffe 955 | NOTOP listexpr /* not $foo */
b5bbe64a 956 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 957 | UNIOP /* Unary op, $_ implied */
b5bbe64a 958 { $$ = newOP($1, 0); }
f05e27e5 959 | UNIOP block /* eval { foo }* */
b5bbe64a 960 { $$ = newUNOP($1, 0, $2); }
891be019 961 | UNIOP term /* Unary op */
b5bbe64a 962 { $$ = newUNOP($1, 0, $2); }
d2fdf8fd 963 | REQUIRE /* require, $_ implied */
b5bbe64a 964 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
d2fdf8fd 965 | REQUIRE term /* require Foo */
b5bbe64a 966 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
3cd0a11a
RGS
967 | UNIOPSUB
968 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 969 | UNIOPSUB term /* Sub treated as unop */
4633a7c4 970 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 971 op_append_elem(OP_LIST, $2, scalar($1))); }
891be019 972 | FUNC0 /* Nullary operator */
b5bbe64a 973 { $$ = newOP($1, 0); }
ae986130 974 | FUNC0 '(' ')'
b5bbe64a 975 { $$ = newOP($1, 0);}
7eb971ee
FC
976 | FUNC0OP /* Same as above, but op created in toke.c */
977 { $$ = $1; }
978 | FUNC0OP '(' ')'
b5bbe64a 979 { $$ = $1; }
891be019 980 | FUNC0SUB /* Sub treated as nullop */
b5bbe64a 981 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 982 | FUNC1 '(' ')' /* not () */
b5bbe64a
JH
983 { $$ = ($1 == OP_NOT)
984 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
985 : newOP($1, OPf_SPECIAL); }
891be019 986 | FUNC1 '(' expr ')' /* not($foo) */
b5bbe64a 987 { $$ = newUNOP($1, 0, $3); }
d63c20f2
DM
988 | PMFUNC /* m//, s///, qr//, tr/// */
989 {
990 if ( $1->op_type != OP_TRANS
991 && $1->op_type != OP_TRANSR
992 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
993 {
994 $<ival>$ = start_subparse(FALSE, CVf_ANON);
995 SAVEFREESV(PL_compcv);
996 } else
997 $<ival>$ = 0;
998 }
999 '(' listexpr ')'
b5bbe64a 1000 { $$ = pmruntime($1, $4, 1, $<ival>2); }
79072805 1001 | WORD
378cc40b 1002 | listop
be25f609 1003 | YADAYADA
1004 {
1005 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1006 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1007 }
88e1f1a2 1008 | PLUGEXPR
8d063cd8
LW
1009 ;
1010
891be019 1011/* "my" declarations, with optional attributes */
09bef843 1012myattrterm: MY myterm myattrlist
b5bbe64a 1013 { $$ = my_attrs($2,$3); }
09bef843 1014 | MY myterm
b5bbe64a 1015 { $$ = localize($2,$1); }
09bef843
SB
1016 ;
1017
891be019 1018/* Things that can be "my"'d */
09bef843 1019myterm : '(' expr ')'
b5bbe64a 1020 { $$ = sawparens($2); }
09bef843 1021 | '(' ')'
b5bbe64a
JH
1022 { $$ = sawparens(newNULLLIST()); }
1023
09bef843
SB
1024 | scalar %prec '('
1025 { $$ = $1; }
1026 | hsh %prec '('
1027 { $$ = $1; }
1028 | ary %prec '('
1029 { $$ = $1; }
1030 ;
1031
891be019 1032/* Basic list expressions */
09b1cffe 1033optlistexpr: /* NULL */ %prec PREC_LOW
bcabcc50 1034 { $$ = (OP*)NULL; }
09b1cffe 1035 | listexpr %prec PREC_LOW
a0d0e21e
LW
1036 { $$ = $1; }
1037 ;
1038
09b1cffe 1039optexpr: /* NULL */
bcabcc50 1040 { $$ = (OP*)NULL; }
79072805
LW
1041 | expr
1042 { $$ = $1; }
1043 ;
1044
891be019
SC
1045/* A little bit of trickery to make "for my $foo (@bar)" actually be
1046 lexical */
55497cff 1047my_scalar: scalar
624fa8bd 1048 { parser->in_my = 0; $$ = my($1); }
55497cff 1049 ;
1050
d39c26a6
FC
1051my_var : scalar
1052 | ary
1053 | hsh
1054 ;
1055
1056refgen_topic: my_var
1057 | amper
1058 ;
1059
79072805 1060amper : '&' indirob
b5bbe64a 1061 { $$ = newCVREF($1,$2); }
a687059c
LW
1062 ;
1063
79072805 1064scalar : '$' indirob
b5bbe64a 1065 { $$ = newSVREF($2); }
a687059c
LW
1066 ;
1067
79072805 1068ary : '@' indirob
f05e27e5 1069 { $$ = newAVREF($2);
b5bbe64a 1070 if ($$) $$->op_private |= $1;
f05e27e5 1071 }
79072805
LW
1072 ;
1073
1074hsh : '%' indirob
f05e27e5 1075 { $$ = newHVREF($2);
b5bbe64a 1076 if ($$) $$->op_private |= $1;
f05e27e5 1077 }
79072805
LW
1078 ;
1079
1080arylen : DOLSHARP indirob
b5bbe64a 1081 { $$ = newAVREF($2); }
ff25e5db 1082 | term ARROW DOLSHARP '*'
b5bbe64a 1083 { $$ = newAVREF($1); }
79072805
LW
1084 ;
1085
1086star : '*' indirob
b5bbe64a 1087 { $$ = newGVREF(0,$2); }
79072805
LW
1088 ;
1089
89f35911
FC
1090sliceme : ary
1091 | term ARROW '@'
b5bbe64a 1092 { $$ = newAVREF($1); }
89f35911
FC
1093 ;
1094
76eba8ab
FC
1095kvslice : hsh
1096 | term ARROW '%'
b5bbe64a 1097 { $$ = newHVREF($1); }
76eba8ab
FC
1098 ;
1099
89f35911
FC
1100gelem : star
1101 | term ARROW '*'
b5bbe64a 1102 { $$ = newGVREF(0,$1); }
89f35911
FC
1103 ;
1104
891be019 1105/* Indirect objects */
79072805
LW
1106indirob : WORD
1107 { $$ = scalar($1); }
fad39ff1 1108 | scalar %prec PREC_LOW
f05e27e5 1109 { $$ = scalar($1); }
79072805 1110 | block
3ad73efd 1111 { $$ = op_scope($1); }
79072805 1112
93a17b20
LW
1113 | PRIVATEREF
1114 { $$ = $1; }
8d063cd8 1115 ;