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