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