This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix example #4 in perlXStut
[perl5.git] / perly.y
CommitLineData
a0d0e21e 1/* perly.y
a687059c 2 *
a0d0e21e 3 * Copyright (c) 1991-1994, 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?
12 * All that is gold does not glitter, not all those that wander are lost.'
8d063cd8
LW
13 */
14
15%{
79072805 16#include "EXTERN.h"
8d063cd8 17#include "perl.h"
378cc40b 18
a0d0e21e
LW
19static void
20dep()
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
28757baa
PP
49%type <ival> prog decl local format startsub startanonsub
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
a0d0e21e 54%type <opval> listexpr listexprcom indirob
28757baa 55%type <opval> listop method 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);}
79072805
LW
156 ;
157
158else : /* NULL */
159 { $$ = Nullop; }
55497cff 160 | ELSE mblock
79072805 161 { $$ = scope($2); }
55497cff 162 | ELSIF '(' mexpr ')' mblock else
79072805 163 { copline = $1;
bbce6d69
PP
164 $$ = newSTATEOP(0, Nullch,
165 newCONDOP(0, $3, scope($5), $6));
4633a7c4 166 hints |= HINT_BLOCK_SCOPE; }
79072805
LW
167 ;
168
55497cff 169cond : IF '(' remember mexpr ')' mblock else
79072805 170 { copline = $1;
36477c24 171 $$ = block_end($3,
bbce6d69 172 newCONDOP(0, $4, scope($6), $7)); }
55497cff 173 | UNLESS '(' remember miexpr ')' mblock else
79072805 174 { copline = $1;
36477c24 175 $$ = block_end($3,
bbce6d69 176 newCONDOP(0, $4, scope($6), $7)); }
79072805
LW
177 ;
178
179cont : /* NULL */
180 { $$ = Nullop; }
181 | CONTINUE block
182 { $$ = scope($2); }
183 ;
184
55497cff 185loop : label WHILE '(' remember mtexpr ')' mblock cont
79072805 186 { copline = $2;
36477c24 187 $$ = block_end($4,
55497cff 188 newSTATEOP(0, $1,
bbce6d69
PP
189 newWHILEOP(0, 1, (LOOP*)Nullop,
190 $5, $7, $8))); }
55497cff 191 | label UNTIL '(' remember miexpr ')' mblock cont
79072805 192 { copline = $2;
36477c24 193 $$ = block_end($4,
55497cff 194 newSTATEOP(0, $1,
bbce6d69
PP
195 newWHILEOP(0, 1, (LOOP*)Nullop,
196 $5, $7, $8))); }
bbce6d69 197 | label FOR MY remember my_scalar '(' mexpr ')' mblock cont
36477c24 198 { $$ = block_end($4,
bbce6d69
PP
199 newFOROP(0, $1, $2, $5, $7, $9, $10)); }
200 | label FOR scalar '(' remember mexpr ')' mblock cont
36477c24 201 { $$ = block_end($5,
bbce6d69
PP
202 newFOROP(0, $1, $2, mod($3, OP_ENTERLOOP),
203 $6, $8, $9)); }
204 | label FOR '(' remember mexpr ')' mblock cont
36477c24 205 { $$ = block_end($4,
55497cff 206 newFOROP(0, $1, $2, Nullop, $5, $7, $8)); }
bbce6d69 207 | label FOR '(' remember mnexpr ';' mtexpr ';' mnexpr ')' mblock
8d063cd8 208 /* basically fake up an initialize-while lineseq */
55497cff 209 { copline = $2;
36477c24 210 $$ = block_end($4,
bbce6d69
PP
211 append_elem(OP_LINESEQ, scalar($5),
212 newSTATEOP(0, $1,
213 newWHILEOP(0, 1, (LOOP*)Nullop,
214 scalar($7),
215 $11, scalar($9))))); }
79072805
LW
216 | label block cont /* a block is a loop that happens once */
217 { $$ = newSTATEOP(0,
463ee0b2
LW
218 $1, newWHILEOP(0, 1, (LOOP*)Nullop,
219 Nullop, $2, $3)); }
8d063cd8
LW
220 ;
221
222nexpr : /* NULL */
79072805 223 { $$ = Nullop; }
8d063cd8
LW
224 | sideff
225 ;
226
227texpr : /* NULL means true */
79072805 228 { (void)scan_num("1"); $$ = yylval.opval; }
8d063cd8
LW
229 | expr
230 ;
231
55497cff
PP
232iexpr : expr
233 { $$ = invert(scalar($1)); }
234 ;
235
236mexpr : expr
bbce6d69
PP
237 { $$ = $1; intro_my(); }
238 ;
239
240mnexpr : nexpr
241 { $$ = $1; intro_my(); }
55497cff
PP
242 ;
243
244mtexpr : texpr
bbce6d69 245 { $$ = $1; intro_my(); }
55497cff
PP
246 ;
247
248miexpr : iexpr
bbce6d69 249 { $$ = $1; intro_my(); }
55497cff
PP
250 ;
251
8d063cd8
LW
252label : /* empty */
253 { $$ = Nullch; }
32c2e4fb 254 | LABEL
8d063cd8
LW
255 ;
256
8d063cd8
LW
257decl : format
258 { $$ = 0; }
259 | subrout
260 { $$ = 0; }
a687059c
LW
261 | package
262 { $$ = 0; }
a0d0e21e 263 | use
85e6fe83 264 { $$ = 0; }
8d063cd8
LW
265 ;
266
a0d0e21e
LW
267format : FORMAT startsub WORD block
268 { newFORM($2, $3, $4); }
269 | FORMAT startsub block
270 { newFORM($2, Nullop, $3); }
8d063cd8
LW
271 ;
272
28757baa 273subrout : SUB startsub subname proto subbody
4633a7c4 274 { newSUB($2, $3, $4, $5); }
28757baa
PP
275 ;
276
277startsub: /* NULL */ /* start a subroutine scope */
278 { $$ = start_subparse(); }
279 ;
280
281startanonsub: /* NULL */ /* start an anonymous subroutine scope */
282 { $$ = start_subparse();
283 CvANON_on(compcv); }
284 ;
285
286subname : WORD { char *name = SvPVx(((SVOP*)$1)->op_sv, na);
287 if (strEQ(name, "BEGIN") || strEQ(name, "END"))
288 CvUNIQUE_on(compcv);
289 $$ = $1; }
a0d0e21e
LW
290 ;
291
4633a7c4
LW
292proto : /* NULL */
293 { $$ = Nullop; }
294 | THING
295 ;
28757baa
PP
296
297subbody : block { $$ = $1; }
298 | ';' { $$ = Nullop; expect = XSTATE; }
8d063cd8
LW
299 ;
300
a687059c 301package : PACKAGE WORD ';'
79072805 302 { package($2); }
93a17b20
LW
303 | PACKAGE ';'
304 { package(Nullop); }
a687059c
LW
305 ;
306
28757baa
PP
307use : USE startsub
308 { CvUNIQUE_on(compcv); /* It's a BEGIN {} */ }
309 WORD WORD listexpr ';'
310 { utilize($1, $2, $4, $5, $6); }
85e6fe83
LW
311 ;
312
a0d0e21e
LW
313expr : expr ANDOP expr
314 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
315 | expr OROP expr
316 { $$ = newLOGOP($2, 0, $1, $3); }
a0d0e21e
LW
317 | argexpr
318 ;
319
320argexpr : argexpr ','
321 { $$ = $1; }
322 | argexpr ',' term
79072805 323 { $$ = append_elem(OP_LIST, $1, $3); }
a0d0e21e 324 | term
8d063cd8
LW
325 ;
326
a0d0e21e 327listop : LSTOP indirob argexpr
79072805 328 { $$ = convert($1, OPf_STACKED,
a0d0e21e
LW
329 prepend_elem(OP_LIST, newGVREF($1,$2), $3) ); }
330 | FUNC '(' indirob expr ')'
79072805 331 { $$ = convert($1, OPf_STACKED,
a0d0e21e
LW
332 prepend_elem(OP_LIST, newGVREF($1,$3), $4) ); }
333 | term ARROW method '(' listexprcom ')'
4633a7c4 334 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
a0d0e21e 335 append_elem(OP_LIST,
55497cff 336 prepend_elem(OP_LIST, scalar($1), $5),
a0d0e21e 337 newUNOP(OP_METHOD, 0, $3))); }
79072805 338 | METHOD indirob listexpr
4633a7c4 339 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
a0d0e21e 340 append_elem(OP_LIST,
4633a7c4 341 prepend_elem(OP_LIST, $2, $3),
a0d0e21e
LW
342 newUNOP(OP_METHOD, 0, $1))); }
343 | FUNCMETH indirob '(' listexprcom ')'
4633a7c4 344 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
a0d0e21e 345 append_elem(OP_LIST,
4633a7c4 346 prepend_elem(OP_LIST, $2, $4),
a0d0e21e 347 newUNOP(OP_METHOD, 0, $1))); }
79072805
LW
348 | LSTOP listexpr
349 { $$ = convert($1, 0, $2); }
a0d0e21e 350 | FUNC '(' listexprcom ')'
79072805 351 { $$ = convert($1, 0, $3); }
28757baa
PP
352 | LSTOPSUB startanonsub block
353 { $3 = newANONSUB($2, 0, $3); }
354 listexpr %prec LSTOP
4633a7c4 355 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
28757baa
PP
356 append_elem(OP_LIST,
357 prepend_elem(OP_LIST, $3, $5), $1)); }
a687059c
LW
358 ;
359
a0d0e21e
LW
360method : METHOD
361 | scalar
362 ;
363
364term : term ASSIGNOP term
365 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
366 | term POWOP term
79072805 367 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 368 | term MULOP term
79072805
LW
369 { if ($2 != OP_REPEAT)
370 scalar($1);
371 $$ = newBINOP($2, 0, $1, scalar($3)); }
a0d0e21e 372 | term ADDOP term
79072805 373 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 374 | term SHIFTOP term
79072805 375 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 376 | term RELOP term
79072805 377 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 378 | term EQOP term
79072805 379 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 380 | term BITANDOP term
79072805 381 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 382 | term BITOROP term
79072805 383 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
a0d0e21e 384 | term DOTDOT term
79072805 385 { $$ = newRANGE($2, scalar($1), scalar($3));}
a0d0e21e 386 | term ANDAND term
463ee0b2 387 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
a0d0e21e 388 | term OROR term
463ee0b2 389 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
a0d0e21e 390 | term '?' term ':' term
79072805 391 { $$ = newCONDOP(0, $1, $3, $5); }
a0d0e21e 392 | term MATCHOP term
79072805 393 { $$ = bind_match($2, $1, $3); }
8d063cd8 394
a0d0e21e 395 | '-' term %prec UMINUS
79072805 396 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
a687059c
LW
397 | '+' term %prec UMINUS
398 { $$ = $2; }
8d063cd8 399 | '!' term
79072805 400 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
8d063cd8 401 | '~' term
79072805
LW
402 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2));}
403 | REFGEN term
a0d0e21e 404 { $$ = newUNOP(OP_REFGEN, 0, mod($2,OP_REFGEN)); }
79072805
LW
405 | term POSTINC
406 { $$ = newUNOP(OP_POSTINC, 0,
463ee0b2 407 mod(scalar($1), OP_POSTINC)); }
79072805
LW
408 | term POSTDEC
409 { $$ = newUNOP(OP_POSTDEC, 0,
463ee0b2 410 mod(scalar($1), OP_POSTDEC)); }
79072805
LW
411 | PREINC term
412 { $$ = newUNOP(OP_PREINC, 0,
463ee0b2 413 mod(scalar($2), OP_PREINC)); }
79072805
LW
414 | PREDEC term
415 { $$ = newUNOP(OP_PREDEC, 0,
463ee0b2 416 mod(scalar($2), OP_PREDEC)); }
55497cff 417 | local term %prec UNIOP
93a17b20 418 { $$ = localize($2,$1); }
a0d0e21e 419 | '(' expr ')'
79072805 420 { $$ = sawparens($2); }
8d063cd8 421 | '(' ')'
8990e307 422 { $$ = sawparens(newNULLLIST()); }
a0d0e21e 423 | '[' expr ']' %prec '('
79072805
LW
424 { $$ = newANONLIST($2); }
425 | '[' ']' %prec '('
426 { $$ = newANONLIST(Nullop); }
a0d0e21e 427 | HASHBRACK expr ';' '}' %prec '('
79072805
LW
428 { $$ = newANONHASH($2); }
429 | HASHBRACK ';' '}' %prec '('
430 { $$ = newANONHASH(Nullop); }
28757baa 431 | ANONSUB startanonsub proto block %prec '('
4633a7c4 432 { $$ = newANONSUB($2, $3, $4); }
79072805 433 | scalar %prec '('
8d063cd8 434 { $$ = $1; }
c07a80fd
PP
435 | star '{' expr ';' '}'
436 { $$ = newBINOP(OP_GELEM, 0, newGVREF(0,$1), $3); }
79072805 437 | star %prec '('
8d063cd8 438 { $$ = $1; }
79072805
LW
439 | scalar '[' expr ']' %prec '('
440 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); }
441 | term ARROW '[' expr ']' %prec '('
442 { $$ = newBINOP(OP_AELEM, 0,
8990e307 443 ref(newAVREF($1),OP_RV2AV),
79072805 444 scalar($4));}
463ee0b2 445 | term '[' expr ']' %prec '('
a0d0e21e 446 { assertref($1); $$ = newBINOP(OP_AELEM, 0,
8990e307 447 ref(newAVREF($1),OP_RV2AV),
463ee0b2 448 scalar($3));}
79072805 449 | hsh %prec '('
8d063cd8 450 { $$ = $1; }
79072805 451 | ary %prec '('
8d063cd8 452 { $$ = $1; }
79072805
LW
453 | arylen %prec '('
454 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
455 | scalar '{' expr ';' '}' %prec '('
456 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
457 expect = XOPERATOR; }
458 | term ARROW '{' expr ';' '}' %prec '('
459 { $$ = newBINOP(OP_HELEM, 0,
8990e307 460 ref(newHVREF($1),OP_RV2HV),
79072805
LW
461 jmaybe($4));
462 expect = XOPERATOR; }
463ee0b2 463 | term '{' expr ';' '}' %prec '('
a0d0e21e 464 { assertref($1); $$ = newBINOP(OP_HELEM, 0,
8990e307 465 ref(newHVREF($1),OP_RV2HV),
463ee0b2
LW
466 jmaybe($3));
467 expect = XOPERATOR; }
a0d0e21e 468 | '(' expr ')' '[' expr ']' %prec '('
79072805
LW
469 { $$ = newSLICEOP(0, $5, $2); }
470 | '(' ')' '[' expr ']' %prec '('
471 { $$ = newSLICEOP(0, $4, Nullop); }
472 | ary '[' expr ']' %prec '('
473 { $$ = prepend_elem(OP_ASLICE,
474 newOP(OP_PUSHMARK, 0),
79072805
LW
475 newLISTOP(OP_ASLICE, 0,
476 list($3),
a0d0e21e 477 ref($1, OP_ASLICE))); }
79072805
LW
478 | ary '{' expr ';' '}' %prec '('
479 { $$ = prepend_elem(OP_HSLICE,
480 newOP(OP_PUSHMARK, 0),
79072805
LW
481 newLISTOP(OP_HSLICE, 0,
482 list($3),
a0d0e21e 483 ref(oopsHV($1), OP_HSLICE)));
79072805
LW
484 expect = XOPERATOR; }
485 | THING %prec '('
486 { $$ = $1; }
487 | amper
c07a80fd 488 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
79072805 489 | amper '(' ')'
a0d0e21e
LW
490 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
491 | amper '(' expr ')'
492 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
4633a7c4 493 append_elem(OP_LIST, $3, scalar($1))); }
93a17b20 494 | NOAMP WORD listexpr
a0d0e21e 495 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
a5f75d66 496 append_elem(OP_LIST, $3, scalar($2))); }
a0d0e21e 497 | DO term %prec UNIOP
463ee0b2 498 { $$ = newUNOP(OP_DOFILE, 0, scalar($2)); }
79072805
LW
499 | DO block %prec '('
500 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2)); }
8d063cd8 501 | DO WORD '(' ')'
c07a80fd
PP
502 { $$ = newUNOP(OP_ENTERSUB,
503 OPf_SPECIAL|OPf_STACKED,
4633a7c4 504 prepend_elem(OP_LIST,
c07a80fd
PP
505 scalar(newCVREF(
506 (OPpENTERSUB_AMPER<<8),
507 scalar($2)
508 )),Nullop)); dep();}
a0d0e21e 509 | DO WORD '(' expr ')'
c07a80fd
PP
510 { $$ = newUNOP(OP_ENTERSUB,
511 OPf_SPECIAL|OPf_STACKED,
4633a7c4 512 append_elem(OP_LIST,
a0d0e21e 513 $4,
c07a80fd
PP
514 scalar(newCVREF(
515 (OPpENTERSUB_AMPER<<8),
516 scalar($2)
517 )))); dep();}
79072805 518 | DO scalar '(' ')'
a0d0e21e 519 { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
4633a7c4 520 prepend_elem(OP_LIST,
c07a80fd 521 scalar(newCVREF(0,scalar($2))), Nullop)); dep();}
a0d0e21e
LW
522 | DO scalar '(' expr ')'
523 { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
4633a7c4 524 prepend_elem(OP_LIST,
a0d0e21e 525 $4,
c07a80fd 526 scalar(newCVREF(0,scalar($2))))); dep();}
8d063cd8 527 | LOOPEX
85e6fe83
LW
528 { $$ = newOP($1, OPf_SPECIAL);
529 hints |= HINT_BLOCK_SCOPE; }
a0d0e21e 530 | LOOPEX term
8990e307 531 { $$ = newLOOPEX($1,$2); }
c07a80fd
PP
532 | NOTOP argexpr
533 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
8d063cd8 534 | UNIOP
79072805 535 { $$ = newOP($1, 0); }
f0fcb552 536 | UNIOP block
79072805 537 { $$ = newUNOP($1, 0, $2); }
a0d0e21e 538 | UNIOP term
79072805 539 { $$ = newUNOP($1, 0, $2); }
4633a7c4
LW
540 | UNIOPSUB term
541 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
542 append_elem(OP_LIST, $2, scalar($1))); }
8d063cd8 543 | FUNC0
79072805 544 { $$ = newOP($1, 0); }
ae986130 545 | FUNC0 '(' ')'
79072805 546 { $$ = newOP($1, 0); }
4633a7c4 547 | FUNC0SUB
28757baa 548 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
4633a7c4 549 scalar($1)); }
03a14243 550 | FUNC1 '(' ')'
79072805 551 { $$ = newOP($1, OPf_SPECIAL); }
8d063cd8 552 | FUNC1 '(' expr ')'
79072805 553 { $$ = newUNOP($1, 0, $3); }
a0d0e21e 554 | PMFUNC '(' term ')'
79072805 555 { $$ = pmruntime($1, $3, Nullop); }
a0d0e21e 556 | PMFUNC '(' term ',' term ')'
79072805
LW
557 { $$ = pmruntime($1, $3, $5); }
558 | WORD
378cc40b 559 | listop
8d063cd8
LW
560 ;
561
79072805 562listexpr: /* NULL */
8990e307 563 { $$ = Nullop; }
a0d0e21e
LW
564 | argexpr
565 { $$ = $1; }
566 ;
567
568listexprcom: /* NULL */
569 { $$ = Nullop; }
79072805
LW
570 | expr
571 { $$ = $1; }
a0d0e21e
LW
572 | expr ','
573 { $$ = $1; }
79072805
LW
574 ;
575
55497cff
PP
576local : LOCAL { $$ = 0; }
577 | MY { $$ = 1; }
578 ;
579
580my_scalar: scalar
581 { in_my = 0; $$ = my($1); }
582 ;
583
79072805 584amper : '&' indirob
c07a80fd 585 { $$ = newCVREF($1,$2); }
a687059c
LW
586 ;
587
79072805
LW
588scalar : '$' indirob
589 { $$ = newSVREF($2); }
a687059c
LW
590 ;
591
79072805
LW
592ary : '@' indirob
593 { $$ = newAVREF($2); }
594 ;
595
596hsh : '%' indirob
597 { $$ = newHVREF($2); }
598 ;
599
600arylen : DOLSHARP indirob
601 { $$ = newAVREF($2); }
602 ;
603
604star : '*' indirob
a0d0e21e 605 { $$ = newGVREF(0,$2); }
79072805
LW
606 ;
607
608indirob : WORD
609 { $$ = scalar($1); }
610 | scalar
463ee0b2 611 { $$ = scalar($1); }
79072805 612 | block
a0d0e21e 613 { $$ = scope($1); }
79072805 614
93a17b20
LW
615 | PRIVATEREF
616 { $$ = $1; }
8d063cd8
LW
617 ;
618
619%% /* PROGRAM */