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