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