Commit | Line | Data |
---|---|---|
a0d0e21e | 1 | /* perly.y |
a687059c | 2 | * |
f05e27e5 | 3 | * Copyright (c) 1991-2002, 2003, 2004, 2005, 2006 Larry Wall |
2eee27d7 | 4 | * Copyright (c) 2007, 2008, 2009, 2010, 2011 by Larry Wall and others |
a687059c | 5 | * |
9ef589d8 LW |
6 | * You may distribute under the terms of either the GNU General Public |
7 | * License or the Artistic License, as specified in the README file. | |
8d063cd8 | 8 | * |
a0d0e21e LW |
9 | */ |
10 | ||
11 | /* | |
12 | * 'I see,' laughed Strider. 'I look foul and feel fair. Is that it? | |
4ac71550 | 13 | * All that is gold does not glitter, not all those who wander are lost.' |
f05e27e5 | 14 | * |
4ac71550 TC |
15 | * [p.171 of _The Lord of the Rings_, I/x: "Strider"] |
16 | */ | |
17 | ||
18 | /* | |
f05e27e5 | 19 | * This file holds the grammar for the Perl language. If edited, you need |
166f8a29 DM |
20 | * to run regen_perly.pl, which re-creates the files perly.h, perly.tab |
21 | * and perly.act which are derived from this. | |
22 | * | |
a3815e44 | 23 | * The main job of this grammar is to call the various newFOO() |
166f8a29 | 24 | * functions in op.c to build a syntax tree of OP structs. |
61296642 | 25 | * It relies on the lexer in toke.c to do the tokenizing. |
29522234 DM |
26 | * |
27 | * Note: due to the way that the cleanup code works WRT to freeing ops on | |
28 | * the parse stack, it is dangerous to assign to the $n variables within | |
29 | * an action. | |
166f8a29 DM |
30 | */ |
31 | ||
0de566d7 | 32 | /* Make the parser re-entrant. */ |
8d063cd8 | 33 | |
0a2b3d88 | 34 | %define api.pure |
8d063cd8 | 35 | |
28ac2b49 | 36 | %start grammar |
9d116dd7 | 37 | |
8d063cd8 | 38 | %union { |
d5c6462e DM |
39 | I32 ival; /* __DEFAULT__ (marker for regen_perly.pl; |
40 | must always be 1st union member) */ | |
79072805 LW |
41 | char *pval; |
42 | OP *opval; | |
43 | GV *gvval; | |
8d063cd8 LW |
44 | } |
45 | ||
996b0cb8 | 46 | %token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ GRAMSUBSIGNATURE |
28ac2b49 | 47 | |
25a50500 BZ |
48 | %token <ival> '-' '+' '@' '%' |
49 | %token <ival> PERLY_AMPERSAND | |
c588171e | 50 | %token <ival> PERLY_BRACE_OPEN |
d0a6a9c7 | 51 | %token <ival> PERLY_BRACE_CLOSE |
669dd22c | 52 | %token <ival> PERLY_BRACKET_OPEN |
fceeeb77 | 53 | %token <ival> PERLY_BRACKET_CLOSE |
da4bce7d | 54 | %token <ival> PERLY_DOT |
db83e45c | 55 | %token <ival> PERLY_EQUAL_SIGN |
5adeeefb | 56 | %token <ival> PERLY_SEMICOLON |
f0fcb552 | 57 | |
185c2e96 | 58 | %token <opval> BAREWORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST |
7eb971ee | 59 | %token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB |
88e1f1a2 | 60 | %token <opval> PLUGEXPR PLUGSTMT |
01719201 | 61 | %token <opval> LABEL |
436ddf68 | 62 | %token <ival> FORMAT SUB SIGSUB ANONSUB ANON_SIGSUB PACKAGE USE |
b5bbe64a | 63 | %token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR |
7896dde7 | 64 | %token <ival> GIVEN WHEN DEFAULT |
b5bbe64a JH |
65 | %token <ival> LOOPEX DOTDOT YADAYADA |
66 | %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP | |
02b85d3d | 67 | %token <ival> MULOP ADDOP |
b5bbe64a JH |
68 | %token <ival> DOLSHARP DO HASHBRACK NOAMP |
69 | %token <ival> LOCAL MY REQUIRE | |
70 | %token <ival> COLONATTR FORMLBRACK FORMRBRACK | |
69afcc21 | 71 | %token <ival> SUBLEXSTART SUBLEXEND |
f05e27e5 | 72 | |
727a8fe5 | 73 | %type <ival> grammar remember mremember |
f05e27e5 | 74 | %type <ival> startsub startanonsub startformsub |
b5bbe64a | 75 | |
b5a64814 | 76 | %type <ival> mintro |
f05e27e5 | 77 | |
8e720305 | 78 | %type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else |
fad39ff1 | 79 | %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff |
53443c95 | 80 | %type <opval> condition |
76eba8ab | 81 | %type <opval> sliceme kvslice gelem |
08b3e84f | 82 | %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr |
9b6b7be8 | 83 | %type <opval> optlistexpr optexpr optrepl indirob listop method |
75230cc1 | 84 | %type <opval> formname subname proto cont my_scalar my_var |
d39c26a6 | 85 | %type <opval> refgen_topic formblock |
f05e27e5 | 86 | %type <opval> subattrlist myattrlist myattrterm myterm |
75230cc1 | 87 | %type <opval> termbinop termunop anonymous termdo |
02b85d3d | 88 | %type <opval> termrelop relopchain termeqop eqopchain |
d3d9da4a DM |
89 | %type <ival> sigslurpsigil |
90 | %type <opval> sigvarname sigdefault sigscalarelem sigslurpelem | |
996b0cb8 | 91 | %type <opval> sigelem siglist siglistornull subsigguts subsignature optsubsignature |
75230cc1 | 92 | %type <opval> subbody optsubbody sigsubbody optsigsubbody |
705fe0e5 | 93 | %type <opval> formstmtseq formline formarg |
79072805 | 94 | |
b5bbe64a | 95 | %nonassoc <ival> PREC_LOW |
fad39ff1 SM |
96 | %nonassoc LOOPEX |
97 | ||
b5bbe64a JH |
98 | %left <ival> OROP DOROP |
99 | %left <ival> ANDOP | |
100 | %right <ival> NOTOP | |
36477c24 | 101 | %nonassoc LSTOP LSTOPSUB |
b5bbe64a JH |
102 | %left <ival> ',' |
103 | %right <ival> ASSIGNOP | |
104 | %right <ival> '?' ':' | |
29d69c3c | 105 | %nonassoc DOTDOT |
b5bbe64a JH |
106 | %left <ival> OROR DORDOR |
107 | %left <ival> ANDAND | |
108 | %left <ival> BITOROP | |
109 | %left <ival> BITANDOP | |
02b85d3d Z |
110 | %left <ival> CHEQOP NCEQOP |
111 | %left <ival> CHRELOP NCRELOP | |
36477c24 | 112 | %nonassoc UNIOP UNIOPSUB |
20515881 | 113 | %nonassoc REQUIRE |
b5bbe64a | 114 | %left <ival> SHIFTOP |
a687059c LW |
115 | %left ADDOP |
116 | %left MULOP | |
b5bbe64a JH |
117 | %left <ival> MATCHOP |
118 | %right <ival> '!' '~' UMINUS REFGEN | |
119 | %right <ival> POWOP | |
120 | %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN | |
121 | %left <ival> ARROW | |
122 | %nonassoc <ival> ')' | |
123 | %left <ival> '(' | |
669dd22c | 124 | %left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN |
8d063cd8 LW |
125 | |
126 | %% /* RULES */ | |
127 | ||
28ac2b49 | 128 | /* Top-level choice of what kind of thing yyparse was called to parse */ |
727a8fe5 Z |
129 | grammar : GRAMPROG |
130 | { | |
624fa8bd | 131 | parser->expect = XSTATE; |
5a2060e2 | 132 | $<ival>$ = 0; |
727a8fe5 Z |
133 | } |
134 | remember stmtseq | |
135 | { | |
53443c95 | 136 | newPROG(block_end($remember,$stmtseq)); |
8635e3c2 | 137 | PL_compiling.cop_seq = 0; |
727a8fe5 Z |
138 | $$ = 0; |
139 | } | |
78cdf107 Z |
140 | | GRAMEXPR |
141 | { | |
142 | parser->expect = XTERM; | |
5a2060e2 | 143 | $<ival>$ = 0; |
78cdf107 | 144 | } |
09b1cffe | 145 | optexpr |
78cdf107 | 146 | { |
53443c95 | 147 | PL_eval_root = $optexpr; |
78cdf107 Z |
148 | $$ = 0; |
149 | } | |
e53d8f76 Z |
150 | | GRAMBLOCK |
151 | { | |
152 | parser->expect = XBLOCK; | |
5a2060e2 | 153 | $<ival>$ = 0; |
e53d8f76 Z |
154 | } |
155 | block | |
156 | { | |
5f211341 | 157 | PL_pad_reset_pending = TRUE; |
53443c95 | 158 | PL_eval_root = $block; |
8359b381 Z |
159 | $$ = 0; |
160 | yyunlex(); | |
0f8490d1 | 161 | parser->yychar = yytoken = YYEOF; |
8359b381 Z |
162 | } |
163 | | GRAMBARESTMT | |
164 | { | |
165 | parser->expect = XSTATE; | |
5a2060e2 | 166 | $<ival>$ = 0; |
8359b381 Z |
167 | } |
168 | barestmt | |
169 | { | |
170 | PL_pad_reset_pending = TRUE; | |
53443c95 | 171 | PL_eval_root = $barestmt; |
e53d8f76 Z |
172 | $$ = 0; |
173 | yyunlex(); | |
0f8490d1 | 174 | parser->yychar = yytoken = YYEOF; |
e53d8f76 | 175 | } |
9eb5c532 | 176 | | GRAMFULLSTMT |
28ac2b49 | 177 | { |
9eb5c532 | 178 | parser->expect = XSTATE; |
5a2060e2 | 179 | $<ival>$ = 0; |
9eb5c532 Z |
180 | } |
181 | fullstmt | |
182 | { | |
5f211341 | 183 | PL_pad_reset_pending = TRUE; |
53443c95 | 184 | PL_eval_root = $fullstmt; |
28ac2b49 Z |
185 | $$ = 0; |
186 | yyunlex(); | |
0f8490d1 | 187 | parser->yychar = yytoken = YYEOF; |
28ac2b49 | 188 | } |
07ffcb73 Z |
189 | | GRAMSTMTSEQ |
190 | { | |
191 | parser->expect = XSTATE; | |
5a2060e2 | 192 | $<ival>$ = 0; |
07ffcb73 | 193 | } |
5f211341 | 194 | stmtseq |
07ffcb73 | 195 | { |
53443c95 | 196 | PL_eval_root = $stmtseq; |
07ffcb73 Z |
197 | $$ = 0; |
198 | } | |
996b0cb8 PLE |
199 | | GRAMSUBSIGNATURE |
200 | { | |
201 | parser->expect = XSTATE; | |
202 | $<ival>$ = 0; | |
203 | } | |
204 | subsigguts | |
205 | { | |
53443c95 | 206 | PL_eval_root = $subsigguts; |
996b0cb8 PLE |
207 | $$ = 0; |
208 | } | |
07ffcb73 Z |
209 | ; |
210 | ||
891be019 | 211 | /* An ordinary block */ |
d0a6a9c7 | 212 | block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE |
c588171e BZ |
213 | { if (parser->copline > (line_t)$PERLY_BRACE_OPEN) |
214 | parser->copline = (line_t)$PERLY_BRACE_OPEN; | |
53443c95 | 215 | $$ = block_end($remember, $stmtseq); |
f05e27e5 | 216 | } |
a0d0e21e LW |
217 | ; |
218 | ||
7c70caa5 | 219 | /* format body */ |
db83e45c BZ |
220 | formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT |
221 | { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN) | |
222 | parser->copline = (line_t)$PERLY_EQUAL_SIGN; | |
53443c95 | 223 | $$ = block_end($remember, $formstmtseq); |
7c70caa5 FC |
224 | } |
225 | ; | |
226 | ||
55497cff | 227 | remember: /* NULL */ /* start a full lexical scope */ |
34b54951 FC |
228 | { $$ = block_start(TRUE); |
229 | parser->parsed_sub = 0; } | |
55497cff PP |
230 | ; |
231 | ||
d0a6a9c7 | 232 | mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE |
c588171e BZ |
233 | { if (parser->copline > (line_t)$PERLY_BRACE_OPEN) |
234 | parser->copline = (line_t)$PERLY_BRACE_OPEN; | |
53443c95 | 235 | $$ = block_end($mremember, $stmtseq); |
f05e27e5 | 236 | } |
55497cff PP |
237 | ; |
238 | ||
239 | mremember: /* NULL */ /* start a partial lexical scope */ | |
34b54951 FC |
240 | { $$ = block_start(FALSE); |
241 | parser->parsed_sub = 0; } | |
8d063cd8 LW |
242 | ; |
243 | ||
eae48c89 | 244 | /* A sequence of statements in the program */ |
5f211341 | 245 | stmtseq : /* NULL */ |
a9f5ab8d | 246 | { $$ = NULL; } |
53443c95 BZ |
247 | | stmtseq[list] fullstmt |
248 | { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt); | |
3280af22 | 249 | PL_pad_reset_pending = TRUE; |
53443c95 | 250 | if ($list && $fullstmt) |
503de470 DM |
251 | PL_hints |= HINT_BLOCK_SCOPE; |
252 | } | |
8d063cd8 LW |
253 | ; |
254 | ||
705fe0e5 FC |
255 | /* A sequence of format lines */ |
256 | formstmtseq: /* NULL */ | |
a9f5ab8d | 257 | { $$ = NULL; } |
53443c95 BZ |
258 | | formstmtseq[list] formline |
259 | { $$ = op_append_list(OP_LINESEQ, $list, $formline); | |
705fe0e5 | 260 | PL_pad_reset_pending = TRUE; |
53443c95 | 261 | if ($list && $formline) |
705fe0e5 FC |
262 | PL_hints |= HINT_BLOCK_SCOPE; |
263 | } | |
264 | ; | |
265 | ||
8e720305 Z |
266 | /* A statement in the program, including optional labels */ |
267 | fullstmt: barestmt | |
eae48c89 | 268 | { |
53443c95 | 269 | $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL; |
eae48c89 | 270 | } |
8e720305 | 271 | | labfullstmt |
53443c95 | 272 | { $$ = $labfullstmt; } |
8e720305 Z |
273 | ; |
274 | ||
275 | labfullstmt: LABEL barestmt | |
276 | { | |
53443c95 | 277 | SV *label = cSVOPx_sv($LABEL); |
01719201 | 278 | $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8, |
53443c95 BZ |
279 | savepv(SvPVX_const(label)), $barestmt); |
280 | op_free($LABEL); | |
8e720305 | 281 | } |
53443c95 | 282 | | LABEL labfullstmt[list] |
8e720305 | 283 | { |
53443c95 | 284 | SV *label = cSVOPx_sv($LABEL); |
01719201 | 285 | $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8, |
53443c95 BZ |
286 | savepv(SvPVX_const(label)), $list); |
287 | op_free($LABEL); | |
8e720305 | 288 | } |
eae48c89 Z |
289 | ; |
290 | ||
291 | /* A bare statement, lacking label and other aspects of state op */ | |
292 | barestmt: PLUGSTMT | |
53443c95 | 293 | { $$ = $PLUGSTMT; } |
7c70caa5 | 294 | | FORMAT startformsub formname formblock |
f05e27e5 | 295 | { |
eae48c89 | 296 | CV *fmtcv = PL_compcv; |
53443c95 | 297 | newFORM($startformsub, $formname, $formblock); |
a9f5ab8d | 298 | $$ = NULL; |
4a273b91 | 299 | if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) { |
74a9453a | 300 | pad_add_weakref(fmtcv); |
f05e27e5 | 301 | } |
8b9fb2f9 | 302 | parser->parsed_sub = 1; |
eae48c89 | 303 | } |
50278755 | 304 | | SUB subname startsub |
75230cc1 DM |
305 | /* sub declaration or definition not within scope |
306 | of 'use feature "signatures"'*/ | |
50278755 | 307 | { |
53443c95 | 308 | init_named_cv(PL_compcv, $subname); |
624fa8bd FC |
309 | parser->in_my = 0; |
310 | parser->in_my_stash = NULL; | |
764212cf | 311 | } |
75230cc1 | 312 | proto subattrlist optsubbody |
eae48c89 Z |
313 | { |
314 | SvREFCNT_inc_simple_void(PL_compcv); | |
53443c95 BZ |
315 | $subname->op_type == OP_CONST |
316 | ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody) | |
317 | : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody) | |
50278755 | 318 | ; |
a9f5ab8d | 319 | $$ = NULL; |
764212cf | 320 | intro_my(); |
34b54951 | 321 | parser->parsed_sub = 1; |
f05e27e5 | 322 | } |
436ddf68 | 323 | | SIGSUB subname startsub |
75230cc1 DM |
324 | /* sub declaration or definition under 'use feature |
325 | * "signatures"'. (Note that a signature isn't | |
326 | * allowed in a declaration) | |
327 | */ | |
436ddf68 | 328 | { |
53443c95 | 329 | init_named_cv(PL_compcv, $subname); |
436ddf68 DM |
330 | parser->in_my = 0; |
331 | parser->in_my_stash = NULL; | |
332 | } | |
75230cc1 | 333 | subattrlist optsigsubbody |
436ddf68 DM |
334 | { |
335 | SvREFCNT_inc_simple_void(PL_compcv); | |
53443c95 BZ |
336 | $subname->op_type == OP_CONST |
337 | ? newATTRSUB($startsub, $subname, NULL, $subattrlist, $optsigsubbody) | |
338 | : newMYSUB( $startsub, $subname, NULL, $subattrlist, $optsigsubbody) | |
436ddf68 DM |
339 | ; |
340 | $$ = NULL; | |
341 | intro_my(); | |
342 | parser->parsed_sub = 1; | |
343 | } | |
5adeeefb | 344 | | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_SEMICOLON |
5f211341 | 345 | { |
53443c95 BZ |
346 | package($package); |
347 | if ($version) | |
348 | package_version($version); | |
a9f5ab8d | 349 | $$ = NULL; |
eae48c89 Z |
350 | } |
351 | | USE startsub | |
352 | { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ } | |
5adeeefb | 353 | BAREWORD[version] BAREWORD[module] optlistexpr PERLY_SEMICOLON |
eae48c89 Z |
354 | { |
355 | SvREFCNT_inc_simple_void(PL_compcv); | |
53443c95 | 356 | utilize($USE, $startsub, $version, $module, $optlistexpr); |
34b54951 | 357 | parser->parsed_sub = 1; |
a9f5ab8d | 358 | $$ = NULL; |
eae48c89 | 359 | } |
417a992d | 360 | | IF '(' remember mexpr ')' mblock else |
eae48c89 | 361 | { |
53443c95 BZ |
362 | $$ = block_end($remember, |
363 | newCONDOP(0, $mexpr, op_scope($mblock), $else)); | |
364 | parser->copline = (line_t)$IF; | |
eae48c89 | 365 | } |
08b3e84f | 366 | | UNLESS '(' remember mexpr ')' mblock else |
eae48c89 | 367 | { |
53443c95 BZ |
368 | $$ = block_end($remember, |
369 | newCONDOP(0, $mexpr, $else, op_scope($mblock))); | |
370 | parser->copline = (line_t)$UNLESS; | |
eae48c89 | 371 | } |
b5a64814 | 372 | | GIVEN '(' remember mexpr ')' mblock |
eae48c89 | 373 | { |
53443c95 BZ |
374 | $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0)); |
375 | parser->copline = (line_t)$GIVEN; | |
eae48c89 | 376 | } |
7896dde7 | 377 | | WHEN '(' remember mexpr ')' mblock |
53443c95 | 378 | { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); } |
7896dde7 | 379 | | DEFAULT block |
53443c95 | 380 | { $$ = newWHENOP(0, op_scope($block)); } |
417a992d | 381 | | WHILE '(' remember texpr ')' mintro mblock cont |
eae48c89 | 382 | { |
53443c95 | 383 | $$ = block_end($remember, |
a9f5ab8d | 384 | newWHILEOP(0, 1, NULL, |
53443c95 BZ |
385 | $texpr, $mblock, $cont, $mintro)); |
386 | parser->copline = (line_t)$WHILE; | |
eae48c89 | 387 | } |
417a992d | 388 | | UNTIL '(' remember iexpr ')' mintro mblock cont |
eae48c89 | 389 | { |
53443c95 | 390 | $$ = block_end($remember, |
a9f5ab8d | 391 | newWHILEOP(0, 1, NULL, |
53443c95 BZ |
392 | $iexpr, $mblock, $cont, $mintro)); |
393 | parser->copline = (line_t)$UNTIL; | |
eae48c89 | 394 | } |
5adeeefb | 395 | | FOR '(' remember mnexpr[init_mnexpr] PERLY_SEMICOLON |
2d0e3c96 | 396 | { parser->expect = XTERM; } |
5adeeefb | 397 | texpr PERLY_SEMICOLON |
2d0e3c96 | 398 | { parser->expect = XTERM; } |
53443c95 | 399 | mintro mnexpr[iterate_mnexpr] ')' |
eae48c89 Z |
400 | mblock |
401 | { | |
53443c95 | 402 | OP *initop = $init_mnexpr; |
a9f5ab8d | 403 | OP *forop = newWHILEOP(0, 1, NULL, |
53443c95 | 404 | scalar($texpr), $mblock, $iterate_mnexpr, $mintro); |
eae48c89 Z |
405 | if (initop) { |
406 | forop = op_prepend_elem(OP_LINESEQ, initop, | |
407 | op_append_elem(OP_LINESEQ, | |
408 | newOP(OP_UNSTACK, OPf_SPECIAL), | |
409 | forop)); | |
5f211341 | 410 | } |
0f602692 | 411 | PL_hints |= HINT_BLOCK_SCOPE; |
53443c95 BZ |
412 | $$ = block_end($remember, forop); |
413 | parser->copline = (line_t)$FOR; | |
eae48c89 | 414 | } |
417a992d | 415 | | FOR MY remember my_scalar '(' mexpr ')' mblock cont |
eae48c89 | 416 | { |
53443c95 BZ |
417 | $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont)); |
418 | parser->copline = (line_t)$FOR; | |
eae48c89 | 419 | } |
417a992d | 420 | | FOR scalar '(' remember mexpr ')' mblock cont |
eae48c89 | 421 | { |
53443c95 BZ |
422 | $$ = block_end($remember, newFOROP(0, |
423 | op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont)); | |
424 | parser->copline = (line_t)$FOR; | |
eae48c89 | 425 | } |
e118fea3 | 426 | | FOR my_refgen remember my_var |
53443c95 | 427 | { parser->in_my = 0; $<opval>$ = my($my_var); }[variable] |
d39c26a6 FC |
428 | '(' mexpr ')' mblock cont |
429 | { | |
430 | $$ = block_end( | |
53443c95 | 431 | $remember, |
d39c26a6 FC |
432 | newFOROP(0, |
433 | op_lvalue( | |
434 | newUNOP(OP_REFGEN, 0, | |
53443c95 | 435 | $<opval>variable), |
d39c26a6 | 436 | OP_ENTERLOOP), |
53443c95 | 437 | $mexpr, $mblock, $cont) |
d39c26a6 | 438 | ); |
53443c95 | 439 | parser->copline = (line_t)$FOR; |
d39c26a6 FC |
440 | } |
441 | | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont | |
442 | { | |
53443c95 | 443 | $$ = block_end($remember, newFOROP( |
d39c26a6 | 444 | 0, op_lvalue(newUNOP(OP_REFGEN, 0, |
53443c95 BZ |
445 | $refgen_topic), |
446 | OP_ENTERLOOP), $mexpr, $mblock, $cont)); | |
447 | parser->copline = (line_t)$FOR; | |
d39c26a6 | 448 | } |
417a992d | 449 | | FOR '(' remember mexpr ')' mblock cont |
eae48c89 | 450 | { |
53443c95 BZ |
451 | $$ = block_end($remember, |
452 | newFOROP(0, NULL, $mexpr, $mblock, $cont)); | |
453 | parser->copline = (line_t)$FOR; | |
eae48c89 Z |
454 | } |
455 | | block cont | |
456 | { | |
457 | /* a block is a loop that happens once */ | |
a9f5ab8d | 458 | $$ = newWHILEOP(0, 1, NULL, |
53443c95 | 459 | NULL, $block, $cont, 0); |
eae48c89 | 460 | } |
c588171e | 461 | | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember |
eae48c89 | 462 | { |
53443c95 BZ |
463 | package($package); |
464 | if ($version) { | |
465 | package_version($version); | |
eae48c89 Z |
466 | } |
467 | } | |
d0a6a9c7 | 468 | stmtseq PERLY_BRACE_CLOSE |
eae48c89 Z |
469 | { |
470 | /* a block is a loop that happens once */ | |
a9f5ab8d | 471 | $$ = newWHILEOP(0, 1, NULL, |
53443c95 | 472 | NULL, block_end($remember, $stmtseq), NULL, 0); |
c588171e BZ |
473 | if (parser->copline > (line_t)$PERLY_BRACE_OPEN) |
474 | parser->copline = (line_t)$PERLY_BRACE_OPEN; | |
eae48c89 | 475 | } |
5adeeefb | 476 | | sideff PERLY_SEMICOLON |
eae48c89 | 477 | { |
53443c95 | 478 | $$ = $sideff; |
eae48c89 | 479 | } |
5adeeefb | 480 | | YADAYADA PERLY_SEMICOLON |
29d69c3c Z |
481 | { |
482 | $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0), | |
483 | newSVOP(OP_CONST, 0, newSVpvs("Unimplemented"))); | |
484 | } | |
5adeeefb | 485 | | PERLY_SEMICOLON |
eae48c89 | 486 | { |
a9f5ab8d | 487 | $$ = NULL; |
624fa8bd | 488 | parser->copline = NOLINE; |
5f211341 | 489 | } |
8d063cd8 LW |
490 | ; |
491 | ||
705fe0e5 FC |
492 | /* Format line */ |
493 | formline: THING formarg | |
494 | { OP *list; | |
53443c95 BZ |
495 | if ($formarg) { |
496 | OP *term = $formarg; | |
497 | list = op_append_elem(OP_LIST, $THING, term); | |
705fe0e5 FC |
498 | } |
499 | else { | |
53443c95 | 500 | list = $THING; |
705fe0e5 | 501 | } |
624fa8bd FC |
502 | if (parser->copline == NOLINE) |
503 | parser->copline = CopLINE(PL_curcop)-1; | |
504 | else parser->copline--; | |
705fe0e5 | 505 | $$ = newSTATEOP(0, NULL, |
03d05f6e | 506 | op_convert_list(OP_FORMLINE, 0, list)); |
705fe0e5 FC |
507 | } |
508 | ; | |
509 | ||
510 | formarg : /* NULL */ | |
511 | { $$ = NULL; } | |
512 | | FORMLBRACK stmtseq FORMRBRACK | |
53443c95 | 513 | { $$ = op_unscope($stmtseq); } |
705fe0e5 FC |
514 | ; |
515 | ||
53443c95 BZ |
516 | condition: expr |
517 | ; | |
518 | ||
891be019 | 519 | /* An expression which may have a side-effect */ |
a687059c | 520 | sideff : error |
a9f5ab8d | 521 | { $$ = NULL; } |
53443c95 BZ |
522 | | expr[body] |
523 | { $$ = $body; } | |
524 | | expr[body] IF condition | |
525 | { $$ = newLOGOP(OP_AND, 0, $condition, $body); } | |
526 | | expr[body] UNLESS condition | |
527 | { $$ = newLOGOP(OP_OR, 0, $condition, $body); } | |
528 | | expr[body] WHILE condition | |
529 | { $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); } | |
530 | | expr[body] UNTIL iexpr | |
531 | { $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); } | |
532 | | expr[body] FOR condition | |
533 | { $$ = newFOROP(0, NULL, $condition, $body, NULL); | |
534 | parser->copline = (line_t)$FOR; } | |
535 | | expr[body] WHEN condition | |
536 | { $$ = newWHENOP($condition, op_scope($body)); } | |
79072805 LW |
537 | ; |
538 | ||
891be019 | 539 | /* else and elsif blocks */ |
79072805 | 540 | else : /* NULL */ |
a9f5ab8d | 541 | { $$ = NULL; } |
55497cff | 542 | | ELSE mblock |
3ad73efd | 543 | { |
53443c95 BZ |
544 | ($mblock)->op_flags |= OPf_PARENS; |
545 | $$ = op_scope($mblock); | |
f05e27e5 | 546 | } |
53443c95 BZ |
547 | | ELSIF '(' mexpr ')' mblock else[else.recurse] |
548 | { parser->copline = (line_t)$ELSIF; | |
3ad73efd | 549 | $$ = newCONDOP(0, |
53443c95 BZ |
550 | newSTATEOP(OPf_SPECIAL,NULL,$mexpr), |
551 | op_scope($mblock), $[else.recurse]); | |
3ad73efd | 552 | PL_hints |= HINT_BLOCK_SCOPE; |
f05e27e5 | 553 | } |
79072805 LW |
554 | ; |
555 | ||
891be019 | 556 | /* Continue blocks */ |
79072805 | 557 | cont : /* NULL */ |
a9f5ab8d | 558 | { $$ = NULL; } |
79072805 | 559 | | CONTINUE block |
53443c95 | 560 | { $$ = op_scope($block); } |
79072805 LW |
561 | ; |
562 | ||
a034e688 DM |
563 | /* determine whether there are any new my declarations */ |
564 | mintro : /* NULL */ | |
565 | { $$ = (PL_min_intro_pending && | |
566 | PL_max_intro_pending >= PL_min_intro_pending); | |
567 | intro_my(); } | |
568 | ||
891be019 | 569 | /* Normal expression */ |
8d063cd8 | 570 | nexpr : /* NULL */ |
a9f5ab8d | 571 | { $$ = NULL; } |
8d063cd8 LW |
572 | | sideff |
573 | ; | |
574 | ||
891be019 | 575 | /* Boolean expression */ |
8d063cd8 | 576 | texpr : /* NULL means true */ |
f05e27e5 DM |
577 | { YYSTYPE tmplval; |
578 | (void)scan_num("1", &tmplval); | |
579 | $$ = tmplval.opval; } | |
8d063cd8 LW |
580 | | expr |
581 | ; | |
582 | ||
891be019 | 583 | /* Inverted boolean expression */ |
55497cff | 584 | iexpr : expr |
53443c95 | 585 | { $$ = invert(scalar($expr)); } |
55497cff PP |
586 | ; |
587 | ||
891be019 | 588 | /* Expression with its own lexical scope */ |
55497cff | 589 | mexpr : expr |
53443c95 | 590 | { $$ = $expr; intro_my(); } |
bbce6d69 PP |
591 | ; |
592 | ||
593 | mnexpr : nexpr | |
53443c95 | 594 | { $$ = $nexpr; intro_my(); } |
55497cff PP |
595 | ; |
596 | ||
53443c95 | 597 | formname: BAREWORD { $$ = $BAREWORD; } |
a9f5ab8d | 598 | | /* NULL */ { $$ = NULL; } |
8d063cd8 LW |
599 | ; |
600 | ||
fa83b5b6 | 601 | startsub: /* NULL */ /* start a regular subroutine scope */ |
a8ff2fa6 DM |
602 | { $$ = start_subparse(FALSE, 0); |
603 | SAVEFREESV(PL_compcv); } | |
f05e27e5 | 604 | |
28757baa PP |
605 | ; |
606 | ||
607 | startanonsub: /* NULL */ /* start an anonymous subroutine scope */ | |
a8ff2fa6 DM |
608 | { $$ = start_subparse(FALSE, CVf_ANON); |
609 | SAVEFREESV(PL_compcv); } | |
28757baa PP |
610 | ; |
611 | ||
44a8e56a | 612 | startformsub: /* NULL */ /* start a format subroutine scope */ |
a8ff2fa6 DM |
613 | { $$ = start_subparse(TRUE, 0); |
614 | SAVEFREESV(PL_compcv); } | |
44a8e56a PP |
615 | ; |
616 | ||
891be019 | 617 | /* Name of a subroutine - must be a bareword, could be special */ |
185c2e96 | 618 | subname : BAREWORD |
4210d3f1 | 619 | | PRIVATEREF |
a0d0e21e LW |
620 | ; |
621 | ||
891be019 | 622 | /* Subroutine prototype */ |
4633a7c4 | 623 | proto : /* NULL */ |
a9f5ab8d | 624 | { $$ = NULL; } |
4633a7c4 LW |
625 | | THING |
626 | ; | |
28757baa | 627 | |
891be019 | 628 | /* Optional list of subroutine attributes */ |
09bef843 | 629 | subattrlist: /* NULL */ |
a9f5ab8d | 630 | { $$ = NULL; } |
09bef843 | 631 | | COLONATTR THING |
53443c95 | 632 | { $$ = $THING; } |
09bef843 | 633 | | COLONATTR |
a9f5ab8d | 634 | { $$ = NULL; } |
09bef843 SB |
635 | ; |
636 | ||
891be019 | 637 | /* List of attributes for a "my" variable declaration */ |
09bef843 | 638 | myattrlist: COLONATTR THING |
53443c95 | 639 | { $$ = $THING; } |
09bef843 | 640 | | COLONATTR |
a9f5ab8d | 641 | { $$ = NULL; } |
09bef843 SB |
642 | ; |
643 | ||
abcf453d | 644 | |
d3d9da4a DM |
645 | |
646 | /* -------------------------------------- | |
647 | * subroutine signature parsing | |
648 | */ | |
649 | ||
650 | /* the '' or 'foo' part of a '$' or '@foo' etc signature variable */ | |
49fb8620 | 651 | sigvarname: /* NULL */ |
a9f5ab8d | 652 | { parser->in_my = 0; $$ = NULL; } |
d3d9da4a | 653 | | PRIVATEREF |
53443c95 | 654 | { parser->in_my = 0; $$ = $PRIVATEREF; } |
d3d9da4a DM |
655 | ; |
656 | ||
657 | sigslurpsigil: | |
658 | '@' | |
659 | { $$ = '@'; } | |
660 | | '%' | |
661 | { $$ = '%'; } | |
662 | ||
663 | /* @, %, @foo, %foo */ | |
664 | sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */ | |
665 | { | |
53443c95 BZ |
666 | I32 sigil = $sigslurpsigil; |
667 | OP *var = $sigvarname; | |
668 | OP *defexpr = $sigdefault; | |
d3d9da4a | 669 | |
036bbc13 | 670 | if (parser->sig_slurpy) |
d3d9da4a | 671 | yyerror("Multiple slurpy parameters not allowed"); |
036bbc13 | 672 | parser->sig_slurpy = (char)sigil; |
d3d9da4a DM |
673 | |
674 | if (defexpr) | |
bb6b75cd | 675 | yyerror("A slurpy parameter may not have " |
d3d9da4a DM |
676 | "a default value"); |
677 | ||
a9f5ab8d | 678 | $$ = var ? newSTATEOP(0, NULL, var) : NULL; |
d3d9da4a DM |
679 | } |
680 | ; | |
681 | ||
682 | /* default part of sub signature scalar element: i.e. '= default_expr' */ | |
683 | sigdefault: /* NULL */ | |
a9f5ab8d | 684 | { $$ = NULL; } |
d3d9da4a DM |
685 | | ASSIGNOP |
686 | { $$ = newOP(OP_NULL, 0); } | |
687 | | ASSIGNOP term | |
53443c95 | 688 | { $$ = $term; } |
d3d9da4a DM |
689 | |
690 | ||
691 | /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */ | |
692 | sigscalarelem: | |
693 | '$' sigvarname sigdefault | |
694 | { | |
53443c95 BZ |
695 | OP *var = $sigvarname; |
696 | OP *defexpr = $sigdefault; | |
d3d9da4a | 697 | |
036bbc13 | 698 | if (parser->sig_slurpy) |
d3d9da4a DM |
699 | yyerror("Slurpy parameter not last"); |
700 | ||
036bbc13 | 701 | parser->sig_elems++; |
d3d9da4a | 702 | |
d3d9da4a | 703 | if (defexpr) { |
036bbc13 | 704 | parser->sig_optelems++; |
4fa06845 DM |
705 | |
706 | if ( defexpr->op_type == OP_NULL | |
d3d9da4a DM |
707 | && !(defexpr->op_flags & OPf_KIDS)) |
708 | { | |
4fa06845 DM |
709 | /* handle '$=' special case */ |
710 | if (var) | |
711 | yyerror("Optional parameter " | |
712 | "lacks default expression"); | |
d3d9da4a DM |
713 | op_free(defexpr); |
714 | } | |
4fa06845 DM |
715 | else { |
716 | /* a normal '=default' expression */ | |
717 | OP *defop = (OP*)alloc_LOGOP(OP_ARGDEFELEM, | |
718 | defexpr, | |
719 | LINKLIST(defexpr)); | |
720 | /* re-purpose op_targ to hold @_ index */ | |
6daeaaa3 | 721 | defop->op_targ = |
036bbc13 | 722 | (PADOFFSET)(parser->sig_elems - 1); |
4fa06845 DM |
723 | |
724 | if (var) { | |
725 | var->op_flags |= OPf_STACKED; | |
726 | (void)op_sibling_splice(var, | |
727 | NULL, 0, defop); | |
728 | scalar(defop); | |
729 | } | |
730 | else | |
731 | var = newUNOP(OP_NULL, 0, defop); | |
732 | ||
733 | LINKLIST(var); | |
734 | /* NB: normally the first child of a | |
735 | * logop is executed before the logop, | |
736 | * and it pushes a boolean result | |
737 | * ready for the logop. For ARGDEFELEM, | |
738 | * the op itself does the boolean | |
739 | * calculation, so set the first op to | |
740 | * it instead. | |
741 | */ | |
742 | var->op_next = defop; | |
743 | defexpr->op_next = var; | |
d3d9da4a DM |
744 | } |
745 | } | |
746 | else { | |
036bbc13 | 747 | if (parser->sig_optelems) |
d3d9da4a DM |
748 | yyerror("Mandatory parameter " |
749 | "follows optional parameter"); | |
d3d9da4a DM |
750 | } |
751 | ||
a9f5ab8d | 752 | $$ = var ? newSTATEOP(0, NULL, var) : NULL; |
d3d9da4a DM |
753 | } |
754 | ; | |
755 | ||
756 | ||
757 | /* subroutine signature element: e.g. '$x = $default' or '%h' */ | |
758 | sigelem: sigscalarelem | |
53443c95 | 759 | { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; } |
d3d9da4a | 760 | | sigslurpelem |
53443c95 | 761 | { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; } |
d3d9da4a DM |
762 | ; |
763 | ||
764 | /* list of subroutine signature elements */ | |
765 | siglist: | |
53443c95 BZ |
766 | siglist[list] ',' |
767 | { $$ = $list; } | |
768 | | siglist[list] ',' sigelem[element] | |
30d9c59b | 769 | { |
53443c95 | 770 | $$ = op_append_list(OP_LINESEQ, $list, $element); |
30d9c59b | 771 | } |
53443c95 BZ |
772 | | sigelem[element] %prec PREC_LOW |
773 | { $$ = $element; } | |
30d9c59b Z |
774 | ; |
775 | ||
d3d9da4a DM |
776 | /* () or (....) */ |
777 | siglistornull: /* NULL */ | |
a9f5ab8d | 778 | { $$ = NULL; } |
d3d9da4a | 779 | | siglist |
53443c95 | 780 | { $$ = $siglist; } |
d3d9da4a | 781 | |
75230cc1 DM |
782 | /* optional subroutine signature */ |
783 | optsubsignature: /* NULL */ | |
784 | { $$ = NULL; } | |
785 | | subsignature | |
53443c95 | 786 | { $$ = $subsignature; } |
75230cc1 | 787 | |
d3d9da4a | 788 | /* Subroutine signature */ |
996b0cb8 | 789 | subsignature: '(' subsigguts ')' |
53443c95 | 790 | { $$ = $subsigguts; } |
996b0cb8 PLE |
791 | |
792 | subsigguts: | |
d3d9da4a DM |
793 | { |
794 | ENTER; | |
036bbc13 FC |
795 | SAVEIV(parser->sig_elems); |
796 | SAVEIV(parser->sig_optelems); | |
797 | SAVEI8(parser->sig_slurpy); | |
798 | parser->sig_elems = 0; | |
799 | parser->sig_optelems = 0; | |
800 | parser->sig_slurpy = 0; | |
49fb8620 | 801 | parser->in_my = KEY_sigvar; |
d3d9da4a DM |
802 | } |
803 | siglistornull | |
d3d9da4a | 804 | { |
53443c95 | 805 | OP *sigops = $siglistornull; |
f417cfa9 | 806 | struct op_argcheck_aux *aux; |
4fa06845 | 807 | OP *check; |
d3d9da4a | 808 | |
894f226e DM |
809 | if (!FEATURE_SIGNATURES_IS_ENABLED) |
810 | Perl_croak(aTHX_ "Experimental " | |
811 | "subroutine signatures not enabled"); | |
d3d9da4a DM |
812 | |
813 | /* We shouldn't get here otherwise */ | |
814 | Perl_ck_warner_d(aTHX_ | |
815 | packWARN(WARN_EXPERIMENTAL__SIGNATURES), | |
816 | "The signatures feature is experimental"); | |
817 | ||
f417cfa9 DM |
818 | aux = (struct op_argcheck_aux*) |
819 | PerlMemShared_malloc( | |
820 | sizeof(struct op_argcheck_aux)); | |
821 | aux->params = parser->sig_elems; | |
822 | aux->opt_params = parser->sig_optelems; | |
823 | aux->slurpy = parser->sig_slurpy; | |
824 | check = newUNOP_AUX(OP_ARGCHECK, 0, NULL, | |
825 | (UNOP_AUX_item *)aux); | |
4fa06845 DM |
826 | sigops = op_prepend_elem(OP_LINESEQ, check, sigops); |
827 | sigops = op_prepend_elem(OP_LINESEQ, | |
828 | newSTATEOP(0, NULL, NULL), | |
829 | sigops); | |
830 | /* a nextstate at the end handles context | |
831 | * correctly for an empty sub body */ | |
4df85778 | 832 | sigops = op_append_elem(OP_LINESEQ, |
4fa06845 DM |
833 | sigops, |
834 | newSTATEOP(0, NULL, NULL)); | |
4df85778 DM |
835 | /* wrap the list of arg ops in a NULL aux op. |
836 | This serves two purposes. First, it makes | |
837 | the arg list a separate subtree from the | |
838 | body of the sub, and secondly the null op | |
839 | may in future be upgraded to an OP_SIGNATURE | |
840 | when implemented. For now leave it as | |
841 | ex-argcheck */ | |
842 | $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL); | |
843 | op_null($$); | |
d3d9da4a | 844 | |
49fb8620 | 845 | parser->in_my = 0; |
a8c56356 DM |
846 | /* tell the toker that attrributes can follow |
847 | * this sig, but only so that the toker | |
848 | * can skip through any (illegal) trailing | |
849 | * attribute text then give a useful error | |
850 | * message about "attributes before sig", | |
851 | * rather than falling over ina mess at | |
852 | * unrecognised syntax. | |
853 | */ | |
854 | parser->expect = XATTRBLOCK; | |
855 | parser->sig_seen = TRUE; | |
d3d9da4a DM |
856 | LEAVE; |
857 | } | |
858 | ; | |
859 | ||
75230cc1 | 860 | /* Optional subroutine body (for named subroutine declaration) */ |
53443c95 | 861 | optsubbody: subbody { $$ = $subbody; } |
5adeeefb | 862 | | PERLY_SEMICOLON { $$ = NULL; } |
75230cc1 DM |
863 | ; |
864 | ||
865 | ||
866 | /* Subroutine body (without signature) */ | |
d0a6a9c7 | 867 | subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE |
75230cc1 | 868 | { |
c588171e BZ |
869 | if (parser->copline > (line_t)$PERLY_BRACE_OPEN) |
870 | parser->copline = (line_t)$PERLY_BRACE_OPEN; | |
53443c95 | 871 | $$ = block_end($remember, $stmtseq); |
75230cc1 DM |
872 | } |
873 | ; | |
874 | ||
875 | ||
876 | /* optional [ Subroutine body with optional signature ] (for named | |
877 | * subroutine declaration) */ | |
53443c95 | 878 | optsigsubbody: sigsubbody { $$ = $sigsubbody; } |
5adeeefb | 879 | | PERLY_SEMICOLON { $$ = NULL; } |
d3d9da4a | 880 | |
75230cc1 | 881 | /* Subroutine body with optional signature */ |
d0a6a9c7 | 882 | sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE |
894f226e | 883 | { |
c588171e BZ |
884 | if (parser->copline > (line_t)$PERLY_BRACE_OPEN) |
885 | parser->copline = (line_t)$PERLY_BRACE_OPEN; | |
53443c95 BZ |
886 | $$ = block_end($remember, |
887 | op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq)); | |
894f226e DM |
888 | } |
889 | ; | |
890 | ||
d3d9da4a | 891 | |
891be019 | 892 | /* Ordinary expressions; logical combinations */ |
53443c95 BZ |
893 | expr : expr[lhs] ANDOP expr[rhs] |
894 | { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); } | |
895 | | expr[lhs] OROP[operator] expr[rhs] | |
896 | { $$ = newLOGOP($operator, 0, $lhs, $rhs); } | |
897 | | expr[lhs] DOROP expr[rhs] | |
898 | { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); } | |
09b1cffe | 899 | | listexpr %prec PREC_LOW |
a0d0e21e LW |
900 | ; |
901 | ||
891be019 | 902 | /* Expressions are a list of terms joined by commas */ |
53443c95 BZ |
903 | listexpr: listexpr[list] ',' |
904 | { $$ = $list; } | |
905 | | listexpr[list] ',' term | |
abcf453d | 906 | { |
53443c95 BZ |
907 | OP* term = $term; |
908 | $$ = op_append_elem(OP_LIST, $list, term); | |
f05e27e5 | 909 | } |
fad39ff1 | 910 | | term %prec PREC_LOW |
8d063cd8 LW |
911 | ; |
912 | ||
891be019 | 913 | /* List operators */ |
09b1cffe | 914 | listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */ |
53443c95 BZ |
915 | { $$ = op_convert_list($LSTOP, OPf_STACKED, |
916 | op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) ); | |
f05e27e5 | 917 | } |
891be019 | 918 | | FUNC '(' indirob expr ')' /* print ($fh @args */ |
53443c95 BZ |
919 | { $$ = op_convert_list($FUNC, OPf_STACKED, |
920 | op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) ); | |
f05e27e5 | 921 | } |
417a992d | 922 | | term ARROW method '(' optexpr ')' /* $foo->bar(list) */ |
03d05f6e | 923 | { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED, |
2fcb4757 | 924 | op_append_elem(OP_LIST, |
53443c95 BZ |
925 | op_prepend_elem(OP_LIST, scalar($term), $optexpr), |
926 | newMETHOP(OP_METHOD, 0, $method))); | |
f05e27e5 | 927 | } |
891be019 | 928 | | term ARROW method /* $foo->bar */ |
03d05f6e | 929 | { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED, |
53443c95 BZ |
930 | op_append_elem(OP_LIST, scalar($term), |
931 | newMETHOP(OP_METHOD, 0, $method))); | |
f05e27e5 | 932 | } |
09b1cffe | 933 | | METHOD indirob optlistexpr /* new Class @args */ |
03d05f6e | 934 | { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED, |
2fcb4757 | 935 | op_append_elem(OP_LIST, |
53443c95 BZ |
936 | op_prepend_elem(OP_LIST, $indirob, $optlistexpr), |
937 | newMETHOP(OP_METHOD, 0, $METHOD))); | |
f05e27e5 | 938 | } |
09b1cffe | 939 | | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */ |
03d05f6e | 940 | { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED, |
2fcb4757 | 941 | op_append_elem(OP_LIST, |
53443c95 BZ |
942 | op_prepend_elem(OP_LIST, $indirob, $optexpr), |
943 | newMETHOP(OP_METHOD, 0, $FUNCMETH))); | |
f05e27e5 | 944 | } |
09b1cffe | 945 | | LSTOP optlistexpr /* print @args */ |
53443c95 | 946 | { $$ = op_convert_list($LSTOP, 0, $optlistexpr); } |
09b1cffe | 947 | | FUNC '(' optexpr ')' /* print (@args) */ |
53443c95 | 948 | { $$ = op_convert_list($FUNC, 0, $optexpr); } |
69afcc21 | 949 | | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */ |
53443c95 | 950 | { $$ = op_convert_list($FUNC, 0, $optexpr); } |
718a7425 | 951 | | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */ |
5a5094bd | 952 | { SvREFCNT_inc_simple_void(PL_compcv); |
53443c95 | 953 | $<opval>$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub] |
09b1cffe | 954 | optlistexpr %prec LSTOP /* ... @bar */ |
4633a7c4 | 955 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
2fcb4757 | 956 | op_append_elem(OP_LIST, |
53443c95 | 957 | op_prepend_elem(OP_LIST, $<opval>anonattrsub, $optlistexpr), $LSTOPSUB)); |
f05e27e5 | 958 | } |
a687059c LW |
959 | ; |
960 | ||
891be019 | 961 | /* Names of methods. May use $object->$methodname */ |
a0d0e21e LW |
962 | method : METHOD |
963 | | scalar | |
964 | ; | |
965 | ||
891be019 | 966 | /* Some kind of subscripted expression */ |
5adeeefb BZ |
967 | subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* *main::{something} */ |
968 | /* In this and all the hash accessors, PERLY_SEMICOLON is | |
891be019 | 969 | * provided by the tokeniser */ |
53443c95 | 970 | { $$ = newBINOP(OP_GELEM, 0, $gelem, scalar($expr)); } |
fceeeb77 | 971 | | scalar[array] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $array[$element] */ |
53443c95 | 972 | { $$ = newBINOP(OP_AELEM, 0, oopsAV($array), scalar($expr)); |
f05e27e5 | 973 | } |
fceeeb77 | 974 | | term[array_reference] ARROW PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* somearef->[$element] */ |
fad39ff1 | 975 | { $$ = newBINOP(OP_AELEM, 0, |
53443c95 BZ |
976 | ref(newAVREF($array_reference),OP_RV2AV), |
977 | scalar($expr)); | |
f05e27e5 | 978 | } |
fceeeb77 | 979 | | subscripted[array_reference] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $foo->[$bar]->[$baz] */ |
fad39ff1 | 980 | { $$ = newBINOP(OP_AELEM, 0, |
53443c95 BZ |
981 | ref(newAVREF($array_reference),OP_RV2AV), |
982 | scalar($expr)); | |
f05e27e5 | 983 | } |
5adeeefb | 984 | | scalar[hash] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo{bar();} */ |
53443c95 | 985 | { $$ = newBINOP(OP_HELEM, 0, oopsHV($hash), jmaybe($expr)); |
f05e27e5 | 986 | } |
5adeeefb | 987 | | term[hash_reference] ARROW PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* somehref->{bar();} */ |
fad39ff1 | 988 | { $$ = newBINOP(OP_HELEM, 0, |
53443c95 BZ |
989 | ref(newHVREF($hash_reference),OP_RV2HV), |
990 | jmaybe($expr)); } | |
5adeeefb | 991 | | subscripted[hash_reference] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo->[bar]->{baz;} */ |
fad39ff1 | 992 | { $$ = newBINOP(OP_HELEM, 0, |
53443c95 BZ |
993 | ref(newHVREF($hash_reference),OP_RV2HV), |
994 | jmaybe($expr)); } | |
995 | | term[code_reference] ARROW '(' ')' /* $subref->() */ | |
fad39ff1 | 996 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
53443c95 | 997 | newCVREF(0, scalar($code_reference))); |
097ff42c Z |
998 | if (parser->expect == XBLOCK) |
999 | parser->expect = XOPERATOR; | |
1000 | } | |
53443c95 | 1001 | | term[code_reference] ARROW '(' expr ')' /* $subref->(@args) */ |
fad39ff1 | 1002 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
53443c95 BZ |
1003 | op_append_elem(OP_LIST, $expr, |
1004 | newCVREF(0, scalar($code_reference)))); | |
097ff42c Z |
1005 | if (parser->expect == XBLOCK) |
1006 | parser->expect = XOPERATOR; | |
1007 | } | |
fad39ff1 | 1008 | |
53443c95 | 1009 | | subscripted[code_reference] '(' expr ')' /* $foo->{bar}->(@args) */ |
fad39ff1 | 1010 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
53443c95 BZ |
1011 | op_append_elem(OP_LIST, $expr, |
1012 | newCVREF(0, scalar($code_reference)))); | |
097ff42c Z |
1013 | if (parser->expect == XBLOCK) |
1014 | parser->expect = XOPERATOR; | |
1015 | } | |
53443c95 | 1016 | | subscripted[code_reference] '(' ')' /* $foo->{bar}->() */ |
fad39ff1 | 1017 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
53443c95 | 1018 | newCVREF(0, scalar($code_reference))); |
097ff42c Z |
1019 | if (parser->expect == XBLOCK) |
1020 | parser->expect = XOPERATOR; | |
1021 | } | |
fceeeb77 | 1022 | | '(' expr[list] ')' PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE /* list slice */ |
53443c95 | 1023 | { $$ = newSLICEOP(0, $slice, $list); } |
fceeeb77 | 1024 | | QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* list literal slice */ |
53443c95 | 1025 | { $$ = newSLICEOP(0, $expr, $QWLIST); } |
fceeeb77 | 1026 | | '(' ')' PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* empty list slice! */ |
53443c95 | 1027 | { $$ = newSLICEOP(0, $expr, NULL); } |
891be019 | 1028 | ; |
fad39ff1 | 1029 | |
891be019 | 1030 | /* Binary operators between terms */ |
53443c95 BZ |
1031 | termbinop: term[lhs] ASSIGNOP term[rhs] /* $x = $y, $x += $y */ |
1032 | { $$ = newASSIGNOP(OPf_STACKED, $lhs, $ASSIGNOP, $rhs); } | |
1033 | | term[lhs] POWOP term[rhs] /* $x ** $y */ | |
1034 | { $$ = newBINOP($POWOP, 0, scalar($lhs), scalar($rhs)); } | |
1035 | | term[lhs] MULOP term[rhs] /* $x * $y, $x x $y */ | |
1036 | { if ($MULOP != OP_REPEAT) | |
1037 | scalar($lhs); | |
1038 | $$ = newBINOP($MULOP, 0, $lhs, scalar($rhs)); | |
1039 | } | |
1040 | | term[lhs] ADDOP term[rhs] /* $x + $y */ | |
1041 | { $$ = newBINOP($ADDOP, 0, scalar($lhs), scalar($rhs)); } | |
1042 | | term[lhs] SHIFTOP term[rhs] /* $x >> $y, $x << $y */ | |
1043 | { $$ = newBINOP($SHIFTOP, 0, scalar($lhs), scalar($rhs)); } | |
02b85d3d | 1044 | | termrelop %prec PREC_LOW /* $x > $y, etc. */ |
53443c95 | 1045 | { $$ = $termrelop; } |
02b85d3d | 1046 | | termeqop %prec PREC_LOW /* $x == $y, $x cmp $y */ |
53443c95 BZ |
1047 | { $$ = $termeqop; } |
1048 | | term[lhs] BITANDOP term[rhs] /* $x & $y */ | |
1049 | { $$ = newBINOP($BITANDOP, 0, scalar($lhs), scalar($rhs)); } | |
1050 | | term[lhs] BITOROP term[rhs] /* $x | $y */ | |
1051 | { $$ = newBINOP($BITOROP, 0, scalar($lhs), scalar($rhs)); } | |
1052 | | term[lhs] DOTDOT term[rhs] /* $x..$y, $x...$y */ | |
1053 | { $$ = newRANGE($DOTDOT, scalar($lhs), scalar($rhs)); } | |
1054 | | term[lhs] ANDAND term[rhs] /* $x && $y */ | |
1055 | { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); } | |
1056 | | term[lhs] OROR term[rhs] /* $x || $y */ | |
1057 | { $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); } | |
1058 | | term[lhs] DORDOR term[rhs] /* $x // $y */ | |
1059 | { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); } | |
1060 | | term[lhs] MATCHOP term[rhs] /* $x =~ /$y/ */ | |
1061 | { $$ = bind_match($MATCHOP, $lhs, $rhs); } | |
891be019 | 1062 | ; |
8d063cd8 | 1063 | |
02b85d3d | 1064 | termrelop: relopchain %prec PREC_LOW |
53443c95 BZ |
1065 | { $$ = cmpchain_finish($relopchain); } |
1066 | | term[lhs] NCRELOP term[rhs] | |
1067 | { $$ = newBINOP($NCRELOP, 0, scalar($lhs), scalar($rhs)); } | |
02b85d3d Z |
1068 | | termrelop NCRELOP |
1069 | { yyerror("syntax error"); YYERROR; } | |
1070 | | termrelop CHRELOP | |
1071 | { yyerror("syntax error"); YYERROR; } | |
1072 | ; | |
1073 | ||
53443c95 BZ |
1074 | relopchain: term[lhs] CHRELOP term[rhs] |
1075 | { $$ = cmpchain_start($CHRELOP, $lhs, $rhs); } | |
1076 | | relopchain[lhs] CHRELOP term[rhs] | |
1077 | { $$ = cmpchain_extend($CHRELOP, $lhs, $rhs); } | |
02b85d3d Z |
1078 | ; |
1079 | ||
1080 | termeqop: eqopchain %prec PREC_LOW | |
53443c95 BZ |
1081 | { $$ = cmpchain_finish($eqopchain); } |
1082 | | term[lhs] NCEQOP term[rhs] | |
1083 | { $$ = newBINOP($NCEQOP, 0, scalar($lhs), scalar($rhs)); } | |
02b85d3d Z |
1084 | | termeqop NCEQOP |
1085 | { yyerror("syntax error"); YYERROR; } | |
1086 | | termeqop CHEQOP | |
1087 | { yyerror("syntax error"); YYERROR; } | |
1088 | ; | |
1089 | ||
53443c95 BZ |
1090 | eqopchain: term[lhs] CHEQOP term[rhs] |
1091 | { $$ = cmpchain_start($CHEQOP, $lhs, $rhs); } | |
1092 | | eqopchain[lhs] CHEQOP term[rhs] | |
1093 | { $$ = cmpchain_extend($CHEQOP, $lhs, $rhs); } | |
02b85d3d Z |
1094 | ; |
1095 | ||
891be019 SC |
1096 | /* Unary operators and terms */ |
1097 | termunop : '-' term %prec UMINUS /* -$x */ | |
53443c95 | 1098 | { $$ = newUNOP(OP_NEGATE, 0, scalar($term)); } |
891be019 | 1099 | | '+' term %prec UMINUS /* +$x */ |
53443c95 | 1100 | { $$ = $term; } |
b5bbe64a | 1101 | |
891be019 | 1102 | | '!' term /* !$x */ |
53443c95 | 1103 | { $$ = newUNOP(OP_NOT, 0, scalar($term)); } |
891be019 | 1104 | | '~' term /* ~$x */ |
53443c95 | 1105 | { $$ = newUNOP($1, 0, scalar($term)); } |
891be019 | 1106 | | term POSTINC /* $x++ */ |
79072805 | 1107 | { $$ = newUNOP(OP_POSTINC, 0, |
53443c95 | 1108 | op_lvalue(scalar($term), OP_POSTINC)); } |
891be019 | 1109 | | term POSTDEC /* $x-- */ |
79072805 | 1110 | { $$ = newUNOP(OP_POSTDEC, 0, |
53443c95 | 1111 | op_lvalue(scalar($term), OP_POSTDEC));} |
cc624add | 1112 | | term POSTJOIN /* implicit join after interpolated ->@ */ |
03d05f6e | 1113 | { $$ = op_convert_list(OP_JOIN, 0, |
cc624add FC |
1114 | op_append_elem( |
1115 | OP_LIST, | |
1116 | newSVREF(scalar( | |
1117 | newSVOP(OP_CONST,0, | |
1118 | newSVpvs("\"")) | |
1119 | )), | |
53443c95 | 1120 | $term |
cc624add | 1121 | )); |
cc624add | 1122 | } |
891be019 | 1123 | | PREINC term /* ++$x */ |
79072805 | 1124 | { $$ = newUNOP(OP_PREINC, 0, |
53443c95 | 1125 | op_lvalue(scalar($term), OP_PREINC)); } |
891be019 | 1126 | | PREDEC term /* --$x */ |
79072805 | 1127 | { $$ = newUNOP(OP_PREDEC, 0, |
53443c95 | 1128 | op_lvalue(scalar($term), OP_PREDEC)); } |
891be019 SC |
1129 | |
1130 | ; | |
1131 | ||
1132 | /* Constructors for anonymous data */ | |
fceeeb77 | 1133 | anonymous: PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE |
53443c95 | 1134 | { $$ = newANONLIST($expr); } |
fceeeb77 | 1135 | | PERLY_BRACKET_OPEN PERLY_BRACKET_CLOSE |
a9f5ab8d | 1136 | { $$ = newANONLIST(NULL);} |
5adeeefb | 1137 | | HASHBRACK expr PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec '(' /* { foo => "Bar" } */ |
53443c95 | 1138 | { $$ = newANONHASH($expr); } |
5adeeefb | 1139 | | HASHBRACK PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec '(' /* { } (PERLY_SEMICOLON by tokener) */ |
a9f5ab8d | 1140 | { $$ = newANONHASH(NULL); } |
75230cc1 | 1141 | | ANONSUB startanonsub proto subattrlist subbody %prec '(' |
436ddf68 | 1142 | { SvREFCNT_inc_simple_void(PL_compcv); |
53443c95 | 1143 | $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); } |
75230cc1 | 1144 | | ANON_SIGSUB startanonsub subattrlist sigsubbody %prec '(' |
5a5094bd | 1145 | { SvREFCNT_inc_simple_void(PL_compcv); |
53443c95 | 1146 | $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); } |
891be019 SC |
1147 | ; |
1148 | ||
1149 | /* Things called with "do" */ | |
1150 | termdo : DO term %prec UNIOP /* do $filename */ | |
53443c95 | 1151 | { $$ = dofile($term, $DO);} |
891be019 | 1152 | | DO block %prec '(' /* do { code */ |
53443c95 | 1153 | { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));} |
891be019 SC |
1154 | ; |
1155 | ||
53443c95 | 1156 | term[product] : termbinop |
891be019 SC |
1157 | | termunop |
1158 | | anonymous | |
1159 | | termdo | |
53443c95 BZ |
1160 | | term[condition] '?' term[then] ':' term[else] |
1161 | { $$ = newCONDOP(0, $condition, $then, $else); } | |
1162 | | REFGEN term[operand] /* \$x, \@y, \%z */ | |
1163 | { $$ = newUNOP(OP_REFGEN, 0, $operand); } | |
1164 | | MY REFGEN term[operand] | |
1165 | { $$ = newUNOP(OP_REFGEN, 0, localize($operand,1)); } | |
09bef843 | 1166 | | myattrterm %prec UNIOP |
53443c95 BZ |
1167 | { $$ = $myattrterm; } |
1168 | | LOCAL term[operand] %prec UNIOP | |
1169 | { $$ = localize($operand,0); } | |
a0d0e21e | 1170 | | '(' expr ')' |
53443c95 | 1171 | { $$ = sawparens($expr); } |
ea25a9b2 | 1172 | | QWLIST |
53443c95 | 1173 | { $$ = $QWLIST; } |
8d063cd8 | 1174 | | '(' ')' |
b5bbe64a | 1175 | { $$ = sawparens(newNULLLIST()); } |
79072805 | 1176 | | scalar %prec '(' |
53443c95 | 1177 | { $$ = $scalar; } |
79072805 | 1178 | | star %prec '(' |
53443c95 | 1179 | { $$ = $star; } |
79072805 | 1180 | | hsh %prec '(' |
53443c95 | 1181 | { $$ = $hsh; } |
79072805 | 1182 | | ary %prec '(' |
53443c95 | 1183 | { $$ = $ary; } |
891be019 | 1184 | | arylen %prec '(' /* $#x, $#{ something } */ |
53443c95 | 1185 | { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));} |
fad39ff1 | 1186 | | subscripted |
53443c95 | 1187 | { $$ = $subscripted; } |
fceeeb77 | 1188 | | sliceme PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array slice */ |
2fcb4757 | 1189 | { $$ = op_prepend_elem(OP_ASLICE, |
79072805 | 1190 | newOP(OP_PUSHMARK, 0), |
79072805 | 1191 | newLISTOP(OP_ASLICE, 0, |
53443c95 BZ |
1192 | list($expr), |
1193 | ref($sliceme, OP_ASLICE))); | |
1194 | if ($$ && $sliceme) | |
429a2555 | 1195 | $$->op_private |= |
53443c95 | 1196 | $sliceme->op_private & OPpSLICEWARNING; |
f05e27e5 | 1197 | } |
fceeeb77 | 1198 | | kvslice PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array key/value slice */ |
6dd3e0f2 RZ |
1199 | { $$ = op_prepend_elem(OP_KVASLICE, |
1200 | newOP(OP_PUSHMARK, 0), | |
1201 | newLISTOP(OP_KVASLICE, 0, | |
53443c95 BZ |
1202 | list($expr), |
1203 | ref(oopsAV($kvslice), OP_KVASLICE))); | |
1204 | if ($$ && $kvslice) | |
95a31aad | 1205 | $$->op_private |= |
53443c95 | 1206 | $kvslice->op_private & OPpSLICEWARNING; |
6dd3e0f2 | 1207 | } |
5adeeefb | 1208 | | sliceme PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* @hash{@keys} */ |
2fcb4757 | 1209 | { $$ = op_prepend_elem(OP_HSLICE, |
79072805 | 1210 | newOP(OP_PUSHMARK, 0), |
79072805 | 1211 | newLISTOP(OP_HSLICE, 0, |
53443c95 BZ |
1212 | list($expr), |
1213 | ref(oopsHV($sliceme), OP_HSLICE))); | |
1214 | if ($$ && $sliceme) | |
429a2555 | 1215 | $$->op_private |= |
53443c95 | 1216 | $sliceme->op_private & OPpSLICEWARNING; |
f05e27e5 | 1217 | } |
5adeeefb | 1218 | | kvslice PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* %hash{@keys} */ |
5cae3edb RZ |
1219 | { $$ = op_prepend_elem(OP_KVHSLICE, |
1220 | newOP(OP_PUSHMARK, 0), | |
1221 | newLISTOP(OP_KVHSLICE, 0, | |
53443c95 BZ |
1222 | list($expr), |
1223 | ref($kvslice, OP_KVHSLICE))); | |
1224 | if ($$ && $kvslice) | |
95a31aad | 1225 | $$->op_private |= |
53443c95 | 1226 | $kvslice->op_private & OPpSLICEWARNING; |
5cae3edb | 1227 | } |
79072805 | 1228 | | THING %prec '(' |
53443c95 | 1229 | { $$ = $THING; } |
891be019 | 1230 | | amper /* &foo; */ |
53443c95 | 1231 | { $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); } |
fb602e32 | 1232 | | amper '(' ')' /* &foo() or foo() */ |
53443c95 | 1233 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper)); |
f05e27e5 | 1234 | } |
fb602e32 | 1235 | | amper '(' expr ')' /* &foo(@args) or foo(@args) */ |
f05e27e5 DM |
1236 | { |
1237 | $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, | |
53443c95 | 1238 | op_append_elem(OP_LIST, $expr, scalar($amper))); |
f05e27e5 | 1239 | } |
fb602e32 | 1240 | | NOAMP subname optlistexpr /* foo @args (no parens) */ |
a0d0e21e | 1241 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
53443c95 BZ |
1242 | op_append_elem(OP_LIST, $optlistexpr, scalar($subname))); |
1243 | } | |
1244 | | term[operand] ARROW '$' '*' | |
1245 | { $$ = newSVREF($operand); } | |
1246 | | term[operand] ARROW '@' '*' | |
1247 | { $$ = newAVREF($operand); } | |
1248 | | term[operand] ARROW '%' '*' | |
1249 | { $$ = newHVREF($operand); } | |
25a50500 | 1250 | | term[operand] ARROW PERLY_AMPERSAND '*' |
89f35911 | 1251 | { $$ = newUNOP(OP_ENTERSUB, 0, |
25a50500 | 1252 | scalar(newCVREF($PERLY_AMPERSAND,$operand))); } |
53443c95 BZ |
1253 | | term[operand] ARROW '*' '*' %prec '(' |
1254 | { $$ = newGVREF(0,$operand); } | |
891be019 | 1255 | | LOOPEX /* loop exiting command (goto, last, dump, etc) */ |
53443c95 | 1256 | { $$ = newOP($LOOPEX, OPf_SPECIAL); |
b5bbe64a | 1257 | PL_hints |= HINT_BLOCK_SCOPE; } |
53443c95 BZ |
1258 | | LOOPEX term[operand] |
1259 | { $$ = newLOOPEX($LOOPEX,$operand); } | |
09b1cffe | 1260 | | NOTOP listexpr /* not $foo */ |
53443c95 | 1261 | { $$ = newUNOP(OP_NOT, 0, scalar($listexpr)); } |
891be019 | 1262 | | UNIOP /* Unary op, $_ implied */ |
53443c95 | 1263 | { $$ = newOP($UNIOP, 0); } |
f05e27e5 | 1264 | | UNIOP block /* eval { foo }* */ |
53443c95 BZ |
1265 | { $$ = newUNOP($UNIOP, 0, $block); } |
1266 | | UNIOP term[operand] /* Unary op */ | |
1267 | { $$ = newUNOP($UNIOP, 0, $operand); } | |
d2fdf8fd | 1268 | | REQUIRE /* require, $_ implied */ |
53443c95 BZ |
1269 | { $$ = newOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0); } |
1270 | | REQUIRE term[operand] /* require Foo */ | |
1271 | { $$ = newUNOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0, $operand); } | |
3cd0a11a | 1272 | | UNIOPSUB |
53443c95 BZ |
1273 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($UNIOPSUB)); } |
1274 | | UNIOPSUB term[operand] /* Sub treated as unop */ | |
4633a7c4 | 1275 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
53443c95 | 1276 | op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); } |
891be019 | 1277 | | FUNC0 /* Nullary operator */ |
53443c95 | 1278 | { $$ = newOP($FUNC0, 0); } |
ae986130 | 1279 | | FUNC0 '(' ')' |
53443c95 | 1280 | { $$ = newOP($FUNC0, 0);} |
7eb971ee | 1281 | | FUNC0OP /* Same as above, but op created in toke.c */ |
53443c95 | 1282 | { $$ = $FUNC0OP; } |
7eb971ee | 1283 | | FUNC0OP '(' ')' |
53443c95 | 1284 | { $$ = $FUNC0OP; } |
891be019 | 1285 | | FUNC0SUB /* Sub treated as nullop */ |
53443c95 | 1286 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); } |
891be019 | 1287 | | FUNC1 '(' ')' /* not () */ |
53443c95 BZ |
1288 | { $$ = ($FUNC1 == OP_NOT) |
1289 | ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0))) | |
1290 | : newOP($FUNC1, OPf_SPECIAL); } | |
891be019 | 1291 | | FUNC1 '(' expr ')' /* not($foo) */ |
53443c95 | 1292 | { $$ = newUNOP($FUNC1, 0, $expr); } |
d63c20f2 DM |
1293 | | PMFUNC /* m//, s///, qr//, tr/// */ |
1294 | { | |
53443c95 BZ |
1295 | if ( $PMFUNC->op_type != OP_TRANS |
1296 | && $PMFUNC->op_type != OP_TRANSR | |
1297 | && (((PMOP*)$PMFUNC)->op_pmflags & PMf_HAS_CV)) | |
d63c20f2 DM |
1298 | { |
1299 | $<ival>$ = start_subparse(FALSE, CVf_ANON); | |
1300 | SAVEFREESV(PL_compcv); | |
1301 | } else | |
1302 | $<ival>$ = 0; | |
1303 | } | |
69afcc21 | 1304 | SUBLEXSTART listexpr optrepl SUBLEXEND |
53443c95 | 1305 | { $$ = pmruntime($PMFUNC, $listexpr, $optrepl, 1, $<ival>2); } |
185c2e96 | 1306 | | BAREWORD |
378cc40b | 1307 | | listop |
88e1f1a2 | 1308 | | PLUGEXPR |
8d063cd8 LW |
1309 | ; |
1310 | ||
891be019 | 1311 | /* "my" declarations, with optional attributes */ |
09bef843 | 1312 | myattrterm: MY myterm myattrlist |
53443c95 | 1313 | { $$ = my_attrs($myterm,$myattrlist); } |
09bef843 | 1314 | | MY myterm |
53443c95 | 1315 | { $$ = localize($myterm,1); } |
e118fea3 | 1316 | | MY REFGEN myterm myattrlist |
53443c95 | 1317 | { $$ = newUNOP(OP_REFGEN, 0, my_attrs($myterm,$myattrlist)); } |
09bef843 SB |
1318 | ; |
1319 | ||
891be019 | 1320 | /* Things that can be "my"'d */ |
09bef843 | 1321 | myterm : '(' expr ')' |
53443c95 | 1322 | { $$ = sawparens($expr); } |
09bef843 | 1323 | | '(' ')' |
b5bbe64a JH |
1324 | { $$ = sawparens(newNULLLIST()); } |
1325 | ||
09bef843 | 1326 | | scalar %prec '(' |
53443c95 | 1327 | { $$ = $scalar; } |
09bef843 | 1328 | | hsh %prec '(' |
53443c95 | 1329 | { $$ = $hsh; } |
09bef843 | 1330 | | ary %prec '(' |
53443c95 | 1331 | { $$ = $ary; } |
09bef843 SB |
1332 | ; |
1333 | ||
891be019 | 1334 | /* Basic list expressions */ |
09b1cffe | 1335 | optlistexpr: /* NULL */ %prec PREC_LOW |
a9f5ab8d | 1336 | { $$ = NULL; } |
09b1cffe | 1337 | | listexpr %prec PREC_LOW |
53443c95 | 1338 | { $$ = $listexpr; } |
a0d0e21e LW |
1339 | ; |
1340 | ||
09b1cffe | 1341 | optexpr: /* NULL */ |
a9f5ab8d | 1342 | { $$ = NULL; } |
79072805 | 1343 | | expr |
53443c95 | 1344 | { $$ = $expr; } |
79072805 LW |
1345 | ; |
1346 | ||
9b6b7be8 | 1347 | optrepl: /* NULL */ |
a9f5ab8d | 1348 | { $$ = NULL; } |
9b6b7be8 | 1349 | | '/' expr |
53443c95 | 1350 | { $$ = $expr; } |
9b6b7be8 FC |
1351 | ; |
1352 | ||
891be019 SC |
1353 | /* A little bit of trickery to make "for my $foo (@bar)" actually be |
1354 | lexical */ | |
55497cff | 1355 | my_scalar: scalar |
53443c95 | 1356 | { parser->in_my = 0; $$ = my($scalar); } |
55497cff PP |
1357 | ; |
1358 | ||
d39c26a6 FC |
1359 | my_var : scalar |
1360 | | ary | |
1361 | | hsh | |
1362 | ; | |
1363 | ||
1364 | refgen_topic: my_var | |
1365 | | amper | |
1366 | ; | |
1367 | ||
e118fea3 FC |
1368 | my_refgen: MY REFGEN |
1369 | | REFGEN MY | |
1370 | ; | |
1371 | ||
25a50500 BZ |
1372 | amper : PERLY_AMPERSAND indirob |
1373 | { $$ = newCVREF($PERLY_AMPERSAND,$indirob); } | |
a687059c LW |
1374 | ; |
1375 | ||
79072805 | 1376 | scalar : '$' indirob |
53443c95 | 1377 | { $$ = newSVREF($indirob); } |
a687059c LW |
1378 | ; |
1379 | ||
79072805 | 1380 | ary : '@' indirob |
53443c95 | 1381 | { $$ = newAVREF($indirob); |
b5bbe64a | 1382 | if ($$) $$->op_private |= $1; |
f05e27e5 | 1383 | } |
79072805 LW |
1384 | ; |
1385 | ||
1386 | hsh : '%' indirob | |
53443c95 | 1387 | { $$ = newHVREF($indirob); |
b5bbe64a | 1388 | if ($$) $$->op_private |= $1; |
f05e27e5 | 1389 | } |
79072805 LW |
1390 | ; |
1391 | ||
1392 | arylen : DOLSHARP indirob | |
53443c95 | 1393 | { $$ = newAVREF($indirob); } |
ff25e5db | 1394 | | term ARROW DOLSHARP '*' |
53443c95 | 1395 | { $$ = newAVREF($term); } |
79072805 LW |
1396 | ; |
1397 | ||
1398 | star : '*' indirob | |
53443c95 | 1399 | { $$ = newGVREF(0,$indirob); } |
79072805 LW |
1400 | ; |
1401 | ||
89f35911 FC |
1402 | sliceme : ary |
1403 | | term ARROW '@' | |
53443c95 | 1404 | { $$ = newAVREF($term); } |
89f35911 FC |
1405 | ; |
1406 | ||
76eba8ab FC |
1407 | kvslice : hsh |
1408 | | term ARROW '%' | |
53443c95 | 1409 | { $$ = newHVREF($term); } |
76eba8ab FC |
1410 | ; |
1411 | ||
89f35911 FC |
1412 | gelem : star |
1413 | | term ARROW '*' | |
53443c95 | 1414 | { $$ = newGVREF(0,$term); } |
89f35911 FC |
1415 | ; |
1416 | ||
891be019 | 1417 | /* Indirect objects */ |
185c2e96 | 1418 | indirob : BAREWORD |
53443c95 | 1419 | { $$ = scalar($BAREWORD); } |
fad39ff1 | 1420 | | scalar %prec PREC_LOW |
53443c95 | 1421 | { $$ = scalar($scalar); } |
79072805 | 1422 | | block |
53443c95 | 1423 | { $$ = op_scope($block); } |
79072805 | 1424 | |
93a17b20 | 1425 | | PRIVATEREF |
53443c95 | 1426 | { $$ = $PRIVATEREF; } |
8d063cd8 | 1427 | ; |