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