This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta for e9e9e546c676
[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
f10ebf6c 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 72%type <opval> listexpr nexpr texpr iexpr mexpr mnexpr miexpr
9b6b7be8 73%type <opval> optlistexpr optexpr optrepl 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
abcf453d 77%type <opval> 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
PP
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
PP
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 }
abcf453d
PM
300 | SUB subname startsub
301 {
302 if ($2->op_type == OP_CONST) {
303 const char *const name =
304 SvPV_nolen_const(((SVOP*)$2)->op_sv);
305 if (strEQ(name, "BEGIN") || strEQ(name, "END")
306 || strEQ(name, "INIT") || strEQ(name, "CHECK")
307 || strEQ(name, "UNITCHECK"))
308 CvSPECIAL_on(PL_compcv);
309 }
310 else
311 /* State subs inside anonymous subs need to be
312 clonable themselves. */
313 if (CvANON(CvOUTSIDE(PL_compcv))
314 || CvCLONE(CvOUTSIDE(PL_compcv))
315 || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
316 CvOUTSIDE(PL_compcv)
317 ))[$2->op_targ]))
318 CvCLONE_on(PL_compcv);
319 parser->in_my = 0;
320 parser->in_my_stash = NULL;
321 }
322 remember subsignature subattrlist '{' stmtseq '}'
323 {
324 OP *body;
325 if (parser->copline > (line_t)$8)
326 parser->copline = (line_t)$8;
327 body = block_end($5,
328 op_append_list(OP_LINESEQ, $6, $9));
329
330 SvREFCNT_inc_simple_void(PL_compcv);
331 $2->op_type == OP_CONST
332 ? newATTRSUB($3, $2, NULL, $7, body)
333 : newMYSUB($3, $2, NULL, $7, body)
334 ;
335 $$ = (OP*)NULL;
336 intro_my();
337 parser->parsed_sub = 1;
338 }
eae48c89 339 | PACKAGE WORD WORD ';'
5f211341 340 {
eae48c89
Z
341 package($3);
342 if ($2)
343 package_version($2);
344 $$ = (OP*)NULL;
eae48c89
Z
345 }
346 | USE startsub
347 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
09b1cffe 348 WORD WORD optlistexpr ';'
eae48c89
Z
349 {
350 SvREFCNT_inc_simple_void(PL_compcv);
b5bbe64a 351 utilize($1, $2, $4, $5, $6);
34b54951 352 parser->parsed_sub = 1;
eae48c89 353 $$ = (OP*)NULL;
eae48c89 354 }
417a992d 355 | IF '(' remember mexpr ')' mblock else
eae48c89 356 {
3ad73efd
Z
357 $$ = block_end($3,
358 newCONDOP(0, $4, op_scope($6), $7));
624fa8bd 359 parser->copline = (line_t)$1;
eae48c89 360 }
417a992d 361 | UNLESS '(' remember miexpr ')' mblock else
eae48c89 362 {
3ad73efd
Z
363 $$ = block_end($3,
364 newCONDOP(0, $4, op_scope($6), $7));
624fa8bd 365 parser->copline = (line_t)$1;
eae48c89 366 }
b5a64814 367 | GIVEN '(' remember mexpr ')' mblock
eae48c89 368 {
5d051ee0 369 $$ = block_end($3, newGIVENOP($4, op_scope($6), 0));
624fa8bd 370 parser->copline = (line_t)$1;
eae48c89 371 }
417a992d 372 | WHEN '(' remember mexpr ')' mblock
3ad73efd 373 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
eae48c89 374 | DEFAULT block
3ad73efd 375 { $$ = newWHENOP(0, op_scope($2)); }
417a992d 376 | WHILE '(' remember texpr ')' mintro mblock cont
eae48c89
Z
377 {
378 $$ = block_end($3,
379 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
94bf0465 380 $4, $7, $8, $6));
624fa8bd 381 parser->copline = (line_t)$1;
eae48c89 382 }
417a992d 383 | UNTIL '(' remember iexpr ')' mintro mblock cont
eae48c89
Z
384 {
385 $$ = block_end($3,
94bf0465
Z
386 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
387 $4, $7, $8, $6));
624fa8bd 388 parser->copline = (line_t)$1;
eae48c89 389 }
2d0e3c96
FC
390 | FOR '(' remember mnexpr ';'
391 { parser->expect = XTERM; }
392 texpr ';'
393 { parser->expect = XTERM; }
394 mintro mnexpr ')'
eae48c89
Z
395 mblock
396 {
b5bbe64a 397 OP *initop = $4;
eae48c89 398 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
2d0e3c96 399 scalar($7), $13, $11, $10);
eae48c89
Z
400 if (initop) {
401 forop = op_prepend_elem(OP_LINESEQ, initop,
402 op_append_elem(OP_LINESEQ,
403 newOP(OP_UNSTACK, OPf_SPECIAL),
404 forop));
5f211341 405 }
0f602692 406 PL_hints |= HINT_BLOCK_SCOPE;
eae48c89 407 $$ = block_end($3, forop);
624fa8bd 408 parser->copline = (line_t)$1;
eae48c89 409 }
417a992d 410 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
eae48c89 411 {
94bf0465 412 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
624fa8bd 413 parser->copline = (line_t)$1;
eae48c89 414 }
417a992d 415 | FOR scalar '(' remember mexpr ')' mblock cont
eae48c89 416 {
94bf0465 417 $$ = block_end($4, newFOROP(0,
3ad73efd 418 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
624fa8bd 419 parser->copline = (line_t)$1;
eae48c89 420 }
d39c26a6
FC
421 | FOR REFGEN MY remember my_var
422 { parser->in_my = 0; $<opval>$ = my($5); }
423 '(' mexpr ')' mblock cont
424 {
425 $$ = block_end(
426 $4,
427 newFOROP(0,
428 op_lvalue(
429 newUNOP(OP_REFGEN, 0,
96801525 430 $<opval>6),
d39c26a6
FC
431 OP_ENTERLOOP),
432 $8, $10, $11)
433 );
434 parser->copline = (line_t)$1;
435 }
436 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
437 {
438 $$ = block_end($5, newFOROP(
439 0, op_lvalue(newUNOP(OP_REFGEN, 0,
96801525 440 $3),
d39c26a6
FC
441 OP_ENTERLOOP), $6, $8, $9));
442 parser->copline = (line_t)$1;
443 }
417a992d 444 | FOR '(' remember mexpr ')' mblock cont
eae48c89
Z
445 {
446 $$ = block_end($3,
94bf0465 447 newFOROP(0, (OP*)NULL, $4, $6, $7));
624fa8bd 448 parser->copline = (line_t)$1;
eae48c89
Z
449 }
450 | block cont
451 {
452 /* a block is a loop that happens once */
453 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
94bf0465 454 (OP*)NULL, $1, $2, 0);
eae48c89
Z
455 }
456 | PACKAGE WORD WORD '{' remember
457 {
eae48c89 458 package($3);
eae48c89 459 if ($2) {
eae48c89 460 package_version($2);
eae48c89
Z
461 }
462 }
463 stmtseq '}'
464 {
465 /* a block is a loop that happens once */
94bf0465 466 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
eae48c89 467 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
624fa8bd
FC
468 if (parser->copline > (line_t)$4)
469 parser->copline = (line_t)$4;
eae48c89
Z
470 }
471 | sideff ';'
472 {
eae48c89 473 $$ = $1;
eae48c89
Z
474 }
475 | ';'
476 {
b5bbe64a 477 $$ = (OP*)NULL;
624fa8bd 478 parser->copline = NOLINE;
5f211341 479 }
8d063cd8
LW
480 ;
481
705fe0e5
FC
482/* Format line */
483formline: THING formarg
484 { OP *list;
485 if ($2) {
486 OP *term = $2;
705fe0e5
FC
487 list = op_append_elem(OP_LIST, $1, term);
488 }
489 else {
705fe0e5 490 list = $1;
705fe0e5 491 }
624fa8bd
FC
492 if (parser->copline == NOLINE)
493 parser->copline = CopLINE(PL_curcop)-1;
494 else parser->copline--;
705fe0e5 495 $$ = newSTATEOP(0, NULL,
03d05f6e 496 op_convert_list(OP_FORMLINE, 0, list));
705fe0e5
FC
497 }
498 ;
499
500formarg : /* NULL */
501 { $$ = NULL; }
502 | FORMLBRACK stmtseq FORMRBRACK
503 { $$ = op_unscope($2); }
504 ;
505
891be019 506/* An expression which may have a side-effect */
a687059c 507sideff : error
bcabcc50 508 { $$ = (OP*)NULL; }
a687059c 509 | expr
79072805 510 { $$ = $1; }
a687059c 511 | expr IF expr
b5bbe64a 512 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
a687059c 513 | expr UNLESS expr
b5bbe64a 514 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
a687059c 515 | expr WHILE expr
b5bbe64a 516 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
55497cff 517 | expr UNTIL iexpr
b5bbe64a 518 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
ecca16b0 519 | expr FOR expr
94bf0465 520 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
624fa8bd 521 parser->copline = (line_t)$2; }
f20dcd76 522 | expr WHEN expr
3ad73efd 523 { $$ = newWHENOP($3, op_scope($1)); }
79072805
LW
524 ;
525
891be019 526/* else and elsif blocks */
79072805 527else : /* NULL */
bcabcc50 528 { $$ = (OP*)NULL; }
55497cff 529 | ELSE mblock
3ad73efd
Z
530 {
531 ($2)->op_flags |= OPf_PARENS;
532 $$ = op_scope($2);
f05e27e5 533 }
417a992d 534 | ELSIF '(' mexpr ')' mblock else
624fa8bd 535 { parser->copline = (line_t)$1;
3ad73efd
Z
536 $$ = newCONDOP(0,
537 newSTATEOP(OPf_SPECIAL,NULL,$3),
538 op_scope($5), $6);
539 PL_hints |= HINT_BLOCK_SCOPE;
f05e27e5 540 }
79072805
LW
541 ;
542
891be019 543/* Continue blocks */
79072805 544cont : /* NULL */
bcabcc50 545 { $$ = (OP*)NULL; }
79072805 546 | CONTINUE block
b5bbe64a 547 { $$ = op_scope($2); }
79072805
LW
548 ;
549
a034e688
DM
550/* determine whether there are any new my declarations */
551mintro : /* NULL */
552 { $$ = (PL_min_intro_pending &&
553 PL_max_intro_pending >= PL_min_intro_pending);
554 intro_my(); }
555
891be019 556/* Normal expression */
8d063cd8 557nexpr : /* NULL */
bcabcc50 558 { $$ = (OP*)NULL; }
8d063cd8
LW
559 | sideff
560 ;
561
891be019 562/* Boolean expression */
8d063cd8 563texpr : /* NULL means true */
f05e27e5
DM
564 { YYSTYPE tmplval;
565 (void)scan_num("1", &tmplval);
566 $$ = tmplval.opval; }
8d063cd8
LW
567 | expr
568 ;
569
891be019 570/* Inverted boolean expression */
55497cff
PP
571iexpr : expr
572 { $$ = invert(scalar($1)); }
573 ;
574
891be019 575/* Expression with its own lexical scope */
55497cff 576mexpr : expr
bbce6d69
PP
577 { $$ = $1; intro_my(); }
578 ;
579
580mnexpr : nexpr
581 { $$ = $1; intro_my(); }
55497cff
PP
582 ;
583
55497cff 584miexpr : iexpr
bbce6d69 585 { $$ = $1; intro_my(); }
55497cff
PP
586 ;
587
44a8e56a 588formname: WORD { $$ = $1; }
bcabcc50 589 | /* NULL */ { $$ = (OP*)NULL; }
8d063cd8
LW
590 ;
591
fa83b5b6 592startsub: /* NULL */ /* start a regular subroutine scope */
a8ff2fa6
DM
593 { $$ = start_subparse(FALSE, 0);
594 SAVEFREESV(PL_compcv); }
f05e27e5 595
28757baa
PP
596 ;
597
598startanonsub: /* NULL */ /* start an anonymous subroutine scope */
a8ff2fa6
DM
599 { $$ = start_subparse(FALSE, CVf_ANON);
600 SAVEFREESV(PL_compcv); }
28757baa
PP
601 ;
602
44a8e56a 603startformsub: /* NULL */ /* start a format subroutine scope */
a8ff2fa6
DM
604 { $$ = start_subparse(TRUE, 0);
605 SAVEFREESV(PL_compcv); }
44a8e56a
PP
606 ;
607
891be019 608/* Name of a subroutine - must be a bareword, could be special */
50278755 609subname : WORD
4210d3f1 610 | PRIVATEREF
a0d0e21e
LW
611 ;
612
891be019 613/* Subroutine prototype */
4633a7c4 614proto : /* NULL */
bcabcc50 615 { $$ = (OP*)NULL; }
4633a7c4
LW
616 | THING
617 ;
28757baa 618
891be019 619/* Optional list of subroutine attributes */
09bef843 620subattrlist: /* NULL */
bcabcc50 621 { $$ = (OP*)NULL; }
09bef843 622 | COLONATTR THING
b5bbe64a 623 { $$ = $2; }
09bef843 624 | COLONATTR
b5bbe64a 625 { $$ = (OP*)NULL; }
09bef843
SB
626 ;
627
891be019 628/* List of attributes for a "my" variable declaration */
09bef843 629myattrlist: COLONATTR THING
b5bbe64a 630 { $$ = $2; }
09bef843 631 | COLONATTR
b5bbe64a 632 { $$ = (OP*)NULL; }
09bef843
SB
633 ;
634
abcf453d
PM
635/* Subroutine signature */
636subsignature: '('
30d9c59b 637 {
abcf453d
PM
638 /* We shouldn't get here otherwise */
639 assert(FEATURE_SIGNATURES_IS_ENABLED);
640
30d9c59b
Z
641 Perl_ck_warner_d(aTHX_
642 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
643 "The signatures feature is experimental");
644 $<opval>$ = parse_subsignature();
645 }
646 ')'
647 {
648 $$ = op_append_list(OP_LINESEQ, $<opval>2,
649 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
abcf453d 650 parser->expect = XATTRBLOCK;
30d9c59b
Z
651 }
652 ;
653
654/* Optional subroutine body, for named subroutine declaration */
abcf453d 655optsubbody: block
2d0e3c96 656 | ';' { $$ = (OP*)NULL; }
8d063cd8
LW
657 ;
658
891be019 659/* Ordinary expressions; logical combinations */
a0d0e21e 660expr : expr ANDOP expr
b5bbe64a 661 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
a0d0e21e 662 | expr OROP expr
b5bbe64a 663 { $$ = newLOGOP($2, 0, $1, $3); }
c963b151 664 | expr DOROP expr
b5bbe64a 665 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
09b1cffe 666 | listexpr %prec PREC_LOW
a0d0e21e
LW
667 ;
668
891be019 669/* Expressions are a list of terms joined by commas */
09b1cffe 670listexpr: listexpr ','
b5bbe64a 671 { $$ = $1; }
09b1cffe 672 | listexpr ',' term
abcf453d 673 {
29522234 674 OP* term = $3;
2fcb4757 675 $$ = op_append_elem(OP_LIST, $1, term);
f05e27e5 676 }
fad39ff1 677 | term %prec PREC_LOW
8d063cd8
LW
678 ;
679
891be019 680/* List operators */
09b1cffe 681listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
03d05f6e 682 { $$ = op_convert_list($1, OPf_STACKED,
b5bbe64a 683 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
f05e27e5 684 }
891be019 685 | FUNC '(' indirob expr ')' /* print ($fh @args */
03d05f6e 686 { $$ = op_convert_list($1, OPf_STACKED,
b5bbe64a 687 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
f05e27e5 688 }
417a992d 689 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
03d05f6e 690 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
691 op_append_elem(OP_LIST,
692 op_prepend_elem(OP_LIST, scalar($1), $5),
b46e009d 693 newMETHOP(OP_METHOD, 0, $3)));
f05e27e5 694 }
891be019 695 | term ARROW method /* $foo->bar */
03d05f6e 696 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757 697 op_append_elem(OP_LIST, scalar($1),
b46e009d 698 newMETHOP(OP_METHOD, 0, $3)));
f05e27e5 699 }
09b1cffe 700 | METHOD indirob optlistexpr /* new Class @args */
03d05f6e 701 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
702 op_append_elem(OP_LIST,
703 op_prepend_elem(OP_LIST, $2, $3),
b46e009d 704 newMETHOP(OP_METHOD, 0, $1)));
f05e27e5 705 }
09b1cffe 706 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
03d05f6e 707 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
708 op_append_elem(OP_LIST,
709 op_prepend_elem(OP_LIST, $2, $4),
b46e009d 710 newMETHOP(OP_METHOD, 0, $1)));
f05e27e5 711 }
09b1cffe 712 | LSTOP optlistexpr /* print @args */
03d05f6e 713 { $$ = op_convert_list($1, 0, $2); }
09b1cffe 714 | FUNC '(' optexpr ')' /* print (@args) */
03d05f6e 715 { $$ = op_convert_list($1, 0, $3); }
718a7425 716 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
5a5094bd 717 { SvREFCNT_inc_simple_void(PL_compcv);
bcabcc50 718 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
09b1cffe 719 optlistexpr %prec LSTOP /* ... @bar */
4633a7c4 720 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
721 op_append_elem(OP_LIST,
722 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
f05e27e5 723 }
a687059c
LW
724 ;
725
891be019 726/* Names of methods. May use $object->$methodname */
a0d0e21e
LW
727method : METHOD
728 | scalar
729 ;
730
891be019 731/* Some kind of subscripted expression */
89f35911 732subscripted: gelem '{' expr ';' '}' /* *main::{something} */
891be019
SC
733 /* In this and all the hash accessors, ';' is
734 * provided by the tokeniser */
5c86b6df 735 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
891be019 736 | scalar '[' expr ']' /* $array[$element] */
f05e27e5 737 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
f05e27e5 738 }
891be019 739 | term ARROW '[' expr ']' /* somearef->[$element] */
fad39ff1
SM
740 { $$ = newBINOP(OP_AELEM, 0,
741 ref(newAVREF($1),OP_RV2AV),
f05e27e5 742 scalar($4));
f05e27e5 743 }
891be019 744 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
fad39ff1
SM
745 { $$ = newBINOP(OP_AELEM, 0,
746 ref(newAVREF($1),OP_RV2AV),
f05e27e5 747 scalar($3));
f05e27e5 748 }
5a63ceef 749 | scalar '{' expr ';' '}' /* $foo{bar();} */
fad39ff1 750 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
f05e27e5 751 }
891be019 752 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
fad39ff1
SM
753 { $$ = newBINOP(OP_HELEM, 0,
754 ref(newHVREF($1),OP_RV2HV),
5c86b6df 755 jmaybe($4)); }
891be019 756 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
fad39ff1
SM
757 { $$ = newBINOP(OP_HELEM, 0,
758 ref(newHVREF($1),OP_RV2HV),
5c86b6df 759 jmaybe($3)); }
891be019 760 | term ARROW '(' ')' /* $subref->() */
fad39ff1 761 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 762 newCVREF(0, scalar($1))); }
891be019 763 | term ARROW '(' expr ')' /* $subref->(@args) */
fad39ff1 764 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 765 op_append_elem(OP_LIST, $4,
b5bbe64a 766 newCVREF(0, scalar($1)))); }
fad39ff1 767
417a992d 768 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
fad39ff1 769 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 770 op_append_elem(OP_LIST, $3,
b5bbe64a 771 newCVREF(0, scalar($1)))); }
417a992d 772 | subscripted '(' ')' /* $foo->{bar}->() */
fad39ff1 773 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 774 newCVREF(0, scalar($1))); }
9a9798c2 775 | '(' expr ')' '[' expr ']' /* list slice */
b5bbe64a 776 { $$ = newSLICEOP(0, $5, $2); }
ea25a9b2 777 | QWLIST '[' expr ']' /* list literal slice */
b5bbe64a 778 { $$ = newSLICEOP(0, $3, $1); }
9a9798c2 779 | '(' ')' '[' expr ']' /* empty list slice! */
b5bbe64a 780 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
891be019 781 ;
fad39ff1 782
891be019 783/* Binary operators between terms */
f05e27e5 784termbinop: term ASSIGNOP term /* $x = $y */
b5bbe64a 785 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
891be019 786 | term POWOP term /* $x ** $y */
b5bbe64a 787 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 788 | term MULOP term /* $x * $y, $x x $y */
b5bbe64a 789 { if ($2 != OP_REPEAT)
79072805 790 scalar($1);
b5bbe64a 791 $$ = newBINOP($2, 0, $1, scalar($3));
f05e27e5 792 }
891be019 793 | term ADDOP term /* $x + $y */
b5bbe64a 794 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 795 | term SHIFTOP term /* $x >> $y, $x << $y */
b5bbe64a 796 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 797 | term RELOP term /* $x > $y, etc. */
b5bbe64a 798 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 799 | term EQOP term /* $x == $y, $x eq $y */
b5bbe64a 800 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 801 | term BITANDOP term /* $x & $y */
b5bbe64a 802 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 803 | term BITOROP term /* $x | $y */
b5bbe64a 804 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 805 | term DOTDOT term /* $x..$y, $x...$y */
b5bbe64a 806 { $$ = newRANGE($2, scalar($1), scalar($3)); }
891be019 807 | term ANDAND term /* $x && $y */
b5bbe64a 808 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
891be019 809 | term OROR term /* $x || $y */
b5bbe64a 810 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
c963b151 811 | term DORDOR term /* $x // $y */
b5bbe64a 812 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
891be019 813 | term MATCHOP term /* $x =~ /$y/ */
b5bbe64a 814 { $$ = bind_match($2, $1, $3); }
891be019 815 ;
8d063cd8 816
891be019
SC
817/* Unary operators and terms */
818termunop : '-' term %prec UMINUS /* -$x */
b5bbe64a 819 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
891be019 820 | '+' term %prec UMINUS /* +$x */
b5bbe64a
JH
821 { $$ = $2; }
822
891be019 823 | '!' term /* !$x */
b5bbe64a 824 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 825 | '~' term /* ~$x */
8823cb89 826 { $$ = newUNOP($1, 0, scalar($2)); }
891be019 827 | term POSTINC /* $x++ */
79072805 828 { $$ = newUNOP(OP_POSTINC, 0,
b5bbe64a 829 op_lvalue(scalar($1), OP_POSTINC)); }
891be019 830 | term POSTDEC /* $x-- */
79072805 831 { $$ = newUNOP(OP_POSTDEC, 0,
b5bbe64a 832 op_lvalue(scalar($1), OP_POSTDEC));}
cc624add 833 | term POSTJOIN /* implicit join after interpolated ->@ */
03d05f6e 834 { $$ = op_convert_list(OP_JOIN, 0,
cc624add
FC
835 op_append_elem(
836 OP_LIST,
837 newSVREF(scalar(
838 newSVOP(OP_CONST,0,
839 newSVpvs("\""))
840 )),
841 $1
842 ));
cc624add 843 }
891be019 844 | PREINC term /* ++$x */
79072805 845 { $$ = newUNOP(OP_PREINC, 0,
b5bbe64a 846 op_lvalue(scalar($2), OP_PREINC)); }
891be019 847 | PREDEC term /* --$x */
79072805 848 { $$ = newUNOP(OP_PREDEC, 0,
b5bbe64a 849 op_lvalue(scalar($2), OP_PREDEC)); }
891be019
SC
850
851 ;
852
853/* Constructors for anonymous data */
854anonymous: '[' expr ']'
b5bbe64a 855 { $$ = newANONLIST($2); }
891be019 856 | '[' ']'
b5bbe64a 857 { $$ = newANONLIST((OP*)NULL);}
891be019 858 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
b5bbe64a 859 { $$ = newANONHASH($2); }
891be019 860 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
b5bbe64a 861 { $$ = newANONHASH((OP*)NULL); }
abcf453d 862 | ANONSUB startanonsub proto subattrlist block %prec '('
5a5094bd 863 { SvREFCNT_inc_simple_void(PL_compcv);
b5bbe64a 864 $$ = newANONATTRSUB($2, $3, $4, $5); }
abcf453d
PM
865 | ANONSUB startanonsub remember subsignature subattrlist '{' stmtseq '}' %prec '('
866 {
867 OP *body;
868 if (parser->copline > (line_t)$6)
869 parser->copline = (line_t)$6;
870 body = block_end($3,
871 op_append_list(OP_LINESEQ, $4, $7));
872 SvREFCNT_inc_simple_void(PL_compcv);
873 $$ = newANONATTRSUB($2, NULL, $5, body);
874 }
891be019
SC
875
876 ;
877
878/* Things called with "do" */
879termdo : DO term %prec UNIOP /* do $filename */
b5bbe64a 880 { $$ = dofile($2, $1);}
891be019 881 | DO block %prec '(' /* do { code */
b5bbe64a 882 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
891be019
SC
883 ;
884
885term : termbinop
886 | termunop
887 | anonymous
888 | termdo
e9bdcc27 889 | term '?' term ':' term
b5bbe64a 890 { $$ = newCONDOP(0, $1, $3, $5); }
891be019 891 | REFGEN term /* \$x, \@y, \%z */
070d3cb6 892 { $$ = newUNOP(OP_REFGEN, 0, $2); }
09bef843
SB
893 | myattrterm %prec UNIOP
894 { $$ = $1; }
895 | LOCAL term %prec UNIOP
b5bbe64a 896 { $$ = localize($2,$1); }
a0d0e21e 897 | '(' expr ')'
b5bbe64a 898 { $$ = sawparens($2); }
ea25a9b2 899 | QWLIST
b5bbe64a 900 { $$ = $1; }
8d063cd8 901 | '(' ')'
b5bbe64a 902 { $$ = sawparens(newNULLLIST()); }
79072805 903 | scalar %prec '('
8d063cd8 904 { $$ = $1; }
79072805 905 | star %prec '('
8d063cd8 906 { $$ = $1; }
79072805 907 | hsh %prec '('
8d063cd8 908 { $$ = $1; }
79072805 909 | ary %prec '('
8d063cd8 910 { $$ = $1; }
891be019 911 | arylen %prec '(' /* $#x, $#{ something } */
79072805 912 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
fad39ff1
SM
913 | subscripted
914 { $$ = $1; }
89f35911 915 | sliceme '[' expr ']' /* array slice */
2fcb4757 916 { $$ = op_prepend_elem(OP_ASLICE,
79072805 917 newOP(OP_PUSHMARK, 0),
79072805
LW
918 newLISTOP(OP_ASLICE, 0,
919 list($3),
f05e27e5 920 ref($1, OP_ASLICE)));
429a2555
FC
921 if ($$ && $1)
922 $$->op_private |=
923 $1->op_private & OPpSLICEWARNING;
f05e27e5 924 }
76eba8ab 925 | kvslice '[' expr ']' /* array key/value slice */
6dd3e0f2
RZ
926 { $$ = op_prepend_elem(OP_KVASLICE,
927 newOP(OP_PUSHMARK, 0),
928 newLISTOP(OP_KVASLICE, 0,
929 list($3),
930 ref(oopsAV($1), OP_KVASLICE)));
95a31aad
FC
931 if ($$ && $1)
932 $$->op_private |=
933 $1->op_private & OPpSLICEWARNING;
6dd3e0f2 934 }
89f35911 935 | sliceme '{' expr ';' '}' /* @hash{@keys} */
2fcb4757 936 { $$ = op_prepend_elem(OP_HSLICE,
79072805 937 newOP(OP_PUSHMARK, 0),
79072805
LW
938 newLISTOP(OP_HSLICE, 0,
939 list($3),
a0d0e21e 940 ref(oopsHV($1), OP_HSLICE)));
429a2555
FC
941 if ($$ && $1)
942 $$->op_private |=
943 $1->op_private & OPpSLICEWARNING;
f05e27e5 944 }
76eba8ab 945 | kvslice '{' expr ';' '}' /* %hash{@keys} */
5cae3edb
RZ
946 { $$ = op_prepend_elem(OP_KVHSLICE,
947 newOP(OP_PUSHMARK, 0),
948 newLISTOP(OP_KVHSLICE, 0,
949 list($3),
950 ref($1, OP_KVHSLICE)));
95a31aad
FC
951 if ($$ && $1)
952 $$->op_private |=
953 $1->op_private & OPpSLICEWARNING;
5cae3edb 954 }
79072805
LW
955 | THING %prec '('
956 { $$ = $1; }
891be019 957 | amper /* &foo; */
c07a80fd 958 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
fb602e32 959 | amper '(' ')' /* &foo() or foo() */
f05e27e5 960 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
f05e27e5 961 }
fb602e32 962 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
f05e27e5
DM
963 {
964 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 965 op_append_elem(OP_LIST, $3, scalar($1)));
f05e27e5 966 }
fb602e32 967 | NOAMP subname optlistexpr /* foo @args (no parens) */
a0d0e21e 968 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 969 op_append_elem(OP_LIST, $3, scalar($2)));
f05e27e5 970 }
89f35911 971 | term ARROW '$' '*'
b5bbe64a 972 { $$ = newSVREF($1); }
89f35911 973 | term ARROW '@' '*'
b5bbe64a 974 { $$ = newAVREF($1); }
89f35911 975 | term ARROW '%' '*'
b5bbe64a 976 { $$ = newHVREF($1); }
89f35911
FC
977 | term ARROW '&' '*'
978 { $$ = newUNOP(OP_ENTERSUB, 0,
b5bbe64a 979 scalar(newCVREF($3,$1))); }
89f35911 980 | term ARROW '*' '*' %prec '('
b5bbe64a 981 { $$ = newGVREF(0,$1); }
891be019 982 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
b5bbe64a
JH
983 { $$ = newOP($1, OPf_SPECIAL);
984 PL_hints |= HINT_BLOCK_SCOPE; }
a0d0e21e 985 | LOOPEX term
b5bbe64a 986 { $$ = newLOOPEX($1,$2); }
09b1cffe 987 | NOTOP listexpr /* not $foo */
b5bbe64a 988 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 989 | UNIOP /* Unary op, $_ implied */
b5bbe64a 990 { $$ = newOP($1, 0); }
f05e27e5 991 | UNIOP block /* eval { foo }* */
b5bbe64a 992 { $$ = newUNOP($1, 0, $2); }
891be019 993 | UNIOP term /* Unary op */
b5bbe64a 994 { $$ = newUNOP($1, 0, $2); }
d2fdf8fd 995 | REQUIRE /* require, $_ implied */
b5bbe64a 996 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
d2fdf8fd 997 | REQUIRE term /* require Foo */
b5bbe64a 998 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
3cd0a11a
RGS
999 | UNIOPSUB
1000 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 1001 | UNIOPSUB term /* Sub treated as unop */
4633a7c4 1002 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 1003 op_append_elem(OP_LIST, $2, scalar($1))); }
891be019 1004 | FUNC0 /* Nullary operator */
b5bbe64a 1005 { $$ = newOP($1, 0); }
ae986130 1006 | FUNC0 '(' ')'
b5bbe64a 1007 { $$ = newOP($1, 0);}
7eb971ee
FC
1008 | FUNC0OP /* Same as above, but op created in toke.c */
1009 { $$ = $1; }
1010 | FUNC0OP '(' ')'
b5bbe64a 1011 { $$ = $1; }
891be019 1012 | FUNC0SUB /* Sub treated as nullop */
b5bbe64a 1013 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 1014 | FUNC1 '(' ')' /* not () */
b5bbe64a
JH
1015 { $$ = ($1 == OP_NOT)
1016 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1017 : newOP($1, OPf_SPECIAL); }
891be019 1018 | FUNC1 '(' expr ')' /* not($foo) */
b5bbe64a 1019 { $$ = newUNOP($1, 0, $3); }
d63c20f2
DM
1020 | PMFUNC /* m//, s///, qr//, tr/// */
1021 {
1022 if ( $1->op_type != OP_TRANS
1023 && $1->op_type != OP_TRANSR
1024 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
1025 {
1026 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1027 SAVEFREESV(PL_compcv);
1028 } else
1029 $<ival>$ = 0;
1030 }
9b6b7be8
FC
1031 '(' listexpr optrepl ')'
1032 { $$ = pmruntime($1, $4, $5, 1, $<ival>2); }
79072805 1033 | WORD
378cc40b 1034 | listop
be25f609 1035 | YADAYADA
1036 {
1037 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1038 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1039 }
88e1f1a2 1040 | PLUGEXPR
8d063cd8
LW
1041 ;
1042
891be019 1043/* "my" declarations, with optional attributes */
09bef843 1044myattrterm: MY myterm myattrlist
b5bbe64a 1045 { $$ = my_attrs($2,$3); }
09bef843 1046 | MY myterm
b5bbe64a 1047 { $$ = localize($2,$1); }
09bef843
SB
1048 ;
1049
891be019 1050/* Things that can be "my"'d */
09bef843 1051myterm : '(' expr ')'
b5bbe64a 1052 { $$ = sawparens($2); }
09bef843 1053 | '(' ')'
b5bbe64a
JH
1054 { $$ = sawparens(newNULLLIST()); }
1055
09bef843
SB
1056 | scalar %prec '('
1057 { $$ = $1; }
1058 | hsh %prec '('
1059 { $$ = $1; }
1060 | ary %prec '('
1061 { $$ = $1; }
1062 ;
1063
891be019 1064/* Basic list expressions */
09b1cffe 1065optlistexpr: /* NULL */ %prec PREC_LOW
bcabcc50 1066 { $$ = (OP*)NULL; }
09b1cffe 1067 | listexpr %prec PREC_LOW
a0d0e21e
LW
1068 { $$ = $1; }
1069 ;
1070
09b1cffe 1071optexpr: /* NULL */
bcabcc50 1072 { $$ = (OP*)NULL; }
79072805
LW
1073 | expr
1074 { $$ = $1; }
1075 ;
1076
9b6b7be8
FC
1077optrepl: /* NULL */
1078 { $$ = (OP*)NULL; }
1079 | '/' expr
1080 { $$ = $2; }
1081 ;
1082
891be019
SC
1083/* A little bit of trickery to make "for my $foo (@bar)" actually be
1084 lexical */
55497cff 1085my_scalar: scalar
624fa8bd 1086 { parser->in_my = 0; $$ = my($1); }
55497cff
PP
1087 ;
1088
d39c26a6
FC
1089my_var : scalar
1090 | ary
1091 | hsh
1092 ;
1093
1094refgen_topic: my_var
1095 | amper
1096 ;
1097
79072805 1098amper : '&' indirob
b5bbe64a 1099 { $$ = newCVREF($1,$2); }
a687059c
LW
1100 ;
1101
79072805 1102scalar : '$' indirob
b5bbe64a 1103 { $$ = newSVREF($2); }
a687059c
LW
1104 ;
1105
79072805 1106ary : '@' indirob
f05e27e5 1107 { $$ = newAVREF($2);
b5bbe64a 1108 if ($$) $$->op_private |= $1;
f05e27e5 1109 }
79072805
LW
1110 ;
1111
1112hsh : '%' indirob
f05e27e5 1113 { $$ = newHVREF($2);
b5bbe64a 1114 if ($$) $$->op_private |= $1;
f05e27e5 1115 }
79072805
LW
1116 ;
1117
1118arylen : DOLSHARP indirob
b5bbe64a 1119 { $$ = newAVREF($2); }
ff25e5db 1120 | term ARROW DOLSHARP '*'
b5bbe64a 1121 { $$ = newAVREF($1); }
79072805
LW
1122 ;
1123
1124star : '*' indirob
b5bbe64a 1125 { $$ = newGVREF(0,$2); }
79072805
LW
1126 ;
1127
89f35911
FC
1128sliceme : ary
1129 | term ARROW '@'
b5bbe64a 1130 { $$ = newAVREF($1); }
89f35911
FC
1131 ;
1132
76eba8ab
FC
1133kvslice : hsh
1134 | term ARROW '%'
b5bbe64a 1135 { $$ = newHVREF($1); }
76eba8ab
FC
1136 ;
1137
89f35911
FC
1138gelem : star
1139 | term ARROW '*'
b5bbe64a 1140 { $$ = newGVREF(0,$1); }
89f35911
FC
1141 ;
1142
891be019 1143/* Indirect objects */
79072805
LW
1144indirob : WORD
1145 { $$ = scalar($1); }
fad39ff1 1146 | scalar %prec PREC_LOW
f05e27e5 1147 { $$ = scalar($1); }
79072805 1148 | block
3ad73efd 1149 { $$ = op_scope($1); }
79072805 1150
93a17b20
LW
1151 | PRIVATEREF
1152 { $$ = $1; }
8d063cd8 1153 ;