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