This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Um, finish reordering the parser struct
[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
f39ff1f3 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
185c2e96 50%token <opval> BAREWORD 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
08b3e84f 72%type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
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 }
185c2e96 339 | PACKAGE BAREWORD BAREWORD ';'
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 {} */ }
185c2e96 348 BAREWORD BAREWORD 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 }
08b3e84f 361 | UNLESS '(' remember mexpr ')' mblock else
eae48c89 362 {
3ad73efd 363 $$ = block_end($3,
08b3e84f 364 newCONDOP(0, $4, $7, op_scope($6)));
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 }
e118fea3
FC
421 | FOR my_refgen remember my_var
422 { parser->in_my = 0; $<opval>$ = my($4); }
d39c26a6
FC
423 '(' mexpr ')' mblock cont
424 {
425 $$ = block_end(
e118fea3 426 $3,
d39c26a6
FC
427 newFOROP(0,
428 op_lvalue(
429 newUNOP(OP_REFGEN, 0,
e118fea3 430 $<opval>5),
d39c26a6 431 OP_ENTERLOOP),
e118fea3 432 $7, $9, $10)
d39c26a6
FC
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 455 }
185c2e96 456 | PACKAGE BAREWORD BAREWORD '{' remember
eae48c89 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
185c2e96 584formname: BAREWORD { $$ = $1; }
bcabcc50 585 | /* NULL */ { $$ = (OP*)NULL; }
8d063cd8
LW
586 ;
587
fa83b5b6 588startsub: /* NULL */ /* start a regular subroutine scope */
a8ff2fa6
DM
589 { $$ = start_subparse(FALSE, 0);
590 SAVEFREESV(PL_compcv); }
f05e27e5 591
28757baa
PP
592 ;
593
594startanonsub: /* NULL */ /* start an anonymous subroutine scope */
a8ff2fa6
DM
595 { $$ = start_subparse(FALSE, CVf_ANON);
596 SAVEFREESV(PL_compcv); }
28757baa
PP
597 ;
598
44a8e56a 599startformsub: /* NULL */ /* start a format subroutine scope */
a8ff2fa6
DM
600 { $$ = start_subparse(TRUE, 0);
601 SAVEFREESV(PL_compcv); }
44a8e56a
PP
602 ;
603
891be019 604/* Name of a subroutine - must be a bareword, could be special */
185c2e96 605subname : BAREWORD
4210d3f1 606 | PRIVATEREF
a0d0e21e
LW
607 ;
608
891be019 609/* Subroutine prototype */
4633a7c4 610proto : /* NULL */
bcabcc50 611 { $$ = (OP*)NULL; }
4633a7c4
LW
612 | THING
613 ;
28757baa 614
891be019 615/* Optional list of subroutine attributes */
09bef843 616subattrlist: /* NULL */
bcabcc50 617 { $$ = (OP*)NULL; }
09bef843 618 | COLONATTR THING
b5bbe64a 619 { $$ = $2; }
09bef843 620 | COLONATTR
b5bbe64a 621 { $$ = (OP*)NULL; }
09bef843
SB
622 ;
623
891be019 624/* List of attributes for a "my" variable declaration */
09bef843 625myattrlist: COLONATTR THING
b5bbe64a 626 { $$ = $2; }
09bef843 627 | COLONATTR
b5bbe64a 628 { $$ = (OP*)NULL; }
09bef843
SB
629 ;
630
abcf453d
PM
631/* Subroutine signature */
632subsignature: '('
30d9c59b 633 {
abcf453d
PM
634 /* We shouldn't get here otherwise */
635 assert(FEATURE_SIGNATURES_IS_ENABLED);
636
30d9c59b
Z
637 Perl_ck_warner_d(aTHX_
638 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
639 "The signatures feature is experimental");
640 $<opval>$ = parse_subsignature();
641 }
642 ')'
643 {
644 $$ = op_append_list(OP_LINESEQ, $<opval>2,
645 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
abcf453d 646 parser->expect = XATTRBLOCK;
30d9c59b
Z
647 }
648 ;
649
650/* Optional subroutine body, for named subroutine declaration */
abcf453d 651optsubbody: block
2d0e3c96 652 | ';' { $$ = (OP*)NULL; }
8d063cd8
LW
653 ;
654
891be019 655/* Ordinary expressions; logical combinations */
a0d0e21e 656expr : expr ANDOP expr
b5bbe64a 657 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
a0d0e21e 658 | expr OROP expr
b5bbe64a 659 { $$ = newLOGOP($2, 0, $1, $3); }
c963b151 660 | expr DOROP expr
b5bbe64a 661 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
09b1cffe 662 | listexpr %prec PREC_LOW
a0d0e21e
LW
663 ;
664
891be019 665/* Expressions are a list of terms joined by commas */
09b1cffe 666listexpr: listexpr ','
b5bbe64a 667 { $$ = $1; }
09b1cffe 668 | listexpr ',' term
abcf453d 669 {
29522234 670 OP* term = $3;
2fcb4757 671 $$ = op_append_elem(OP_LIST, $1, term);
f05e27e5 672 }
fad39ff1 673 | term %prec PREC_LOW
8d063cd8
LW
674 ;
675
891be019 676/* List operators */
09b1cffe 677listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
03d05f6e 678 { $$ = op_convert_list($1, OPf_STACKED,
b5bbe64a 679 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
f05e27e5 680 }
891be019 681 | FUNC '(' indirob expr ')' /* print ($fh @args */
03d05f6e 682 { $$ = op_convert_list($1, OPf_STACKED,
b5bbe64a 683 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
f05e27e5 684 }
417a992d 685 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
03d05f6e 686 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
687 op_append_elem(OP_LIST,
688 op_prepend_elem(OP_LIST, scalar($1), $5),
b46e009d 689 newMETHOP(OP_METHOD, 0, $3)));
f05e27e5 690 }
891be019 691 | term ARROW method /* $foo->bar */
03d05f6e 692 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757 693 op_append_elem(OP_LIST, scalar($1),
b46e009d 694 newMETHOP(OP_METHOD, 0, $3)));
f05e27e5 695 }
09b1cffe 696 | METHOD indirob optlistexpr /* new Class @args */
03d05f6e 697 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
698 op_append_elem(OP_LIST,
699 op_prepend_elem(OP_LIST, $2, $3),
b46e009d 700 newMETHOP(OP_METHOD, 0, $1)));
f05e27e5 701 }
09b1cffe 702 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
03d05f6e 703 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
704 op_append_elem(OP_LIST,
705 op_prepend_elem(OP_LIST, $2, $4),
b46e009d 706 newMETHOP(OP_METHOD, 0, $1)));
f05e27e5 707 }
09b1cffe 708 | LSTOP optlistexpr /* print @args */
03d05f6e 709 { $$ = op_convert_list($1, 0, $2); }
09b1cffe 710 | FUNC '(' optexpr ')' /* print (@args) */
03d05f6e 711 { $$ = op_convert_list($1, 0, $3); }
718a7425 712 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
5a5094bd 713 { SvREFCNT_inc_simple_void(PL_compcv);
bcabcc50 714 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
09b1cffe 715 optlistexpr %prec LSTOP /* ... @bar */
4633a7c4 716 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
717 op_append_elem(OP_LIST,
718 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
f05e27e5 719 }
a687059c
LW
720 ;
721
891be019 722/* Names of methods. May use $object->$methodname */
a0d0e21e
LW
723method : METHOD
724 | scalar
725 ;
726
891be019 727/* Some kind of subscripted expression */
89f35911 728subscripted: gelem '{' expr ';' '}' /* *main::{something} */
891be019
SC
729 /* In this and all the hash accessors, ';' is
730 * provided by the tokeniser */
5c86b6df 731 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
891be019 732 | scalar '[' expr ']' /* $array[$element] */
f05e27e5 733 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
f05e27e5 734 }
891be019 735 | term ARROW '[' expr ']' /* somearef->[$element] */
fad39ff1
SM
736 { $$ = newBINOP(OP_AELEM, 0,
737 ref(newAVREF($1),OP_RV2AV),
f05e27e5 738 scalar($4));
f05e27e5 739 }
891be019 740 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
fad39ff1
SM
741 { $$ = newBINOP(OP_AELEM, 0,
742 ref(newAVREF($1),OP_RV2AV),
f05e27e5 743 scalar($3));
f05e27e5 744 }
5a63ceef 745 | scalar '{' expr ';' '}' /* $foo{bar();} */
fad39ff1 746 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
f05e27e5 747 }
891be019 748 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
fad39ff1
SM
749 { $$ = newBINOP(OP_HELEM, 0,
750 ref(newHVREF($1),OP_RV2HV),
5c86b6df 751 jmaybe($4)); }
891be019 752 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
fad39ff1
SM
753 { $$ = newBINOP(OP_HELEM, 0,
754 ref(newHVREF($1),OP_RV2HV),
5c86b6df 755 jmaybe($3)); }
891be019 756 | term ARROW '(' ')' /* $subref->() */
fad39ff1 757 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 758 newCVREF(0, scalar($1))); }
891be019 759 | term ARROW '(' expr ')' /* $subref->(@args) */
fad39ff1 760 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 761 op_append_elem(OP_LIST, $4,
b5bbe64a 762 newCVREF(0, scalar($1)))); }
fad39ff1 763
417a992d 764 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
fad39ff1 765 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 766 op_append_elem(OP_LIST, $3,
b5bbe64a 767 newCVREF(0, scalar($1)))); }
417a992d 768 | subscripted '(' ')' /* $foo->{bar}->() */
fad39ff1 769 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 770 newCVREF(0, scalar($1))); }
9a9798c2 771 | '(' expr ')' '[' expr ']' /* list slice */
b5bbe64a 772 { $$ = newSLICEOP(0, $5, $2); }
ea25a9b2 773 | QWLIST '[' expr ']' /* list literal slice */
b5bbe64a 774 { $$ = newSLICEOP(0, $3, $1); }
9a9798c2 775 | '(' ')' '[' expr ']' /* empty list slice! */
b5bbe64a 776 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
891be019 777 ;
fad39ff1 778
891be019 779/* Binary operators between terms */
f05e27e5 780termbinop: term ASSIGNOP term /* $x = $y */
b5bbe64a 781 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
891be019 782 | term POWOP term /* $x ** $y */
b5bbe64a 783 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 784 | term MULOP term /* $x * $y, $x x $y */
b5bbe64a 785 { if ($2 != OP_REPEAT)
79072805 786 scalar($1);
b5bbe64a 787 $$ = newBINOP($2, 0, $1, scalar($3));
f05e27e5 788 }
891be019 789 | term ADDOP term /* $x + $y */
b5bbe64a 790 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 791 | term SHIFTOP term /* $x >> $y, $x << $y */
b5bbe64a 792 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 793 | term RELOP term /* $x > $y, etc. */
b5bbe64a 794 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 795 | term EQOP term /* $x == $y, $x eq $y */
b5bbe64a 796 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 797 | term BITANDOP term /* $x & $y */
b5bbe64a 798 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 799 | term BITOROP term /* $x | $y */
b5bbe64a 800 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 801 | term DOTDOT term /* $x..$y, $x...$y */
b5bbe64a 802 { $$ = newRANGE($2, scalar($1), scalar($3)); }
891be019 803 | term ANDAND term /* $x && $y */
b5bbe64a 804 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
891be019 805 | term OROR term /* $x || $y */
b5bbe64a 806 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
c963b151 807 | term DORDOR term /* $x // $y */
b5bbe64a 808 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
891be019 809 | term MATCHOP term /* $x =~ /$y/ */
b5bbe64a 810 { $$ = bind_match($2, $1, $3); }
891be019 811 ;
8d063cd8 812
891be019
SC
813/* Unary operators and terms */
814termunop : '-' term %prec UMINUS /* -$x */
b5bbe64a 815 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
891be019 816 | '+' term %prec UMINUS /* +$x */
b5bbe64a
JH
817 { $$ = $2; }
818
891be019 819 | '!' term /* !$x */
b5bbe64a 820 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 821 | '~' term /* ~$x */
8823cb89 822 { $$ = newUNOP($1, 0, scalar($2)); }
891be019 823 | term POSTINC /* $x++ */
79072805 824 { $$ = newUNOP(OP_POSTINC, 0,
b5bbe64a 825 op_lvalue(scalar($1), OP_POSTINC)); }
891be019 826 | term POSTDEC /* $x-- */
79072805 827 { $$ = newUNOP(OP_POSTDEC, 0,
b5bbe64a 828 op_lvalue(scalar($1), OP_POSTDEC));}
cc624add 829 | term POSTJOIN /* implicit join after interpolated ->@ */
03d05f6e 830 { $$ = op_convert_list(OP_JOIN, 0,
cc624add
FC
831 op_append_elem(
832 OP_LIST,
833 newSVREF(scalar(
834 newSVOP(OP_CONST,0,
835 newSVpvs("\""))
836 )),
837 $1
838 ));
cc624add 839 }
891be019 840 | PREINC term /* ++$x */
79072805 841 { $$ = newUNOP(OP_PREINC, 0,
b5bbe64a 842 op_lvalue(scalar($2), OP_PREINC)); }
891be019 843 | PREDEC term /* --$x */
79072805 844 { $$ = newUNOP(OP_PREDEC, 0,
b5bbe64a 845 op_lvalue(scalar($2), OP_PREDEC)); }
891be019
SC
846
847 ;
848
849/* Constructors for anonymous data */
850anonymous: '[' expr ']'
b5bbe64a 851 { $$ = newANONLIST($2); }
891be019 852 | '[' ']'
b5bbe64a 853 { $$ = newANONLIST((OP*)NULL);}
891be019 854 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
b5bbe64a 855 { $$ = newANONHASH($2); }
891be019 856 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
b5bbe64a 857 { $$ = newANONHASH((OP*)NULL); }
abcf453d 858 | ANONSUB startanonsub proto subattrlist block %prec '('
5a5094bd 859 { SvREFCNT_inc_simple_void(PL_compcv);
b5bbe64a 860 $$ = newANONATTRSUB($2, $3, $4, $5); }
abcf453d
PM
861 | ANONSUB startanonsub remember subsignature subattrlist '{' stmtseq '}' %prec '('
862 {
863 OP *body;
864 if (parser->copline > (line_t)$6)
865 parser->copline = (line_t)$6;
866 body = block_end($3,
867 op_append_list(OP_LINESEQ, $4, $7));
868 SvREFCNT_inc_simple_void(PL_compcv);
869 $$ = newANONATTRSUB($2, NULL, $5, body);
870 }
891be019
SC
871
872 ;
873
874/* Things called with "do" */
875termdo : DO term %prec UNIOP /* do $filename */
b5bbe64a 876 { $$ = dofile($2, $1);}
891be019 877 | DO block %prec '(' /* do { code */
b5bbe64a 878 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
891be019
SC
879 ;
880
881term : termbinop
882 | termunop
883 | anonymous
884 | termdo
e9bdcc27 885 | term '?' term ':' term
b5bbe64a 886 { $$ = newCONDOP(0, $1, $3, $5); }
891be019 887 | REFGEN term /* \$x, \@y, \%z */
070d3cb6 888 { $$ = newUNOP(OP_REFGEN, 0, $2); }
e118fea3
FC
889 | MY REFGEN term
890 { $$ = newUNOP(OP_REFGEN, 0, localize($3,1)); }
09bef843
SB
891 | myattrterm %prec UNIOP
892 { $$ = $1; }
893 | LOCAL term %prec UNIOP
28383d1a 894 { $$ = localize($2,0); }
a0d0e21e 895 | '(' expr ')'
b5bbe64a 896 { $$ = sawparens($2); }
ea25a9b2 897 | QWLIST
b5bbe64a 898 { $$ = $1; }
8d063cd8 899 | '(' ')'
b5bbe64a 900 { $$ = sawparens(newNULLLIST()); }
79072805 901 | scalar %prec '('
8d063cd8 902 { $$ = $1; }
79072805 903 | star %prec '('
8d063cd8 904 { $$ = $1; }
79072805 905 | hsh %prec '('
8d063cd8 906 { $$ = $1; }
79072805 907 | ary %prec '('
8d063cd8 908 { $$ = $1; }
891be019 909 | arylen %prec '(' /* $#x, $#{ something } */
79072805 910 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
fad39ff1
SM
911 | subscripted
912 { $$ = $1; }
89f35911 913 | sliceme '[' expr ']' /* array slice */
2fcb4757 914 { $$ = op_prepend_elem(OP_ASLICE,
79072805 915 newOP(OP_PUSHMARK, 0),
79072805
LW
916 newLISTOP(OP_ASLICE, 0,
917 list($3),
f05e27e5 918 ref($1, OP_ASLICE)));
429a2555
FC
919 if ($$ && $1)
920 $$->op_private |=
921 $1->op_private & OPpSLICEWARNING;
f05e27e5 922 }
76eba8ab 923 | kvslice '[' expr ']' /* array key/value slice */
6dd3e0f2
RZ
924 { $$ = op_prepend_elem(OP_KVASLICE,
925 newOP(OP_PUSHMARK, 0),
926 newLISTOP(OP_KVASLICE, 0,
927 list($3),
928 ref(oopsAV($1), OP_KVASLICE)));
95a31aad
FC
929 if ($$ && $1)
930 $$->op_private |=
931 $1->op_private & OPpSLICEWARNING;
6dd3e0f2 932 }
89f35911 933 | sliceme '{' expr ';' '}' /* @hash{@keys} */
2fcb4757 934 { $$ = op_prepend_elem(OP_HSLICE,
79072805 935 newOP(OP_PUSHMARK, 0),
79072805
LW
936 newLISTOP(OP_HSLICE, 0,
937 list($3),
a0d0e21e 938 ref(oopsHV($1), OP_HSLICE)));
429a2555
FC
939 if ($$ && $1)
940 $$->op_private |=
941 $1->op_private & OPpSLICEWARNING;
f05e27e5 942 }
76eba8ab 943 | kvslice '{' expr ';' '}' /* %hash{@keys} */
5cae3edb
RZ
944 { $$ = op_prepend_elem(OP_KVHSLICE,
945 newOP(OP_PUSHMARK, 0),
946 newLISTOP(OP_KVHSLICE, 0,
947 list($3),
948 ref($1, OP_KVHSLICE)));
95a31aad
FC
949 if ($$ && $1)
950 $$->op_private |=
951 $1->op_private & OPpSLICEWARNING;
5cae3edb 952 }
79072805
LW
953 | THING %prec '('
954 { $$ = $1; }
891be019 955 | amper /* &foo; */
c07a80fd 956 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
fb602e32 957 | amper '(' ')' /* &foo() or foo() */
f05e27e5 958 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
f05e27e5 959 }
fb602e32 960 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
f05e27e5
DM
961 {
962 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 963 op_append_elem(OP_LIST, $3, scalar($1)));
f05e27e5 964 }
fb602e32 965 | NOAMP subname optlistexpr /* foo @args (no parens) */
a0d0e21e 966 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 967 op_append_elem(OP_LIST, $3, scalar($2)));
f05e27e5 968 }
89f35911 969 | term ARROW '$' '*'
b5bbe64a 970 { $$ = newSVREF($1); }
89f35911 971 | term ARROW '@' '*'
b5bbe64a 972 { $$ = newAVREF($1); }
89f35911 973 | term ARROW '%' '*'
b5bbe64a 974 { $$ = newHVREF($1); }
89f35911
FC
975 | term ARROW '&' '*'
976 { $$ = newUNOP(OP_ENTERSUB, 0,
b5bbe64a 977 scalar(newCVREF($3,$1))); }
89f35911 978 | term ARROW '*' '*' %prec '('
b5bbe64a 979 { $$ = newGVREF(0,$1); }
891be019 980 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
b5bbe64a
JH
981 { $$ = newOP($1, OPf_SPECIAL);
982 PL_hints |= HINT_BLOCK_SCOPE; }
a0d0e21e 983 | LOOPEX term
b5bbe64a 984 { $$ = newLOOPEX($1,$2); }
09b1cffe 985 | NOTOP listexpr /* not $foo */
b5bbe64a 986 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 987 | UNIOP /* Unary op, $_ implied */
b5bbe64a 988 { $$ = newOP($1, 0); }
f05e27e5 989 | UNIOP block /* eval { foo }* */
b5bbe64a 990 { $$ = newUNOP($1, 0, $2); }
891be019 991 | UNIOP term /* Unary op */
b5bbe64a 992 { $$ = newUNOP($1, 0, $2); }
d2fdf8fd 993 | REQUIRE /* require, $_ implied */
b5bbe64a 994 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
d2fdf8fd 995 | REQUIRE term /* require Foo */
b5bbe64a 996 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
3cd0a11a
RGS
997 | UNIOPSUB
998 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 999 | UNIOPSUB term /* Sub treated as unop */
4633a7c4 1000 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 1001 op_append_elem(OP_LIST, $2, scalar($1))); }
891be019 1002 | FUNC0 /* Nullary operator */
b5bbe64a 1003 { $$ = newOP($1, 0); }
ae986130 1004 | FUNC0 '(' ')'
b5bbe64a 1005 { $$ = newOP($1, 0);}
7eb971ee
FC
1006 | FUNC0OP /* Same as above, but op created in toke.c */
1007 { $$ = $1; }
1008 | FUNC0OP '(' ')'
b5bbe64a 1009 { $$ = $1; }
891be019 1010 | FUNC0SUB /* Sub treated as nullop */
b5bbe64a 1011 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 1012 | FUNC1 '(' ')' /* not () */
b5bbe64a
JH
1013 { $$ = ($1 == OP_NOT)
1014 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1015 : newOP($1, OPf_SPECIAL); }
891be019 1016 | FUNC1 '(' expr ')' /* not($foo) */
b5bbe64a 1017 { $$ = newUNOP($1, 0, $3); }
d63c20f2
DM
1018 | PMFUNC /* m//, s///, qr//, tr/// */
1019 {
1020 if ( $1->op_type != OP_TRANS
1021 && $1->op_type != OP_TRANSR
1022 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
1023 {
1024 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1025 SAVEFREESV(PL_compcv);
1026 } else
1027 $<ival>$ = 0;
1028 }
9b6b7be8
FC
1029 '(' listexpr optrepl ')'
1030 { $$ = pmruntime($1, $4, $5, 1, $<ival>2); }
185c2e96 1031 | BAREWORD
378cc40b 1032 | listop
be25f609 1033 | YADAYADA
1034 {
1035 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1036 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1037 }
88e1f1a2 1038 | PLUGEXPR
8d063cd8
LW
1039 ;
1040
891be019 1041/* "my" declarations, with optional attributes */
09bef843 1042myattrterm: MY myterm myattrlist
b5bbe64a 1043 { $$ = my_attrs($2,$3); }
09bef843 1044 | MY myterm
28383d1a 1045 { $$ = localize($2,1); }
e118fea3
FC
1046 | MY REFGEN myterm myattrlist
1047 { $$ = newUNOP(OP_REFGEN, 0, my_attrs($3,$4)); }
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
e118fea3
FC
1098my_refgen: MY REFGEN
1099 | REFGEN MY
1100 ;
1101
79072805 1102amper : '&' indirob
b5bbe64a 1103 { $$ = newCVREF($1,$2); }
a687059c
LW
1104 ;
1105
79072805 1106scalar : '$' indirob
b5bbe64a 1107 { $$ = newSVREF($2); }
a687059c
LW
1108 ;
1109
79072805 1110ary : '@' indirob
f05e27e5 1111 { $$ = newAVREF($2);
b5bbe64a 1112 if ($$) $$->op_private |= $1;
f05e27e5 1113 }
79072805
LW
1114 ;
1115
1116hsh : '%' indirob
f05e27e5 1117 { $$ = newHVREF($2);
b5bbe64a 1118 if ($$) $$->op_private |= $1;
f05e27e5 1119 }
79072805
LW
1120 ;
1121
1122arylen : DOLSHARP indirob
b5bbe64a 1123 { $$ = newAVREF($2); }
ff25e5db 1124 | term ARROW DOLSHARP '*'
b5bbe64a 1125 { $$ = newAVREF($1); }
79072805
LW
1126 ;
1127
1128star : '*' indirob
b5bbe64a 1129 { $$ = newGVREF(0,$2); }
79072805
LW
1130 ;
1131
89f35911
FC
1132sliceme : ary
1133 | term ARROW '@'
b5bbe64a 1134 { $$ = newAVREF($1); }
89f35911
FC
1135 ;
1136
76eba8ab
FC
1137kvslice : hsh
1138 | term ARROW '%'
b5bbe64a 1139 { $$ = newHVREF($1); }
76eba8ab
FC
1140 ;
1141
89f35911
FC
1142gelem : star
1143 | term ARROW '*'
b5bbe64a 1144 { $$ = newGVREF(0,$1); }
89f35911
FC
1145 ;
1146
891be019 1147/* Indirect objects */
185c2e96 1148indirob : BAREWORD
79072805 1149 { $$ = scalar($1); }
fad39ff1 1150 | scalar %prec PREC_LOW
f05e27e5 1151 { $$ = scalar($1); }
79072805 1152 | block
3ad73efd 1153 { $$ = op_scope($1); }
79072805 1154
93a17b20
LW
1155 | PRIVATEREF
1156 { $$ = $1; }
8d063cd8 1157 ;