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