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