This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate post-beta tweaks to ansiperl
[perl5.git] / perly.y
CommitLineData
a0d0e21e 1/* perly.y
a687059c 2 *
9607fc9c 3 * Copyright (c) 1991-1997, Larry Wall
a687059c 4 *
9ef589d8
LW
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
8d063cd8 7 *
a0d0e21e
LW
8 */
9
10/*
11 * 'I see,' laughed Strider. 'I look foul and feel fair. Is that it?
14a38fd5 12 * All that is gold does not glitter, not all those who wander are lost.'
8d063cd8
LW
13 */
14
15%{
79072805 16#include "EXTERN.h"
8d063cd8 17#include "perl.h"
378cc40b 18
a0d0e21e 19static void
8ac85365 20dep(void)
a0d0e21e
LW
21{
22 deprecate("\"do\" to call subroutines");
23}
f0fcb552 24
8d063cd8
LW
25%}
26
27%start prog
28
29%union {
79072805
LW
30 I32 ival;
31 char *pval;
32 OP *opval;
33 GV *gvval;
8d063cd8
LW
34}
35
f0fcb552
LW
36%token <ival> '{' ')'
37
a0d0e21e 38%token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF
4633a7c4 39%token <opval> FUNC0SUB UNIOPSUB LSTOPSUB
79072805 40%token <pval> LABEL
a0d0e21e 41%token <ival> FORMAT SUB ANONSUB PACKAGE USE
79072805
LW
42%token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
43%token <ival> LOOPEX DOTDOT
36477c24 44%token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
79072805 45%token <ival> RELOP EQOP MULOP ADDOP
55497cff
PP
46%token <ival> DOLSHARP DO HASHBRACK NOAMP
47%token LOCAL MY
79072805 48
44a8e56a 49%type <ival> prog decl local format startsub startanonsub startformsub
28757baa 50%type <ival> remember mremember '&'
bbce6d69 51%type <opval> block mblock lineseq line loop cond else
a0d0e21e 52%type <opval> expr term scalar ary hsh arylen star amper sideff
bbce6d69 53%type <opval> argexpr nexpr texpr iexpr mexpr mnexpr mtexpr miexpr
44a8e56a
PP
54%type <opval> listexpr listexprcom indirob listop method
55%type <opval> formname subname proto subbody cont my_scalar
79072805 56%type <pval> label
79072805 57
a0d0e21e 58%left <ival> OROP
463ee0b2 59%left ANDOP
c07a80fd 60%right NOTOP
36477c24 61%nonassoc LSTOP LSTOPSUB
8d063cd8 62%left ','
a0d0e21e 63%right <ival> ASSIGNOP
8d063cd8
LW
64%right '?' ':'
65%nonassoc DOTDOT
66%left OROR
67%left ANDAND
79072805
LW
68%left <ival> BITOROP
69%left <ival> BITANDOP
a687059c
LW
70%nonassoc EQOP
71%nonassoc RELOP
36477c24 72%nonassoc UNIOP UNIOPSUB
79072805 73%left <ival> SHIFTOP
a687059c
LW
74%left ADDOP
75%left MULOP
8990e307 76%left <ival> MATCHOP
79072805
LW
77%right '!' '~' UMINUS REFGEN
78%right <ival> POWOP
79%nonassoc PREINC PREDEC POSTINC POSTDEC
8990e307 80%left ARROW
8d063cd8
LW
81%left '('
82
83%% /* RULES */
84
ae986130
LW
85prog : /* NULL */
86 {
87#if defined(YYDEBUG) && defined(DEBUGGING)
88 yydebug = (debug & 1);
89#endif
8990e307 90 expect = XSTATE;
ae986130
LW
91 }
92 /*CONTINUED*/ lineseq
a0d0e21e 93 { newPROG($2); }
8d063cd8
LW
94 ;
95
a687059c 96block : '{' remember lineseq '}'
36477c24
PP
97 { if (copline > (line_t)$1)
98 copline = $1;
99 $$ = block_end($2, $3); }
a0d0e21e
LW
100 ;
101
55497cff
PP
102remember: /* NULL */ /* start a full lexical scope */
103 { $$ = block_start(TRUE); }
104 ;
105
bbce6d69 106mblock : '{' mremember lineseq '}'
36477c24
PP
107 { if (copline > (line_t)$1)
108 copline = $1;
109 $$ = block_end($2, $3); }
55497cff
PP
110 ;
111
112mremember: /* NULL */ /* start a partial lexical scope */
113 { $$ = block_start(FALSE); }
8d063cd8
LW
114 ;
115
116lineseq : /* NULL */
79072805
LW
117 { $$ = Nullop; }
118 | lineseq decl
119 { $$ = $1; }
8d063cd8 120 | lineseq line
463ee0b2 121 { $$ = append_list(OP_LINESEQ,
a0d0e21e
LW
122 (LISTOP*)$1, (LISTOP*)$2);
123 pad_reset_pending = TRUE;
85e6fe83 124 if ($1 && $2) hints |= HINT_BLOCK_SCOPE; }
8d063cd8
LW
125 ;
126
79072805
LW
127line : label cond
128 { $$ = newSTATEOP(0, $1, $2); }
8d063cd8
LW
129 | loop /* loops add their own labels */
130 | label ';'
131 { if ($1 != Nullch) {
79072805 132 $$ = newSTATEOP(0, $1, newOP(OP_NULL, 0));
450a55e4
LW
133 }
134 else {
79072805
LW
135 $$ = Nullop;
136 copline = NOLINE;
32c2e4fb 137 }
8990e307 138 expect = XSTATE; }
8d063cd8 139 | label sideff ';'
79072805 140 { $$ = newSTATEOP(0, $1, $2);
8990e307 141 expect = XSTATE; }
8d063cd8
LW
142 ;
143
a687059c 144sideff : error
79072805 145 { $$ = Nullop; }
a687059c 146 | expr
79072805 147 { $$ = $1; }
a687059c 148 | expr IF expr
79072805 149 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
a687059c 150 | expr UNLESS expr
79072805 151 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
a687059c 152 | expr WHILE expr
8990e307 153 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
55497cff
PP
154 | expr UNTIL iexpr
155 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1);}
ecca16b0
CS
156 | expr FOR expr
157 { $$ = newFOROP(0, Nullch, $2,
158 Nullop, $3, $1, Nullop); }
79072805
LW
159 ;
160
161else : /* NULL */
162 { $$ = Nullop; }
55497cff 163 | ELSE mblock
79072805 164 { $$ = scope($2); }
55497cff 165 | ELSIF '(' mexpr ')' mblock else
79072805 166 { copline = $1;
bbce6d69
PP
167 $$ = newSTATEOP(0, Nullch,
168 newCONDOP(0, $3, scope($5), $6));
4633a7c4 169 hints |= HINT_BLOCK_SCOPE; }
79072805
LW
170 ;
171
55497cff 172cond : IF '(' remember mexpr ')' mblock else
79072805 173 { copline = $1;
36477c24 174 $$ = block_end($3,
bbce6d69 175 newCONDOP(0, $4, scope($6), $7)); }
55497cff 176 | UNLESS '(' remember miexpr ')' mblock else
79072805 177 { copline = $1;
36477c24 178 $$ = block_end($3,
bbce6d69 179 newCONDOP(0, $4, scope($6), $7)); }
79072805
LW
180 ;
181
182cont : /* NULL */
183 { $$ = Nullop; }
184 | CONTINUE block
185 { $$ = scope($2); }
186 ;
187
55497cff 188loop : label WHILE '(' remember mtexpr ')' mblock cont
79072805 189 { copline = $2;
36477c24 190 $$ = block_end($4,
55497cff 191 newSTATEOP(0, $1,
bbce6d69 192 newWHILEOP(0, 1, (LOOP*)Nullop,
fb73857a 193 $2, $5, $7, $8))); }
55497cff 194 | label UNTIL '(' remember miexpr ')' mblock cont
79072805 195 { copline = $2;
36477c24 196 $$ = block_end($4,
55497cff 197 newSTATEOP(0, $1,
bbce6d69 198 newWHILEOP(0, 1, (LOOP*)Nullop,
fb73857a 199 $2, $5, $7, $8))); }
bbce6d69 200 | label FOR MY remember my_scalar '(' mexpr ')' mblock cont
36477c24 201 { $$ = block_end($4,
bbce6d69
PP
202 newFOROP(0, $1, $2, $5, $7, $9, $10)); }
203 | label FOR scalar '(' remember mexpr ')' mblock cont
36477c24 204 { $$ = block_end($5,
bbce6d69
PP
205 newFOROP(0, $1, $2, mod($3, OP_ENTERLOOP),
206 $6, $8, $9)); }
207 | label FOR '(' remember mexpr ')' mblock cont
36477c24 208 { $$ = block_end($4,
55497cff 209 newFOROP(0, $1, $2, Nullop, $5, $7, $8)); }
bbce6d69 210 | label FOR '(' remember mnexpr ';' mtexpr ';' mnexpr ')' mblock
8d063cd8 211 /* basically fake up an initialize-while lineseq */
fb73857a
PP
212 { OP *forop = append_elem(OP_LINESEQ,
213 scalar($5),
214 newWHILEOP(0, 1, (LOOP*)Nullop,
215 $2, scalar($7),
216 $11, scalar($9)));
217 copline = $2;
218 $$ = block_end($4, newSTATEOP(0, $1, forop)); }
79072805 219 | label block cont /* a block is a loop that happens once */
fb73857a
PP
220 { $$ = newSTATEOP(0, $1,
221 newWHILEOP(0, 1, (LOOP*)Nullop,
222 NOLINE, Nullop, $2, $3)); }
8d063cd8
LW
223 ;
224
225nexpr : /* NULL */
79072805 226 { $$ = Nullop; }
8d063cd8
LW
227 | sideff
228 ;
229
230texpr : /* NULL means true */
79072805 231 { (void)scan_num("1"); $$ = yylval.opval; }
8d063cd8
LW
232 | expr
233 ;
234
55497cff
PP
235iexpr : expr
236 { $$ = invert(scalar($1)); }
237 ;
238
239mexpr : expr
bbce6d69
PP
240 { $$ = $1; intro_my(); }
241 ;
242
243mnexpr : nexpr
244 { $$ = $1; intro_my(); }
55497cff
PP
245 ;
246
247mtexpr : texpr
bbce6d69 248 { $$ = $1; intro_my(); }
55497cff
PP
249 ;
250
251miexpr : iexpr
bbce6d69 252 { $$ = $1; intro_my(); }
55497cff
PP
253 ;
254
8d063cd8
LW
255label : /* empty */
256 { $$ = Nullch; }
32c2e4fb 257 | LABEL
8d063cd8
LW
258 ;
259
8d063cd8
LW
260decl : format
261 { $$ = 0; }
262 | subrout
263 { $$ = 0; }
a687059c
LW
264 | package
265 { $$ = 0; }
a0d0e21e 266 | use
85e6fe83 267 { $$ = 0; }
8d063cd8
LW
268 ;
269
44a8e56a 270format : FORMAT startformsub formname block
a0d0e21e 271 { newFORM($2, $3, $4); }
44a8e56a
PP
272 ;
273
274formname: WORD { $$ = $1; }
275 | /* NULL */ { $$ = Nullop; }
8d063cd8
LW
276 ;
277
28757baa 278subrout : SUB startsub subname proto subbody
4633a7c4 279 { newSUB($2, $3, $4, $5); }
28757baa
PP
280 ;
281
fa83b5b6 282startsub: /* NULL */ /* start a regular subroutine scope */
774d564b 283 { $$ = start_subparse(FALSE, 0); }
28757baa
PP
284 ;
285
286startanonsub: /* NULL */ /* start an anonymous subroutine scope */
774d564b 287 { $$ = start_subparse(FALSE, CVf_ANON); }
28757baa
PP
288 ;
289
44a8e56a 290startformsub: /* NULL */ /* start a format subroutine scope */
774d564b 291 { $$ = start_subparse(TRUE, 0); }
44a8e56a
PP
292 ;
293
e858de61
MB
294subname : WORD { char *name = SvPV(((SVOP*)$1)->op_sv, na);
295 if (strEQ(name, "BEGIN") || strEQ(name, "END")
7d07dbc2 296 || strEQ(name, "INIT"))
977336f5 297 CvUNIQUE_on(compcv);
28757baa 298 $$ = $1; }
a0d0e21e
LW
299 ;
300
4633a7c4
LW
301proto : /* NULL */
302 { $$ = Nullop; }
303 | THING
304 ;
28757baa
PP
305
306subbody : block { $$ = $1; }
307 | ';' { $$ = Nullop; expect = XSTATE; }
8d063cd8
LW
308 ;
309
a687059c 310package : PACKAGE WORD ';'
79072805 311 { package($2); }
93a17b20
LW
312 | PACKAGE ';'
313 { package(Nullop); }
a687059c
LW
314 ;
315
28757baa
PP
316use : USE startsub
317 { CvUNIQUE_on(compcv); /* It's a BEGIN {} */ }
318 WORD WORD listexpr ';'
319 { utilize($1, $2, $4, $5, $6); }
85e6fe83
LW
320 ;
321
a0d0e21e
LW
322expr : expr ANDOP expr
323 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
324 | expr OROP expr
325 { $$ = newLOGOP($2, 0, $1, $3); }
a0d0e21e
LW
326 | argexpr
327 ;
328
329argexpr : argexpr ','
330 { $$ = $1; }
331 | argexpr ',' term
79072805 332 { $$ = append_elem(OP_LIST, $1, $3); }
a0d0e21e 333 | term
8d063cd8
LW
334 ;
335
a0d0e21e 336listop : LSTOP indirob argexpr
79072805 337 { $$ = convert($1, OPf_STACKED,
a0d0e21e
LW
338 prepend_elem(OP_LIST, newGVREF($1,$2), $3) ); }
339 | FUNC '(' indirob expr ')'
79072805 340 { $$ = convert($1, OPf_STACKED,
a0d0e21e
LW
341 prepend_elem(OP_LIST, newGVREF($1,$3), $4) ); }
342 | term ARROW method '(' listexprcom ')'
4633a7c4 343 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
a0d0e21e 344 append_elem(OP_LIST,
55497cff 345 prepend_elem(OP_LIST, scalar($1), $5),
a0d0e21e 346 newUNOP(OP_METHOD, 0, $3))); }
79072805 347 | METHOD indirob listexpr
4633a7c4 348 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
a0d0e21e 349 append_elem(OP_LIST,
4633a7c4 350 prepend_elem(OP_LIST, $2, $3),
a0d0e21e
LW
351 newUNOP(OP_METHOD, 0, $1))); }
352 | FUNCMETH indirob '(' listexprcom ')'
4633a7c4 353 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
a0d0e21e 354 append_elem(OP_LIST,
4633a7c4 355 prepend_elem(OP_LIST, $2, $4),
a0d0e21e 356 newUNOP(OP_METHOD, 0, $1))); }
79072805
LW
357 | LSTOP listexpr
358 { $$ = convert($1, 0, $2); }
a0d0e21e 359 | FUNC '(' listexprcom ')'
79072805 360 { $$ = convert($1, 0, $3); }
28757baa
PP
361 | LSTOPSUB startanonsub block
362 { $3 = newANONSUB($2, 0, $3); }
363 listexpr %prec LSTOP
4633a7c4 364 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
28757baa
PP
365 append_elem(OP_LIST,
366 prepend_elem(OP_LIST, $3, $5), $1)); }
a687059c
LW
367 ;
368
a0d0e21e
LW
369method : METHOD
370 | scalar
371 ;
372
373term : term ASSIGNOP term
374 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
375 | term POWOP term
79072805 376 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 377 | term MULOP term
79072805
LW
378 { if ($2 != OP_REPEAT)
379 scalar($1);
380 $$ = newBINOP($2, 0, $1, scalar($3)); }
a0d0e21e 381 | term ADDOP term
79072805 382 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 383 | term SHIFTOP term
79072805 384 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 385 | term RELOP term
79072805 386 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 387 | term EQOP term
79072805 388 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 389 | term BITANDOP term
79072805 390 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 391 | term BITOROP term
79072805 392 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 393 | term DOTDOT term
79072805 394 { $$ = newRANGE($2, scalar($1), scalar($3));}
a0d0e21e 395 | term ANDAND term
463ee0b2 396 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
a0d0e21e 397 | term OROR term
463ee0b2 398 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
a0d0e21e 399 | term '?' term ':' term
79072805 400 { $$ = newCONDOP(0, $1, $3, $5); }
a0d0e21e 401 | term MATCHOP term
79072805 402 { $$ = bind_match($2, $1, $3); }
8d063cd8 403
a0d0e21e 404 | '-' term %prec UMINUS
79072805 405 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
a687059c
LW
406 | '+' term %prec UMINUS
407 { $$ = $2; }
8d063cd8 408 | '!' term
79072805 409 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
8d063cd8 410 | '~' term
79072805
LW
411 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2));}
412 | REFGEN term
a0d0e21e 413 { $$ = newUNOP(OP_REFGEN, 0, mod($2,OP_REFGEN)); }
79072805
LW
414 | term POSTINC
415 { $$ = newUNOP(OP_POSTINC, 0,
463ee0b2 416 mod(scalar($1), OP_POSTINC)); }
79072805
LW
417 | term POSTDEC
418 { $$ = newUNOP(OP_POSTDEC, 0,
463ee0b2 419 mod(scalar($1), OP_POSTDEC)); }
79072805
LW
420 | PREINC term
421 { $$ = newUNOP(OP_PREINC, 0,
463ee0b2 422 mod(scalar($2), OP_PREINC)); }
79072805
LW
423 | PREDEC term
424 { $$ = newUNOP(OP_PREDEC, 0,
463ee0b2 425 mod(scalar($2), OP_PREDEC)); }
55497cff 426 | local term %prec UNIOP
93a17b20 427 { $$ = localize($2,$1); }
a0d0e21e 428 | '(' expr ')'
79072805 429 { $$ = sawparens($2); }
8d063cd8 430 | '(' ')'
8990e307 431 { $$ = sawparens(newNULLLIST()); }
a0d0e21e 432 | '[' expr ']' %prec '('
79072805
LW
433 { $$ = newANONLIST($2); }
434 | '[' ']' %prec '('
435 { $$ = newANONLIST(Nullop); }
a0d0e21e 436 | HASHBRACK expr ';' '}' %prec '('
79072805
LW
437 { $$ = newANONHASH($2); }
438 | HASHBRACK ';' '}' %prec '('
439 { $$ = newANONHASH(Nullop); }
28757baa 440 | ANONSUB startanonsub proto block %prec '('
4633a7c4 441 { $$ = newANONSUB($2, $3, $4); }
79072805 442 | scalar %prec '('
8d063cd8 443 { $$ = $1; }
c07a80fd 444 | star '{' expr ';' '}'
640b9ef6 445 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
79072805 446 | star %prec '('
8d063cd8 447 { $$ = $1; }
79072805
LW
448 | scalar '[' expr ']' %prec '('
449 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); }
450 | term ARROW '[' expr ']' %prec '('
451 { $$ = newBINOP(OP_AELEM, 0,
8990e307 452 ref(newAVREF($1),OP_RV2AV),
79072805 453 scalar($4));}
463ee0b2 454 | term '[' expr ']' %prec '('
a0d0e21e 455 { assertref($1); $$ = newBINOP(OP_AELEM, 0,
8990e307 456 ref(newAVREF($1),OP_RV2AV),
463ee0b2 457 scalar($3));}
79072805 458 | hsh %prec '('
8d063cd8 459 { $$ = $1; }
79072805 460 | ary %prec '('
8d063cd8 461 { $$ = $1; }
79072805
LW
462 | arylen %prec '('
463 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
464 | scalar '{' expr ';' '}' %prec '('
465 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
466 expect = XOPERATOR; }
467 | term ARROW '{' expr ';' '}' %prec '('
468 { $$ = newBINOP(OP_HELEM, 0,
8990e307 469 ref(newHVREF($1),OP_RV2HV),
79072805
LW
470 jmaybe($4));
471 expect = XOPERATOR; }
463ee0b2 472 | term '{' expr ';' '}' %prec '('
a0d0e21e 473 { assertref($1); $$ = newBINOP(OP_HELEM, 0,
8990e307 474 ref(newHVREF($1),OP_RV2HV),
463ee0b2
LW
475 jmaybe($3));
476 expect = XOPERATOR; }
a0d0e21e 477 | '(' expr ')' '[' expr ']' %prec '('
79072805
LW
478 { $$ = newSLICEOP(0, $5, $2); }
479 | '(' ')' '[' expr ']' %prec '('
480 { $$ = newSLICEOP(0, $4, Nullop); }
481 | ary '[' expr ']' %prec '('
482 { $$ = prepend_elem(OP_ASLICE,
483 newOP(OP_PUSHMARK, 0),
79072805
LW
484 newLISTOP(OP_ASLICE, 0,
485 list($3),
a0d0e21e 486 ref($1, OP_ASLICE))); }
79072805
LW
487 | ary '{' expr ';' '}' %prec '('
488 { $$ = prepend_elem(OP_HSLICE,
489 newOP(OP_PUSHMARK, 0),
79072805
LW
490 newLISTOP(OP_HSLICE, 0,
491 list($3),
a0d0e21e 492 ref(oopsHV($1), OP_HSLICE)));
79072805
LW
493 expect = XOPERATOR; }
494 | THING %prec '('
495 { $$ = $1; }
496 | amper
c07a80fd 497 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
79072805 498 | amper '(' ')'
a0d0e21e
LW
499 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
500 | amper '(' expr ')'
501 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
4633a7c4 502 append_elem(OP_LIST, $3, scalar($1))); }
93a17b20 503 | NOAMP WORD listexpr
a0d0e21e 504 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
a5f75d66 505 append_elem(OP_LIST, $3, scalar($2))); }
a0d0e21e 506 | DO term %prec UNIOP
463ee0b2 507 { $$ = newUNOP(OP_DOFILE, 0, scalar($2)); }
79072805
LW
508 | DO block %prec '('
509 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2)); }
8d063cd8 510 | DO WORD '(' ')'
c07a80fd
PP
511 { $$ = newUNOP(OP_ENTERSUB,
512 OPf_SPECIAL|OPf_STACKED,
4633a7c4 513 prepend_elem(OP_LIST,
c07a80fd
PP
514 scalar(newCVREF(
515 (OPpENTERSUB_AMPER<<8),
516 scalar($2)
517 )),Nullop)); dep();}
a0d0e21e 518 | DO WORD '(' expr ')'
c07a80fd
PP
519 { $$ = newUNOP(OP_ENTERSUB,
520 OPf_SPECIAL|OPf_STACKED,
4633a7c4 521 append_elem(OP_LIST,
a0d0e21e 522 $4,
c07a80fd
PP
523 scalar(newCVREF(
524 (OPpENTERSUB_AMPER<<8),
525 scalar($2)
526 )))); dep();}
79072805 527 | DO scalar '(' ')'
a0d0e21e 528 { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
4633a7c4 529 prepend_elem(OP_LIST,
c07a80fd 530 scalar(newCVREF(0,scalar($2))), Nullop)); dep();}
a0d0e21e
LW
531 | DO scalar '(' expr ')'
532 { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
4633a7c4 533 prepend_elem(OP_LIST,
a0d0e21e 534 $4,
c07a80fd 535 scalar(newCVREF(0,scalar($2))))); dep();}
6da72b64
CS
536 | term ARROW '(' ')' %prec '('
537 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
538 newCVREF(0, scalar($1))); }
539 | term ARROW '(' expr ')' %prec '('
540 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
541 append_elem(OP_LIST, $4,
542 newCVREF(0, scalar($1)))); }
8d063cd8 543 | LOOPEX
85e6fe83
LW
544 { $$ = newOP($1, OPf_SPECIAL);
545 hints |= HINT_BLOCK_SCOPE; }
a0d0e21e 546 | LOOPEX term
8990e307 547 { $$ = newLOOPEX($1,$2); }
c07a80fd
PP
548 | NOTOP argexpr
549 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
8d063cd8 550 | UNIOP
79072805 551 { $$ = newOP($1, 0); }
f0fcb552 552 | UNIOP block
79072805 553 { $$ = newUNOP($1, 0, $2); }
a0d0e21e 554 | UNIOP term
79072805 555 { $$ = newUNOP($1, 0, $2); }
4633a7c4
LW
556 | UNIOPSUB term
557 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
558 append_elem(OP_LIST, $2, scalar($1))); }
8d063cd8 559 | FUNC0
79072805 560 { $$ = newOP($1, 0); }
ae986130 561 | FUNC0 '(' ')'
79072805 562 { $$ = newOP($1, 0); }
4633a7c4 563 | FUNC0SUB
28757baa 564 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
4633a7c4 565 scalar($1)); }
03a14243 566 | FUNC1 '(' ')'
79072805 567 { $$ = newOP($1, OPf_SPECIAL); }
8d063cd8 568 | FUNC1 '(' expr ')'
79072805 569 { $$ = newUNOP($1, 0, $3); }
a0d0e21e 570 | PMFUNC '(' term ')'
79072805 571 { $$ = pmruntime($1, $3, Nullop); }
a0d0e21e 572 | PMFUNC '(' term ',' term ')'
79072805
LW
573 { $$ = pmruntime($1, $3, $5); }
574 | WORD
378cc40b 575 | listop
8d063cd8
LW
576 ;
577
79072805 578listexpr: /* NULL */
8990e307 579 { $$ = Nullop; }
a0d0e21e
LW
580 | argexpr
581 { $$ = $1; }
582 ;
583
584listexprcom: /* NULL */
585 { $$ = Nullop; }
79072805
LW
586 | expr
587 { $$ = $1; }
a0d0e21e
LW
588 | expr ','
589 { $$ = $1; }
79072805
LW
590 ;
591
55497cff
PP
592local : LOCAL { $$ = 0; }
593 | MY { $$ = 1; }
594 ;
595
596my_scalar: scalar
597 { in_my = 0; $$ = my($1); }
598 ;
599
79072805 600amper : '&' indirob
c07a80fd 601 { $$ = newCVREF($1,$2); }
a687059c
LW
602 ;
603
79072805
LW
604scalar : '$' indirob
605 { $$ = newSVREF($2); }
a687059c
LW
606 ;
607
79072805
LW
608ary : '@' indirob
609 { $$ = newAVREF($2); }
610 ;
611
612hsh : '%' indirob
613 { $$ = newHVREF($2); }
614 ;
615
616arylen : DOLSHARP indirob
617 { $$ = newAVREF($2); }
618 ;
619
620star : '*' indirob
a0d0e21e 621 { $$ = newGVREF(0,$2); }
79072805
LW
622 ;
623
624indirob : WORD
625 { $$ = scalar($1); }
626 | scalar
463ee0b2 627 { $$ = scalar($1); }
79072805 628 | block
a0d0e21e 629 { $$ = scope($1); }
79072805 630
93a17b20
LW
631 | PRIVATEREF
632 { $$ = $1; }
8d063cd8
LW
633 ;
634
635%% /* PROGRAM */