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