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