This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.0 alpha 9
[perl5.git] / perly.y
CommitLineData
79072805 1/* $RCSfile: perly.y,v $$Revision: 4.1 $$Date: 92/08/07 18:26:16 $
a687059c 2 *
9ef589d8 3 * Copyright (c) 1991, 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 *
fe14fcc3 8 * $Log: perly.y,v $
79072805
LW
9 * Revision 4.1 92/08/07 18:26:16 lwall
10 *
faf8582f
LW
11 * Revision 4.0.1.5 92/06/11 21:12:50 lwall
12 * patch34: expectterm incorrectly set to indicate start of program or block
13 *
32c2e4fb
LW
14 * Revision 4.0.1.4 92/06/08 17:33:25 lwall
15 * patch20: one of the backdoors to expectterm was on the wrong reduction
16 *
17 * Revision 4.0.1.3 92/06/08 15:18:16 lwall
18 * patch20: an expression may now start with a bareword
19 * patch20: relaxed requirement for semicolon at the end of a block
20 * patch20: added ... as variant on ..
21 * patch20: fixed double debug break in foreach with implicit array assignment
22 * patch20: if {block} {block} didn't work any more
23 * patch20: deleted some minor memory leaks
24 *
f0fcb552
LW
25 * Revision 4.0.1.2 91/11/05 18:17:38 lwall
26 * patch11: extra comma at end of list is now allowed in more places (Hi, Felix!)
27 * patch11: once-thru blocks didn't display right in the debugger
28 * patch11: debugger got confused over nested subroutine definitions
29 *
9ef589d8
LW
30 * Revision 4.0.1.1 91/06/07 11:42:34 lwall
31 * patch4: new copyright notice
32 *
fe14fcc3
LW
33 * Revision 4.0 91/03/20 01:38:40 lwall
34 * 4.0 baseline.
8d063cd8
LW
35 *
36 */
37
38%{
79072805 39#include "EXTERN.h"
8d063cd8 40#include "perl.h"
378cc40b 41
f0fcb552
LW
42/*SUPPRESS 530*/
43/*SUPPRESS 593*/
44/*SUPPRESS 595*/
45
8d063cd8
LW
46%}
47
48%start prog
49
50%union {
79072805
LW
51 I32 ival;
52 char *pval;
53 OP *opval;
54 GV *gvval;
8d063cd8
LW
55}
56
f0fcb552
LW
57%token <ival> '{' ')'
58
93a17b20 59%token <opval> WORD METHOD THING PMFUNC PRIVATEREF
79072805 60%token <pval> LABEL
85e6fe83 61%token <ival> FORMAT SUB PACKAGE HINT
79072805
LW
62%token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
63%token <ival> LOOPEX DOTDOT
64%token <ival> FUNC0 FUNC1 FUNC
65%token <ival> RELOP EQOP MULOP ADDOP
93a17b20 66%token <ival> DOLSHARP DO LOCAL DELETE HASHBRACK NOAMP
79072805
LW
67
68%type <ival> prog decl format remember crp crb crhb
69%type <opval> block lineseq line loop cond nexpr else
70%type <opval> expr sexpr term scalar ary hsh arylen star amper sideff
71%type <opval> listexpr indirob
72%type <opval> texpr listop
73%type <pval> label
74%type <opval> cont
75
463ee0b2
LW
76%left OROP
77%left ANDOP
79072805 78%nonassoc <ival> LSTOP
8d063cd8 79%left ','
8d063cd8
LW
80%right '='
81%right '?' ':'
82%nonassoc DOTDOT
83%left OROR
84%left ANDAND
79072805
LW
85%left <ival> BITOROP
86%left <ival> BITANDOP
a687059c
LW
87%nonassoc EQOP
88%nonassoc RELOP
378cc40b 89%nonassoc <ival> UNIOP
79072805 90%left <ival> SHIFTOP
a687059c
LW
91%left ADDOP
92%left MULOP
8990e307 93%left <ival> MATCHOP
79072805
LW
94%right '!' '~' UMINUS REFGEN
95%right <ival> POWOP
96%nonassoc PREINC PREDEC POSTINC POSTDEC
8990e307 97%left ARROW
8d063cd8
LW
98%left '('
99
100%% /* RULES */
101
ae986130
LW
102prog : /* NULL */
103 {
104#if defined(YYDEBUG) && defined(DEBUGGING)
105 yydebug = (debug & 1);
106#endif
8990e307 107 expect = XSTATE;
ae986130
LW
108 }
109 /*CONTINUED*/ lineseq
79072805
LW
110 { if (in_eval) {
111 eval_root = newUNOP(OP_LEAVEEVAL, 0, $2);
112 eval_start = linklist(eval_root);
113 eval_root->op_next = 0;
114 peep(eval_start);
115 }
a559c259 116 else
93a17b20 117 main_root = block_head($2, &main_start);
79072805 118 }
8d063cd8
LW
119 ;
120
a687059c 121block : '{' remember lineseq '}'
85e6fe83 122 { int needblockscope = hints & HINT_BLOCK_SCOPE;
463ee0b2
LW
123 $$ = scalarseq($3);
124 if (copline > (line_t)$1)
125 copline = $1;
8990e307 126 LEAVE_SCOPE($2);
85e6fe83
LW
127 if (needblockscope)
128 hints |= HINT_BLOCK_SCOPE; /* propagate out */
8990e307 129 pad_leavemy(comppad_name_fill); }
a687059c
LW
130 ;
131
132remember: /* NULL */ /* in case they push a package name */
463ee0b2 133 { $$ = savestack_ix;
8990e307
LW
134 comppad_name_fill = AvFILL(comppad_name);
135 SAVEINT(min_intro_pending);
136 SAVEINT(max_intro_pending);
137 min_intro_pending = 0;
138 SAVEINT(comppad_name_fill);
85e6fe83
LW
139 SAVEINT(hints);
140 hints &= ~HINT_BLOCK_SCOPE; }
8d063cd8
LW
141 ;
142
143lineseq : /* NULL */
79072805
LW
144 { $$ = Nullop; }
145 | lineseq decl
146 { $$ = $1; }
8d063cd8 147 | lineseq line
463ee0b2
LW
148 { $$ = append_list(OP_LINESEQ,
149 (LISTOP*)$1, (LISTOP*)$2); pad_reset();
85e6fe83 150 if ($1 && $2) hints |= HINT_BLOCK_SCOPE; }
8d063cd8
LW
151 ;
152
79072805
LW
153line : label cond
154 { $$ = newSTATEOP(0, $1, $2); }
8d063cd8
LW
155 | loop /* loops add their own labels */
156 | label ';'
157 { if ($1 != Nullch) {
79072805 158 $$ = newSTATEOP(0, $1, newOP(OP_NULL, 0));
450a55e4
LW
159 }
160 else {
79072805
LW
161 $$ = Nullop;
162 copline = NOLINE;
32c2e4fb 163 }
8990e307 164 expect = XSTATE; }
8d063cd8 165 | label sideff ';'
79072805 166 { $$ = newSTATEOP(0, $1, $2);
8990e307 167 expect = XSTATE; }
8d063cd8
LW
168 ;
169
a687059c 170sideff : error
79072805 171 { $$ = Nullop; }
a687059c 172 | expr
79072805 173 { $$ = $1; }
a687059c 174 | expr IF expr
79072805 175 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
a687059c 176 | expr UNLESS expr
79072805 177 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
a687059c 178 | expr WHILE expr
8990e307 179 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
a687059c 180 | expr UNTIL expr
8990e307 181 { $$ = newLOOPOP(OPf_PARENS, 1, invert(scalar($3)), $1);}
79072805
LW
182 ;
183
184else : /* NULL */
185 { $$ = Nullop; }
186 | ELSE block
187 { $$ = scope($2); }
188 | ELSIF '(' expr ')' block else
189 { copline = $1;
85e6fe83
LW
190 $$ = newSTATEOP(0, 0,
191 newCONDOP(0, $3, scope($5), $6)); }
79072805
LW
192 ;
193
194cond : IF '(' expr ')' block else
195 { copline = $1;
196 $$ = newCONDOP(0, $3, scope($5), $6); }
197 | UNLESS '(' expr ')' block else
198 { copline = $1;
199 $$ = newCONDOP(0,
200 invert(scalar($3)), scope($5), $6); }
201 | IF block block else
202 { copline = $1;
203 $$ = newCONDOP(0, scope($2), scope($3), $4); }
204 | UNLESS block block else
205 { copline = $1;
206 $$ = newCONDOP(0, invert(scalar(scope($2))),
207 scope($3), $4); }
208 ;
209
210cont : /* NULL */
211 { $$ = Nullop; }
212 | CONTINUE block
213 { $$ = scope($2); }
214 ;
215
216loop : label WHILE '(' texpr ')' block cont
217 { copline = $2;
218 $$ = newSTATEOP(0, $1,
463ee0b2
LW
219 newWHILEOP(0, 1, (LOOP*)Nullop,
220 $4, $6, $7) ); }
79072805
LW
221 | label UNTIL '(' expr ')' block cont
222 { copline = $2;
223 $$ = newSTATEOP(0, $1,
463ee0b2 224 newWHILEOP(0, 1, (LOOP*)Nullop,
79072805
LW
225 invert(scalar($4)), $6, $7) ); }
226 | label WHILE block block cont
227 { copline = $2;
228 $$ = newSTATEOP(0, $1,
463ee0b2 229 newWHILEOP(0, 1, (LOOP*)Nullop,
79072805
LW
230 scope($3), $4, $5) ); }
231 | label UNTIL block block cont
232 { copline = $2;
233 $$ = newSTATEOP(0, $1,
463ee0b2 234 newWHILEOP(0, 1, (LOOP*)Nullop,
79072805
LW
235 invert(scalar(scope($3))), $4, $5)); }
236 | label FOR scalar '(' expr crp block cont
463ee0b2 237 { $$ = newFOROP(0, $1, $2, mod($3, OP_ENTERLOOP),
79072805
LW
238 $5, $7, $8); }
239 | label FOR '(' expr crp block cont
240 { $$ = newFOROP(0, $1, $2, Nullop, $4, $6, $7); }
8d063cd8
LW
241 | label FOR '(' nexpr ';' texpr ';' nexpr ')' block
242 /* basically fake up an initialize-while lineseq */
79072805
LW
243 { copline = $2;
244 $$ = append_elem(OP_LINESEQ,
245 newSTATEOP(0, $1, scalar($4)),
246 newSTATEOP(0, $1,
463ee0b2 247 newWHILEOP(0, 1, (LOOP*)Nullop,
79072805
LW
248 scalar($6), $10, scalar($8)) )); }
249 | label block cont /* a block is a loop that happens once */
250 { $$ = newSTATEOP(0,
463ee0b2
LW
251 $1, newWHILEOP(0, 1, (LOOP*)Nullop,
252 Nullop, $2, $3)); }
8d063cd8
LW
253 ;
254
255nexpr : /* NULL */
79072805 256 { $$ = Nullop; }
8d063cd8
LW
257 | sideff
258 ;
259
260texpr : /* NULL means true */
79072805 261 { (void)scan_num("1"); $$ = yylval.opval; }
8d063cd8
LW
262 | expr
263 ;
264
265label : /* empty */
266 { $$ = Nullch; }
32c2e4fb 267 | LABEL
8d063cd8
LW
268 ;
269
8d063cd8
LW
270decl : format
271 { $$ = 0; }
272 | subrout
273 { $$ = 0; }
a687059c
LW
274 | package
275 { $$ = 0; }
85e6fe83
LW
276 | hint
277 { $$ = 0; }
8d063cd8
LW
278 ;
279
79072805
LW
280format : FORMAT WORD block
281 { newFORM($1, $2, $3); }
282 | FORMAT block
283 { newFORM($1, Nullop, $2); }
8d063cd8
LW
284 ;
285
286subrout : SUB WORD block
79072805 287 { newSUB($1, $2, $3); }
93a17b20 288 | SUB WORD ';'
8990e307 289 { newSUB($1, $2, Nullop); expect = XSTATE; }
8d063cd8
LW
290 ;
291
a687059c 292package : PACKAGE WORD ';'
79072805 293 { package($2); }
93a17b20
LW
294 | PACKAGE ';'
295 { package(Nullop); }
a687059c
LW
296 ;
297
85e6fe83
LW
298hint : HINT WORD ';'
299 { hint($1, $2, Nullop); }
300 | HINT WORD expr ';'
301 { hint($1, $2, list(force_list($3))); }
302 ;
303
a687059c 304expr : expr ',' sexpr
79072805 305 { $$ = append_elem(OP_LIST, $1, $3); }
8d063cd8
LW
306 | sexpr
307 ;
308
79072805
LW
309listop : LSTOP indirob listexpr
310 { $$ = convert($1, OPf_STACKED,
311 prepend_elem(OP_LIST, newGVREF($2), $3) ); }
312 | FUNC '(' indirob listexpr ')'
313 { $$ = convert($1, OPf_STACKED,
314 prepend_elem(OP_LIST, newGVREF($3), $4) ); }
315 | indirob ARROW LSTOP listexpr
316 { $$ = convert($3, OPf_STACKED,
317 prepend_elem(OP_LIST, newGVREF($1), $4) ); }
318 | indirob ARROW FUNC '(' listexpr ')'
319 { $$ = convert($3, OPf_STACKED,
320 prepend_elem(OP_LIST, newGVREF($1), $5) ); }
321 | term ARROW METHOD '(' listexpr ')'
322 { $$ = convert(OP_ENTERSUBR, OPf_STACKED|OPf_SPECIAL,
8990e307
LW
323 prepend_elem(OP_LIST,
324 newMETHOD($1,$3), list($5))); }
79072805
LW
325 | METHOD indirob listexpr
326 { $$ = convert(OP_ENTERSUBR, OPf_STACKED|OPf_SPECIAL,
8990e307
LW
327 prepend_elem(OP_LIST,
328 newMETHOD($2,$1), list($3))); }
79072805
LW
329 | LSTOP listexpr
330 { $$ = convert($1, 0, $2); }
331 | FUNC '(' listexpr ')'
332 { $$ = convert($1, 0, $3); }
a687059c
LW
333 ;
334
8d063cd8 335sexpr : sexpr '=' sexpr
79072805
LW
336 { $$ = newASSIGNOP(OPf_STACKED, $1, $3); }
337 | sexpr POWOP '=' sexpr
338 { $$ = newBINOP($2, OPf_STACKED,
463ee0b2 339 mod(scalar($1), $2), scalar($4)); }
a687059c 340 | sexpr MULOP '=' sexpr
79072805 341 { $$ = newBINOP($2, OPf_STACKED,
463ee0b2 342 mod(scalar($1), $2), scalar($4)); }
a687059c 343 | sexpr ADDOP '=' sexpr
79072805 344 { $$ = newBINOP($2, OPf_STACKED,
463ee0b2 345 mod(scalar($1), $2), scalar($4));}
79072805
LW
346 | sexpr SHIFTOP '=' sexpr
347 { $$ = newBINOP($2, OPf_STACKED,
463ee0b2 348 mod(scalar($1), $2), scalar($4)); }
79072805
LW
349 | sexpr BITANDOP '=' sexpr
350 { $$ = newBINOP($2, OPf_STACKED,
463ee0b2 351 mod(scalar($1), $2), scalar($4)); }
79072805
LW
352 | sexpr BITOROP '=' sexpr
353 { $$ = newBINOP($2, OPf_STACKED,
463ee0b2 354 mod(scalar($1), $2), scalar($4)); }
79072805
LW
355 | sexpr ANDAND '=' sexpr
356 { $$ = newLOGOP(OP_ANDASSIGN, 0,
463ee0b2 357 mod(scalar($1), OP_ANDASSIGN),
79072805
LW
358 newUNOP(OP_SASSIGN, 0, scalar($4))); }
359 | sexpr OROR '=' sexpr
360 { $$ = newLOGOP(OP_ORASSIGN, 0,
463ee0b2 361 mod(scalar($1), OP_ORASSIGN),
79072805
LW
362 newUNOP(OP_SASSIGN, 0, scalar($4))); }
363
364
365 | sexpr POWOP sexpr
366 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a687059c 367 | sexpr MULOP sexpr
79072805
LW
368 { if ($2 != OP_REPEAT)
369 scalar($1);
370 $$ = newBINOP($2, 0, $1, scalar($3)); }
a687059c 371 | sexpr ADDOP sexpr
79072805
LW
372 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
373 | sexpr SHIFTOP sexpr
374 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a687059c 375 | sexpr RELOP sexpr
79072805 376 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a687059c 377 | sexpr EQOP sexpr
79072805
LW
378 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
379 | sexpr BITANDOP sexpr
380 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
381 | sexpr BITOROP sexpr
382 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
8d063cd8 383 | sexpr DOTDOT sexpr
79072805 384 { $$ = newRANGE($2, scalar($1), scalar($3));}
8d063cd8 385 | sexpr ANDAND sexpr
79072805 386 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
8d063cd8 387 | sexpr OROR sexpr
79072805 388 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
463ee0b2
LW
389 | sexpr ANDOP sexpr
390 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
391 | sexpr OROP sexpr
392 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
8d063cd8 393 | sexpr '?' sexpr ':' sexpr
79072805
LW
394 { $$ = newCONDOP(0, $1, $3, $5); }
395 | sexpr MATCHOP sexpr
396 { $$ = bind_match($2, $1, $3); }
8d063cd8
LW
397 | term
398 { $$ = $1; }
399 ;
400
401term : '-' term %prec UMINUS
79072805 402 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
a687059c
LW
403 | '+' term %prec UMINUS
404 { $$ = $2; }
8d063cd8 405 | '!' term
79072805 406 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
8d063cd8 407 | '~' term
79072805
LW
408 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2));}
409 | REFGEN term
8990e307 410 { $$ = newUNOP(OP_REFGEN, 0, ref($2,OP_REFGEN)); }
79072805
LW
411 | term POSTINC
412 { $$ = newUNOP(OP_POSTINC, 0,
463ee0b2 413 mod(scalar($1), OP_POSTINC)); }
79072805
LW
414 | term POSTDEC
415 { $$ = newUNOP(OP_POSTDEC, 0,
463ee0b2 416 mod(scalar($1), OP_POSTDEC)); }
79072805
LW
417 | PREINC term
418 { $$ = newUNOP(OP_PREINC, 0,
463ee0b2 419 mod(scalar($2), OP_PREINC)); }
79072805
LW
420 | PREDEC term
421 { $$ = newUNOP(OP_PREDEC, 0,
463ee0b2 422 mod(scalar($2), OP_PREDEC)); }
79072805 423 | LOCAL sexpr %prec UNIOP
93a17b20 424 { $$ = localize($2,$1); }
f0fcb552 425 | '(' expr crp
79072805 426 { $$ = sawparens($2); }
8d063cd8 427 | '(' ')'
8990e307 428 { $$ = sawparens(newNULLLIST()); }
79072805
LW
429 | '[' expr crb %prec '('
430 { $$ = newANONLIST($2); }
431 | '[' ']' %prec '('
432 { $$ = newANONLIST(Nullop); }
433 | HASHBRACK expr crhb %prec '('
434 { $$ = newANONHASH($2); }
435 | HASHBRACK ';' '}' %prec '('
436 { $$ = newANONHASH(Nullop); }
437 | scalar %prec '('
8d063cd8 438 { $$ = $1; }
79072805 439 | star %prec '('
8d063cd8 440 { $$ = $1; }
79072805
LW
441 | scalar '[' expr ']' %prec '('
442 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); }
443 | term ARROW '[' expr ']' %prec '('
444 { $$ = newBINOP(OP_AELEM, 0,
8990e307 445 ref(newAVREF($1),OP_RV2AV),
79072805 446 scalar($4));}
463ee0b2
LW
447 | term '[' expr ']' %prec '('
448 { $$ = newBINOP(OP_AELEM, 0,
8990e307 449 ref(newAVREF($1),OP_RV2AV),
463ee0b2 450 scalar($3));}
79072805 451 | hsh %prec '('
8d063cd8 452 { $$ = $1; }
79072805 453 | ary %prec '('
8d063cd8 454 { $$ = $1; }
79072805
LW
455 | arylen %prec '('
456 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
457 | scalar '{' expr ';' '}' %prec '('
458 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
459 expect = XOPERATOR; }
460 | term ARROW '{' expr ';' '}' %prec '('
461 { $$ = newBINOP(OP_HELEM, 0,
8990e307 462 ref(newHVREF($1),OP_RV2HV),
79072805
LW
463 jmaybe($4));
464 expect = XOPERATOR; }
463ee0b2
LW
465 | term '{' expr ';' '}' %prec '('
466 { $$ = newBINOP(OP_HELEM, 0,
8990e307 467 ref(newHVREF($1),OP_RV2HV),
463ee0b2
LW
468 jmaybe($3));
469 expect = XOPERATOR; }
79072805
LW
470 | '(' expr crp '[' expr ']' %prec '('
471 { $$ = newSLICEOP(0, $5, $2); }
472 | '(' ')' '[' expr ']' %prec '('
473 { $$ = newSLICEOP(0, $4, Nullop); }
474 | ary '[' expr ']' %prec '('
475 { $$ = prepend_elem(OP_ASLICE,
476 newOP(OP_PUSHMARK, 0),
477 list(
478 newLISTOP(OP_ASLICE, 0,
479 list($3),
480 ref($1, OP_ASLICE)))); }
481 | ary '{' expr ';' '}' %prec '('
482 { $$ = prepend_elem(OP_HSLICE,
483 newOP(OP_PUSHMARK, 0),
484 list(
485 newLISTOP(OP_HSLICE, 0,
486 list($3),
487 ref(oopsHV($1), OP_HSLICE))));
488 expect = XOPERATOR; }
489 | DELETE scalar '{' expr ';' '}' %prec '('
490 { $$ = newBINOP(OP_DELETE, 0, oopsHV($2), jmaybe($4));
491 expect = XOPERATOR; }
492 | DELETE '(' scalar '{' expr ';' '}' ')' %prec '('
493 { $$ = newBINOP(OP_DELETE, 0, oopsHV($3), jmaybe($5));
494 expect = XOPERATOR; }
495 | THING %prec '('
496 { $$ = $1; }
497 | amper
498 { $$ = newUNOP(OP_ENTERSUBR, 0,
499 scalar($1)); }
500 | amper '(' ')'
501 { $$ = newUNOP(OP_ENTERSUBR, OPf_STACKED, scalar($1)); }
502 | amper '(' expr crp
503 { $$ = newUNOP(OP_ENTERSUBR, OPf_STACKED,
504 list(prepend_elem(OP_LIST, scalar($1), $3))); }
93a17b20
LW
505 | NOAMP WORD listexpr
506 { $$ = newUNOP(OP_ENTERSUBR, OPf_STACKED,
507 list(prepend_elem(OP_LIST,
508 newCVREF(scalar($2)), $3))); }
463ee0b2
LW
509 | NOAMP WORD indirob listexpr
510 { $$ = convert(OP_ENTERSUBR, OPf_STACKED|OPf_SPECIAL,
8990e307
LW
511 prepend_elem(OP_LIST,
512 newMETHOD($3,$2), list($4))); }
79072805 513 | DO sexpr %prec UNIOP
463ee0b2 514 { $$ = newUNOP(OP_DOFILE, 0, scalar($2)); }
79072805
LW
515 | DO block %prec '('
516 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2)); }
8d063cd8 517 | DO WORD '(' ')'
79072805
LW
518 { $$ = newUNOP(OP_ENTERSUBR, OPf_SPECIAL|OPf_STACKED,
519 list(prepend_elem(OP_LIST,
8990e307 520 scalar(newCVREF(scalar($2))), Nullop))); }
79072805
LW
521 | DO WORD '(' expr crp
522 { $$ = newUNOP(OP_ENTERSUBR, OPf_SPECIAL|OPf_STACKED,
523 list(prepend_elem(OP_LIST,
524 scalar(newCVREF(scalar($2))),
525 $4))); }
526 | DO scalar '(' ')'
527 { $$ = newUNOP(OP_ENTERSUBR, OPf_SPECIAL|OPf_STACKED,
528 list(prepend_elem(OP_LIST,
8990e307 529 scalar(newCVREF(scalar($2))), Nullop)));}
79072805
LW
530 | DO scalar '(' expr crp
531 { $$ = newUNOP(OP_ENTERSUBR, OPf_SPECIAL|OPf_STACKED,
532 list(prepend_elem(OP_LIST,
533 scalar(newCVREF(scalar($2))),
534 $4))); }
8d063cd8 535 | LOOPEX
85e6fe83
LW
536 { $$ = newOP($1, OPf_SPECIAL);
537 hints |= HINT_BLOCK_SCOPE; }
8990e307
LW
538 | LOOPEX sexpr
539 { $$ = newLOOPEX($1,$2); }
8d063cd8 540 | UNIOP
79072805 541 { $$ = newOP($1, 0); }
f0fcb552 542 | UNIOP block
79072805 543 { $$ = newUNOP($1, 0, $2); }
8d063cd8 544 | UNIOP sexpr
79072805 545 { $$ = newUNOP($1, 0, $2); }
8d063cd8 546 | FUNC0
79072805 547 { $$ = newOP($1, 0); }
ae986130 548 | FUNC0 '(' ')'
79072805 549 { $$ = newOP($1, 0); }
03a14243 550 | FUNC1 '(' ')'
79072805 551 { $$ = newOP($1, OPf_SPECIAL); }
8d063cd8 552 | FUNC1 '(' expr ')'
79072805
LW
553 { $$ = newUNOP($1, 0, $3); }
554 | PMFUNC '(' sexpr ')'
555 { $$ = pmruntime($1, $3, Nullop); }
556 | PMFUNC '(' sexpr ',' sexpr ')'
557 { $$ = pmruntime($1, $3, $5); }
558 | WORD
378cc40b 559 | listop
8d063cd8
LW
560 ;
561
79072805 562listexpr: /* NULL */
8990e307 563 { $$ = Nullop; }
79072805
LW
564 | expr
565 { $$ = $1; }
566 ;
567
568amper : '&' indirob
569 { $$ = newCVREF($2); }
a687059c
LW
570 ;
571
79072805
LW
572scalar : '$' indirob
573 { $$ = newSVREF($2); }
a687059c
LW
574 ;
575
79072805
LW
576ary : '@' indirob
577 { $$ = newAVREF($2); }
578 ;
579
580hsh : '%' indirob
581 { $$ = newHVREF($2); }
582 ;
583
584arylen : DOLSHARP indirob
585 { $$ = newAVREF($2); }
586 ;
587
588star : '*' indirob
589 { $$ = newGVREF($2); }
590 ;
591
592indirob : WORD
593 { $$ = scalar($1); }
594 | scalar
463ee0b2 595 { $$ = scalar($1); }
79072805
LW
596 | block
597 { $$ = scalar(scope($1)); }
598
93a17b20
LW
599 | PRIVATEREF
600 { $$ = $1; }
8d063cd8
LW
601 ;
602
f0fcb552
LW
603crp : ',' ')'
604 { $$ = 1; }
605 | ')'
606 { $$ = 0; }
607 ;
608
79072805
LW
609crb : ',' ']'
610 { $$ = 1; }
611 | ']'
612 { $$ = 0; }
613 ;
614
615crhb : ',' ';' '}'
616 { $$ = 1; }
617 | ';' '}'
618 { $$ = 0; }
619 ;
450a55e4 620
8d063cd8 621%% /* PROGRAM */