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