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