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 |
b5bbe64a JH |
72 | %token <ival> LOOPEX DOTDOT YADAYADA |
73 | %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP | |
02b85d3d | 74 | %token <ival> MULOP ADDOP |
b5bbe64a JH |
75 | %token <ival> DOLSHARP DO HASHBRACK NOAMP |
76 | %token <ival> LOCAL MY REQUIRE | |
77 | %token <ival> COLONATTR FORMLBRACK FORMRBRACK | |
69afcc21 | 78 | %token <ival> SUBLEXSTART SUBLEXEND |
f05e27e5 | 79 | |
727a8fe5 | 80 | %type <ival> grammar remember mremember |
f05e27e5 | 81 | %type <ival> startsub startanonsub startformsub |
b5bbe64a | 82 | |
b5a64814 | 83 | %type <ival> mintro |
f05e27e5 | 84 | |
8e720305 | 85 | %type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else |
fad39ff1 | 86 | %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff |
53443c95 | 87 | %type <opval> condition |
76eba8ab | 88 | %type <opval> sliceme kvslice gelem |
08b3e84f | 89 | %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr |
9b6b7be8 | 90 | %type <opval> optlistexpr optexpr optrepl indirob listop method |
75230cc1 | 91 | %type <opval> formname subname proto cont my_scalar my_var |
d39c26a6 | 92 | %type <opval> refgen_topic formblock |
f05e27e5 | 93 | %type <opval> subattrlist myattrlist myattrterm myterm |
75230cc1 | 94 | %type <opval> termbinop termunop anonymous termdo |
02b85d3d | 95 | %type <opval> termrelop relopchain termeqop eqopchain |
d3d9da4a DM |
96 | %type <ival> sigslurpsigil |
97 | %type <opval> sigvarname sigdefault sigscalarelem sigslurpelem | |
996b0cb8 | 98 | %type <opval> sigelem siglist siglistornull subsigguts subsignature optsubsignature |
75230cc1 | 99 | %type <opval> subbody optsubbody sigsubbody optsigsubbody |
705fe0e5 | 100 | %type <opval> formstmtseq formline formarg |
79072805 | 101 | |
b5bbe64a | 102 | %nonassoc <ival> PREC_LOW |
fad39ff1 SM |
103 | %nonassoc LOOPEX |
104 | ||
6e9e8105 | 105 | %left <ival> OROP |
b5bbe64a JH |
106 | %left <ival> ANDOP |
107 | %right <ival> NOTOP | |
36477c24 | 108 | %nonassoc LSTOP LSTOPSUB |
581f9a7a | 109 | %left PERLY_COMMA |
b5bbe64a | 110 | %right <ival> ASSIGNOP |
a1ad62bf | 111 | %right <ival> PERLY_QUESTION_MARK PERLY_COLON |
29d69c3c | 112 | %nonassoc DOTDOT |
b5bbe64a JH |
113 | %left <ival> OROR DORDOR |
114 | %left <ival> ANDAND | |
115 | %left <ival> BITOROP | |
116 | %left <ival> BITANDOP | |
02b85d3d Z |
117 | %left <ival> CHEQOP NCEQOP |
118 | %left <ival> CHRELOP NCRELOP | |
36477c24 | 119 | %nonassoc UNIOP UNIOPSUB |
20515881 | 120 | %nonassoc REQUIRE |
b5bbe64a | 121 | %left <ival> SHIFTOP |
a687059c LW |
122 | %left ADDOP |
123 | %left MULOP | |
b5bbe64a | 124 | %left <ival> MATCHOP |
3d92c6b8 | 125 | %right <ival> PERLY_EXCLAMATION_MARK PERLY_TILDE UMINUS REFGEN |
b5bbe64a JH |
126 | %right <ival> POWOP |
127 | %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN | |
128 | %left <ival> ARROW | |
04884b68 | 129 | %nonassoc <ival> PERLY_PAREN_CLOSE |
ee67f254 | 130 | %left <ival> PERLY_PAREN_OPEN |
669dd22c | 131 | %left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN |
8d063cd8 LW |
132 | |
133 | %% /* RULES */ | |
134 | ||
28ac2b49 | 135 | /* Top-level choice of what kind of thing yyparse was called to parse */ |
727a8fe5 Z |
136 | grammar : GRAMPROG |
137 | { | |
624fa8bd | 138 | parser->expect = XSTATE; |
5a2060e2 | 139 | $<ival>$ = 0; |
727a8fe5 Z |
140 | } |
141 | remember stmtseq | |
142 | { | |
53443c95 | 143 | newPROG(block_end($remember,$stmtseq)); |
8635e3c2 | 144 | PL_compiling.cop_seq = 0; |
727a8fe5 Z |
145 | $$ = 0; |
146 | } | |
78cdf107 Z |
147 | | GRAMEXPR |
148 | { | |
149 | parser->expect = XTERM; | |
5a2060e2 | 150 | $<ival>$ = 0; |
78cdf107 | 151 | } |
09b1cffe | 152 | optexpr |
78cdf107 | 153 | { |
53443c95 | 154 | PL_eval_root = $optexpr; |
78cdf107 Z |
155 | $$ = 0; |
156 | } | |
e53d8f76 Z |
157 | | GRAMBLOCK |
158 | { | |
159 | parser->expect = XBLOCK; | |
5a2060e2 | 160 | $<ival>$ = 0; |
e53d8f76 Z |
161 | } |
162 | block | |
163 | { | |
5f211341 | 164 | PL_pad_reset_pending = TRUE; |
53443c95 | 165 | PL_eval_root = $block; |
8359b381 Z |
166 | $$ = 0; |
167 | yyunlex(); | |
0f8490d1 | 168 | parser->yychar = yytoken = YYEOF; |
8359b381 Z |
169 | } |
170 | | GRAMBARESTMT | |
171 | { | |
172 | parser->expect = XSTATE; | |
5a2060e2 | 173 | $<ival>$ = 0; |
8359b381 Z |
174 | } |
175 | barestmt | |
176 | { | |
177 | PL_pad_reset_pending = TRUE; | |
53443c95 | 178 | PL_eval_root = $barestmt; |
e53d8f76 Z |
179 | $$ = 0; |
180 | yyunlex(); | |
0f8490d1 | 181 | parser->yychar = yytoken = YYEOF; |
e53d8f76 | 182 | } |
9eb5c532 | 183 | | GRAMFULLSTMT |
28ac2b49 | 184 | { |
9eb5c532 | 185 | parser->expect = XSTATE; |
5a2060e2 | 186 | $<ival>$ = 0; |
9eb5c532 Z |
187 | } |
188 | fullstmt | |
189 | { | |
5f211341 | 190 | PL_pad_reset_pending = TRUE; |
53443c95 | 191 | PL_eval_root = $fullstmt; |
28ac2b49 Z |
192 | $$ = 0; |
193 | yyunlex(); | |
0f8490d1 | 194 | parser->yychar = yytoken = YYEOF; |
28ac2b49 | 195 | } |
07ffcb73 Z |
196 | | GRAMSTMTSEQ |
197 | { | |
198 | parser->expect = XSTATE; | |
5a2060e2 | 199 | $<ival>$ = 0; |
07ffcb73 | 200 | } |
5f211341 | 201 | stmtseq |
07ffcb73 | 202 | { |
53443c95 | 203 | PL_eval_root = $stmtseq; |
07ffcb73 Z |
204 | $$ = 0; |
205 | } | |
996b0cb8 PLE |
206 | | GRAMSUBSIGNATURE |
207 | { | |
208 | parser->expect = XSTATE; | |
209 | $<ival>$ = 0; | |
210 | } | |
211 | subsigguts | |
212 | { | |
53443c95 | 213 | PL_eval_root = $subsigguts; |
996b0cb8 PLE |
214 | $$ = 0; |
215 | } | |
07ffcb73 Z |
216 | ; |
217 | ||
891be019 | 218 | /* An ordinary block */ |
d0a6a9c7 | 219 | block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE |
c588171e BZ |
220 | { if (parser->copline > (line_t)$PERLY_BRACE_OPEN) |
221 | parser->copline = (line_t)$PERLY_BRACE_OPEN; | |
53443c95 | 222 | $$ = block_end($remember, $stmtseq); |
f05e27e5 | 223 | } |
a0d0e21e LW |
224 | ; |
225 | ||
7c70caa5 | 226 | /* format body */ |
db83e45c BZ |
227 | formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT |
228 | { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN) | |
229 | parser->copline = (line_t)$PERLY_EQUAL_SIGN; | |
53443c95 | 230 | $$ = block_end($remember, $formstmtseq); |
7c70caa5 FC |
231 | } |
232 | ; | |
233 | ||
55497cff | 234 | remember: /* NULL */ /* start a full lexical scope */ |
34b54951 FC |
235 | { $$ = block_start(TRUE); |
236 | parser->parsed_sub = 0; } | |
55497cff PP |
237 | ; |
238 | ||
d0a6a9c7 | 239 | mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE |
c588171e BZ |
240 | { if (parser->copline > (line_t)$PERLY_BRACE_OPEN) |
241 | parser->copline = (line_t)$PERLY_BRACE_OPEN; | |
53443c95 | 242 | $$ = block_end($mremember, $stmtseq); |
f05e27e5 | 243 | } |
55497cff PP |
244 | ; |
245 | ||
246 | mremember: /* NULL */ /* start a partial lexical scope */ | |
34b54951 FC |
247 | { $$ = block_start(FALSE); |
248 | parser->parsed_sub = 0; } | |
8d063cd8 LW |
249 | ; |
250 | ||
eae48c89 | 251 | /* A sequence of statements in the program */ |
5f211341 | 252 | stmtseq : /* NULL */ |
a9f5ab8d | 253 | { $$ = NULL; } |
53443c95 BZ |
254 | | stmtseq[list] fullstmt |
255 | { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt); | |
3280af22 | 256 | PL_pad_reset_pending = TRUE; |
53443c95 | 257 | if ($list && $fullstmt) |
503de470 DM |
258 | PL_hints |= HINT_BLOCK_SCOPE; |
259 | } | |
8d063cd8 LW |
260 | ; |
261 | ||
705fe0e5 FC |
262 | /* A sequence of format lines */ |
263 | formstmtseq: /* NULL */ | |
a9f5ab8d | 264 | { $$ = NULL; } |
53443c95 BZ |
265 | | formstmtseq[list] formline |
266 | { $$ = op_append_list(OP_LINESEQ, $list, $formline); | |
705fe0e5 | 267 | PL_pad_reset_pending = TRUE; |
53443c95 | 268 | if ($list && $formline) |
705fe0e5 FC |
269 | PL_hints |= HINT_BLOCK_SCOPE; |
270 | } | |
271 | ; | |
272 | ||
8e720305 Z |
273 | /* A statement in the program, including optional labels */ |
274 | fullstmt: barestmt | |
eae48c89 | 275 | { |
53443c95 | 276 | $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL; |
eae48c89 | 277 | } |
8e720305 | 278 | | labfullstmt |
53443c95 | 279 | { $$ = $labfullstmt; } |
8e720305 Z |
280 | ; |
281 | ||
282 | labfullstmt: LABEL barestmt | |
283 | { | |
53443c95 | 284 | SV *label = cSVOPx_sv($LABEL); |
01719201 | 285 | $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8, |
53443c95 BZ |
286 | savepv(SvPVX_const(label)), $barestmt); |
287 | op_free($LABEL); | |
8e720305 | 288 | } |
53443c95 | 289 | | LABEL labfullstmt[list] |
8e720305 | 290 | { |
53443c95 | 291 | SV *label = cSVOPx_sv($LABEL); |
01719201 | 292 | $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8, |
53443c95 BZ |
293 | savepv(SvPVX_const(label)), $list); |
294 | op_free($LABEL); | |
8e720305 | 295 | } |
eae48c89 Z |
296 | ; |
297 | ||
298 | /* A bare statement, lacking label and other aspects of state op */ | |
299 | barestmt: PLUGSTMT | |
53443c95 | 300 | { $$ = $PLUGSTMT; } |
7c70caa5 | 301 | | FORMAT startformsub formname formblock |
f05e27e5 | 302 | { |
eae48c89 | 303 | CV *fmtcv = PL_compcv; |
53443c95 | 304 | newFORM($startformsub, $formname, $formblock); |
a9f5ab8d | 305 | $$ = NULL; |
4a273b91 | 306 | if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) { |
74a9453a | 307 | pad_add_weakref(fmtcv); |
f05e27e5 | 308 | } |
8b9fb2f9 | 309 | parser->parsed_sub = 1; |
eae48c89 | 310 | } |
50278755 | 311 | | SUB subname startsub |
75230cc1 DM |
312 | /* sub declaration or definition not within scope |
313 | of 'use feature "signatures"'*/ | |
50278755 | 314 | { |
53443c95 | 315 | init_named_cv(PL_compcv, $subname); |
624fa8bd FC |
316 | parser->in_my = 0; |
317 | parser->in_my_stash = NULL; | |
764212cf | 318 | } |
75230cc1 | 319 | proto subattrlist optsubbody |
eae48c89 Z |
320 | { |
321 | SvREFCNT_inc_simple_void(PL_compcv); | |
53443c95 BZ |
322 | $subname->op_type == OP_CONST |
323 | ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody) | |
324 | : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody) | |
50278755 | 325 | ; |
a9f5ab8d | 326 | $$ = NULL; |
764212cf | 327 | intro_my(); |
34b54951 | 328 | parser->parsed_sub = 1; |
f05e27e5 | 329 | } |
436ddf68 | 330 | | SIGSUB subname startsub |
75230cc1 DM |
331 | /* sub declaration or definition under 'use feature |
332 | * "signatures"'. (Note that a signature isn't | |
333 | * allowed in a declaration) | |
334 | */ | |
436ddf68 | 335 | { |
53443c95 | 336 | init_named_cv(PL_compcv, $subname); |
436ddf68 DM |
337 | parser->in_my = 0; |
338 | parser->in_my_stash = NULL; | |
339 | } | |
75230cc1 | 340 | subattrlist optsigsubbody |
436ddf68 DM |
341 | { |
342 | SvREFCNT_inc_simple_void(PL_compcv); | |
53443c95 BZ |
343 | $subname->op_type == OP_CONST |
344 | ? newATTRSUB($startsub, $subname, NULL, $subattrlist, $optsigsubbody) | |
345 | : newMYSUB( $startsub, $subname, NULL, $subattrlist, $optsigsubbody) | |
436ddf68 DM |
346 | ; |
347 | $$ = NULL; | |
348 | intro_my(); | |
349 | parser->parsed_sub = 1; | |
350 | } | |
5adeeefb | 351 | | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_SEMICOLON |
5f211341 | 352 | { |
53443c95 BZ |
353 | package($package); |
354 | if ($version) | |
355 | package_version($version); | |
a9f5ab8d | 356 | $$ = NULL; |
eae48c89 Z |
357 | } |
358 | | USE startsub | |
359 | { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ } | |
5adeeefb | 360 | BAREWORD[version] BAREWORD[module] optlistexpr PERLY_SEMICOLON |
eae48c89 Z |
361 | { |
362 | SvREFCNT_inc_simple_void(PL_compcv); | |
53443c95 | 363 | utilize($USE, $startsub, $version, $module, $optlistexpr); |
34b54951 | 364 | parser->parsed_sub = 1; |
a9f5ab8d | 365 | $$ = NULL; |
eae48c89 | 366 | } |
04884b68 | 367 | | IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else |
eae48c89 | 368 | { |
53443c95 BZ |
369 | $$ = block_end($remember, |
370 | newCONDOP(0, $mexpr, op_scope($mblock), $else)); | |
371 | parser->copline = (line_t)$IF; | |
eae48c89 | 372 | } |
04884b68 | 373 | | UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else |
eae48c89 | 374 | { |
53443c95 BZ |
375 | $$ = block_end($remember, |
376 | newCONDOP(0, $mexpr, $else, op_scope($mblock))); | |
377 | parser->copline = (line_t)$UNLESS; | |
eae48c89 | 378 | } |
04884b68 | 379 | | GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock |
eae48c89 | 380 | { |
53443c95 BZ |
381 | $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0)); |
382 | parser->copline = (line_t)$GIVEN; | |
eae48c89 | 383 | } |
04884b68 | 384 | | WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock |
53443c95 | 385 | { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); } |
7896dde7 | 386 | | DEFAULT block |
53443c95 | 387 | { $$ = newWHENOP(0, op_scope($block)); } |
04884b68 | 388 | | WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont |
eae48c89 | 389 | { |
53443c95 | 390 | $$ = block_end($remember, |
a9f5ab8d | 391 | newWHILEOP(0, 1, NULL, |
53443c95 BZ |
392 | $texpr, $mblock, $cont, $mintro)); |
393 | parser->copline = (line_t)$WHILE; | |
eae48c89 | 394 | } |
04884b68 | 395 | | UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont |
eae48c89 | 396 | { |
53443c95 | 397 | $$ = block_end($remember, |
a9f5ab8d | 398 | newWHILEOP(0, 1, NULL, |
53443c95 BZ |
399 | $iexpr, $mblock, $cont, $mintro)); |
400 | parser->copline = (line_t)$UNTIL; | |
eae48c89 | 401 | } |
ee67f254 | 402 | | FOR PERLY_PAREN_OPEN remember mnexpr[init_mnexpr] PERLY_SEMICOLON |
2d0e3c96 | 403 | { parser->expect = XTERM; } |
5adeeefb | 404 | texpr PERLY_SEMICOLON |
2d0e3c96 | 405 | { parser->expect = XTERM; } |
04884b68 | 406 | mintro mnexpr[iterate_mnexpr] PERLY_PAREN_CLOSE |
eae48c89 Z |
407 | mblock |
408 | { | |
53443c95 | 409 | OP *initop = $init_mnexpr; |
a9f5ab8d | 410 | OP *forop = newWHILEOP(0, 1, NULL, |
53443c95 | 411 | scalar($texpr), $mblock, $iterate_mnexpr, $mintro); |
eae48c89 Z |
412 | if (initop) { |
413 | forop = op_prepend_elem(OP_LINESEQ, initop, | |
414 | op_append_elem(OP_LINESEQ, | |
415 | newOP(OP_UNSTACK, OPf_SPECIAL), | |
416 | forop)); | |
5f211341 | 417 | } |
0f602692 | 418 | PL_hints |= HINT_BLOCK_SCOPE; |
53443c95 BZ |
419 | $$ = block_end($remember, forop); |
420 | parser->copline = (line_t)$FOR; | |
eae48c89 | 421 | } |
04884b68 | 422 | | FOR MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont |
eae48c89 | 423 | { |
53443c95 BZ |
424 | $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont)); |
425 | parser->copline = (line_t)$FOR; | |
eae48c89 | 426 | } |
04884b68 | 427 | | FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont |
eae48c89 | 428 | { |
53443c95 BZ |
429 | $$ = block_end($remember, newFOROP(0, |
430 | op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont)); | |
431 | parser->copline = (line_t)$FOR; | |
eae48c89 | 432 | } |
e118fea3 | 433 | | FOR my_refgen remember my_var |
53443c95 | 434 | { parser->in_my = 0; $<opval>$ = my($my_var); }[variable] |
04884b68 | 435 | PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont |
d39c26a6 FC |
436 | { |
437 | $$ = block_end( | |
53443c95 | 438 | $remember, |
d39c26a6 FC |
439 | newFOROP(0, |
440 | op_lvalue( | |
441 | newUNOP(OP_REFGEN, 0, | |
53443c95 | 442 | $<opval>variable), |
d39c26a6 | 443 | OP_ENTERLOOP), |
53443c95 | 444 | $mexpr, $mblock, $cont) |
d39c26a6 | 445 | ); |
53443c95 | 446 | parser->copline = (line_t)$FOR; |
d39c26a6 | 447 | } |
04884b68 | 448 | | FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont |
d39c26a6 | 449 | { |
53443c95 | 450 | $$ = block_end($remember, newFOROP( |
d39c26a6 | 451 | 0, op_lvalue(newUNOP(OP_REFGEN, 0, |
53443c95 BZ |
452 | $refgen_topic), |
453 | OP_ENTERLOOP), $mexpr, $mblock, $cont)); | |
454 | parser->copline = (line_t)$FOR; | |
d39c26a6 | 455 | } |
04884b68 | 456 | | FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont |
eae48c89 | 457 | { |
53443c95 BZ |
458 | $$ = block_end($remember, |
459 | newFOROP(0, NULL, $mexpr, $mblock, $cont)); | |
460 | parser->copline = (line_t)$FOR; | |
eae48c89 Z |
461 | } |
462 | | block cont | |
463 | { | |
464 | /* a block is a loop that happens once */ | |
a9f5ab8d | 465 | $$ = newWHILEOP(0, 1, NULL, |
53443c95 | 466 | NULL, $block, $cont, 0); |
eae48c89 | 467 | } |
c588171e | 468 | | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember |
eae48c89 | 469 | { |
53443c95 BZ |
470 | package($package); |
471 | if ($version) { | |
472 | package_version($version); | |
eae48c89 Z |
473 | } |
474 | } | |
d0a6a9c7 | 475 | stmtseq PERLY_BRACE_CLOSE |
eae48c89 Z |
476 | { |
477 | /* a block is a loop that happens once */ | |
a9f5ab8d | 478 | $$ = newWHILEOP(0, 1, NULL, |
53443c95 | 479 | NULL, block_end($remember, $stmtseq), NULL, 0); |
c588171e BZ |
480 | if (parser->copline > (line_t)$PERLY_BRACE_OPEN) |
481 | parser->copline = (line_t)$PERLY_BRACE_OPEN; | |
eae48c89 | 482 | } |
5adeeefb | 483 | | sideff PERLY_SEMICOLON |
eae48c89 | 484 | { |
53443c95 | 485 | $$ = $sideff; |
eae48c89 | 486 | } |
5adeeefb | 487 | | YADAYADA PERLY_SEMICOLON |
29d69c3c Z |
488 | { |
489 | $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0), | |
490 | newSVOP(OP_CONST, 0, newSVpvs("Unimplemented"))); | |
491 | } | |
5adeeefb | 492 | | PERLY_SEMICOLON |
eae48c89 | 493 | { |
a9f5ab8d | 494 | $$ = NULL; |
624fa8bd | 495 | parser->copline = NOLINE; |
5f211341 | 496 | } |
8d063cd8 LW |
497 | ; |
498 | ||
705fe0e5 FC |
499 | /* Format line */ |
500 | formline: THING formarg | |
501 | { OP *list; | |
53443c95 BZ |
502 | if ($formarg) { |
503 | OP *term = $formarg; | |
504 | list = op_append_elem(OP_LIST, $THING, term); | |
705fe0e5 FC |
505 | } |
506 | else { | |
53443c95 | 507 | list = $THING; |
705fe0e5 | 508 | } |
624fa8bd FC |
509 | if (parser->copline == NOLINE) |
510 | parser->copline = CopLINE(PL_curcop)-1; | |
511 | else parser->copline--; | |
705fe0e5 | 512 | $$ = newSTATEOP(0, NULL, |
03d05f6e | 513 | op_convert_list(OP_FORMLINE, 0, list)); |
705fe0e5 FC |
514 | } |
515 | ; | |
516 | ||
517 | formarg : /* NULL */ | |
518 | { $$ = NULL; } | |
519 | | FORMLBRACK stmtseq FORMRBRACK | |
53443c95 | 520 | { $$ = op_unscope($stmtseq); } |
705fe0e5 FC |
521 | ; |
522 | ||
53443c95 BZ |
523 | condition: expr |
524 | ; | |
525 | ||
891be019 | 526 | /* An expression which may have a side-effect */ |
a687059c | 527 | sideff : error |
a9f5ab8d | 528 | { $$ = NULL; } |
53443c95 BZ |
529 | | expr[body] |
530 | { $$ = $body; } | |
531 | | expr[body] IF condition | |
532 | { $$ = newLOGOP(OP_AND, 0, $condition, $body); } | |
533 | | expr[body] UNLESS condition | |
534 | { $$ = newLOGOP(OP_OR, 0, $condition, $body); } | |
535 | | expr[body] WHILE condition | |
536 | { $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); } | |
537 | | expr[body] UNTIL iexpr | |
538 | { $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); } | |
539 | | expr[body] FOR condition | |
540 | { $$ = newFOROP(0, NULL, $condition, $body, NULL); | |
541 | parser->copline = (line_t)$FOR; } | |
542 | | expr[body] WHEN condition | |
543 | { $$ = newWHENOP($condition, op_scope($body)); } | |
79072805 LW |
544 | ; |
545 | ||
891be019 | 546 | /* else and elsif blocks */ |
79072805 | 547 | else : /* NULL */ |
a9f5ab8d | 548 | { $$ = NULL; } |
55497cff | 549 | | ELSE mblock |
3ad73efd | 550 | { |
53443c95 BZ |
551 | ($mblock)->op_flags |= OPf_PARENS; |
552 | $$ = op_scope($mblock); | |
f05e27e5 | 553 | } |
04884b68 | 554 | | ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else[else.recurse] |
53443c95 | 555 | { parser->copline = (line_t)$ELSIF; |
3ad73efd | 556 | $$ = newCONDOP(0, |
53443c95 BZ |
557 | newSTATEOP(OPf_SPECIAL,NULL,$mexpr), |
558 | op_scope($mblock), $[else.recurse]); | |
3ad73efd | 559 | PL_hints |= HINT_BLOCK_SCOPE; |
f05e27e5 | 560 | } |
79072805 LW |
561 | ; |
562 | ||
891be019 | 563 | /* Continue blocks */ |
79072805 | 564 | cont : /* NULL */ |
a9f5ab8d | 565 | { $$ = NULL; } |
79072805 | 566 | | CONTINUE block |
53443c95 | 567 | { $$ = op_scope($block); } |
79072805 LW |
568 | ; |
569 | ||
a034e688 DM |
570 | /* determine whether there are any new my declarations */ |
571 | mintro : /* NULL */ | |
572 | { $$ = (PL_min_intro_pending && | |
573 | PL_max_intro_pending >= PL_min_intro_pending); | |
574 | intro_my(); } | |
575 | ||
891be019 | 576 | /* Normal expression */ |
8d063cd8 | 577 | nexpr : /* NULL */ |
a9f5ab8d | 578 | { $$ = NULL; } |
8d063cd8 LW |
579 | | sideff |
580 | ; | |
581 | ||
891be019 | 582 | /* Boolean expression */ |
8d063cd8 | 583 | texpr : /* NULL means true */ |
f05e27e5 DM |
584 | { YYSTYPE tmplval; |
585 | (void)scan_num("1", &tmplval); | |
586 | $$ = tmplval.opval; } | |
8d063cd8 LW |
587 | | expr |
588 | ; | |
589 | ||
891be019 | 590 | /* Inverted boolean expression */ |
55497cff | 591 | iexpr : expr |
53443c95 | 592 | { $$ = invert(scalar($expr)); } |
55497cff PP |
593 | ; |
594 | ||
891be019 | 595 | /* Expression with its own lexical scope */ |
55497cff | 596 | mexpr : expr |
53443c95 | 597 | { $$ = $expr; intro_my(); } |
bbce6d69 PP |
598 | ; |
599 | ||
600 | mnexpr : nexpr | |
53443c95 | 601 | { $$ = $nexpr; intro_my(); } |
55497cff PP |
602 | ; |
603 | ||
53443c95 | 604 | formname: BAREWORD { $$ = $BAREWORD; } |
a9f5ab8d | 605 | | /* NULL */ { $$ = NULL; } |
8d063cd8 LW |
606 | ; |
607 | ||
fa83b5b6 | 608 | startsub: /* NULL */ /* start a regular subroutine scope */ |
a8ff2fa6 DM |
609 | { $$ = start_subparse(FALSE, 0); |
610 | SAVEFREESV(PL_compcv); } | |
f05e27e5 | 611 | |
28757baa PP |
612 | ; |
613 | ||
614 | startanonsub: /* NULL */ /* start an anonymous subroutine scope */ | |
a8ff2fa6 DM |
615 | { $$ = start_subparse(FALSE, CVf_ANON); |
616 | SAVEFREESV(PL_compcv); } | |
28757baa PP |
617 | ; |
618 | ||
44a8e56a | 619 | startformsub: /* NULL */ /* start a format subroutine scope */ |
a8ff2fa6 DM |
620 | { $$ = start_subparse(TRUE, 0); |
621 | SAVEFREESV(PL_compcv); } | |
44a8e56a PP |
622 | ; |
623 | ||
891be019 | 624 | /* Name of a subroutine - must be a bareword, could be special */ |
185c2e96 | 625 | subname : BAREWORD |
4210d3f1 | 626 | | PRIVATEREF |
a0d0e21e LW |
627 | ; |
628 | ||
891be019 | 629 | /* Subroutine prototype */ |
4633a7c4 | 630 | proto : /* NULL */ |
a9f5ab8d | 631 | { $$ = NULL; } |
4633a7c4 LW |
632 | | THING |
633 | ; | |
28757baa | 634 | |
891be019 | 635 | /* Optional list of subroutine attributes */ |
09bef843 | 636 | subattrlist: /* NULL */ |
a9f5ab8d | 637 | { $$ = NULL; } |
09bef843 | 638 | | COLONATTR THING |
53443c95 | 639 | { $$ = $THING; } |
09bef843 | 640 | | COLONATTR |
a9f5ab8d | 641 | { $$ = NULL; } |
09bef843 SB |
642 | ; |
643 | ||
891be019 | 644 | /* List of attributes for a "my" variable declaration */ |
09bef843 | 645 | myattrlist: COLONATTR THING |
53443c95 | 646 | { $$ = $THING; } |
09bef843 | 647 | | COLONATTR |
a9f5ab8d | 648 | { $$ = NULL; } |
09bef843 SB |
649 | ; |
650 | ||
abcf453d | 651 | |
d3d9da4a DM |
652 | |
653 | /* -------------------------------------- | |
654 | * subroutine signature parsing | |
655 | */ | |
656 | ||
657 | /* the '' or 'foo' part of a '$' or '@foo' etc signature variable */ | |
49fb8620 | 658 | sigvarname: /* NULL */ |
a9f5ab8d | 659 | { parser->in_my = 0; $$ = NULL; } |
d3d9da4a | 660 | | PRIVATEREF |
53443c95 | 661 | { parser->in_my = 0; $$ = $PRIVATEREF; } |
d3d9da4a DM |
662 | ; |
663 | ||
664 | sigslurpsigil: | |
9086c946 | 665 | PERLY_SNAIL |
d3d9da4a | 666 | { $$ = '@'; } |
0ba95c59 | 667 | | PERLY_PERCENT_SIGN |
d3d9da4a DM |
668 | { $$ = '%'; } |
669 | ||
670 | /* @, %, @foo, %foo */ | |
671 | sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */ | |
672 | { | |
53443c95 BZ |
673 | I32 sigil = $sigslurpsigil; |
674 | OP *var = $sigvarname; | |
675 | OP *defexpr = $sigdefault; | |
d3d9da4a | 676 | |
036bbc13 | 677 | if (parser->sig_slurpy) |
d3d9da4a | 678 | yyerror("Multiple slurpy parameters not allowed"); |
036bbc13 | 679 | parser->sig_slurpy = (char)sigil; |
d3d9da4a DM |
680 | |
681 | if (defexpr) | |
bb6b75cd | 682 | yyerror("A slurpy parameter may not have " |
d3d9da4a DM |
683 | "a default value"); |
684 | ||
a9f5ab8d | 685 | $$ = var ? newSTATEOP(0, NULL, var) : NULL; |
d3d9da4a DM |
686 | } |
687 | ; | |
688 | ||
689 | /* default part of sub signature scalar element: i.e. '= default_expr' */ | |
690 | sigdefault: /* NULL */ | |
a9f5ab8d | 691 | { $$ = NULL; } |
d3d9da4a DM |
692 | | ASSIGNOP |
693 | { $$ = newOP(OP_NULL, 0); } | |
694 | | ASSIGNOP term | |
53443c95 | 695 | { $$ = $term; } |
d3d9da4a DM |
696 | |
697 | ||
698 | /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */ | |
699 | sigscalarelem: | |
bfa838cc | 700 | PERLY_DOLLAR sigvarname sigdefault |
d3d9da4a | 701 | { |
53443c95 BZ |
702 | OP *var = $sigvarname; |
703 | OP *defexpr = $sigdefault; | |
d3d9da4a | 704 | |
036bbc13 | 705 | if (parser->sig_slurpy) |
d3d9da4a DM |
706 | yyerror("Slurpy parameter not last"); |
707 | ||
036bbc13 | 708 | parser->sig_elems++; |
d3d9da4a | 709 | |
d3d9da4a | 710 | if (defexpr) { |
036bbc13 | 711 | parser->sig_optelems++; |
4fa06845 DM |
712 | |
713 | if ( defexpr->op_type == OP_NULL | |
d3d9da4a DM |
714 | && !(defexpr->op_flags & OPf_KIDS)) |
715 | { | |
4fa06845 DM |
716 | /* handle '$=' special case */ |
717 | if (var) | |
718 | yyerror("Optional parameter " | |
719 | "lacks default expression"); | |
d3d9da4a DM |
720 | op_free(defexpr); |
721 | } | |
4fa06845 DM |
722 | else { |
723 | /* a normal '=default' expression */ | |
724 | OP *defop = (OP*)alloc_LOGOP(OP_ARGDEFELEM, | |
725 | defexpr, | |
726 | LINKLIST(defexpr)); | |
727 | /* re-purpose op_targ to hold @_ index */ | |
6daeaaa3 | 728 | defop->op_targ = |
036bbc13 | 729 | (PADOFFSET)(parser->sig_elems - 1); |
4fa06845 DM |
730 | |
731 | if (var) { | |
732 | var->op_flags |= OPf_STACKED; | |
733 | (void)op_sibling_splice(var, | |
734 | NULL, 0, defop); | |
735 | scalar(defop); | |
736 | } | |
737 | else | |
738 | var = newUNOP(OP_NULL, 0, defop); | |
739 | ||
740 | LINKLIST(var); | |
741 | /* NB: normally the first child of a | |
742 | * logop is executed before the logop, | |
743 | * and it pushes a boolean result | |
744 | * ready for the logop. For ARGDEFELEM, | |
745 | * the op itself does the boolean | |
746 | * calculation, so set the first op to | |
747 | * it instead. | |
748 | */ | |
749 | var->op_next = defop; | |
750 | defexpr->op_next = var; | |
d3d9da4a DM |
751 | } |
752 | } | |
753 | else { | |
036bbc13 | 754 | if (parser->sig_optelems) |
d3d9da4a DM |
755 | yyerror("Mandatory parameter " |
756 | "follows optional parameter"); | |
d3d9da4a DM |
757 | } |
758 | ||
a9f5ab8d | 759 | $$ = var ? newSTATEOP(0, NULL, var) : NULL; |
d3d9da4a DM |
760 | } |
761 | ; | |
762 | ||
763 | ||
764 | /* subroutine signature element: e.g. '$x = $default' or '%h' */ | |
765 | sigelem: sigscalarelem | |
53443c95 | 766 | { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; } |
d3d9da4a | 767 | | sigslurpelem |
53443c95 | 768 | { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; } |
d3d9da4a DM |
769 | ; |
770 | ||
771 | /* list of subroutine signature elements */ | |
772 | siglist: | |
581f9a7a | 773 | siglist[list] PERLY_COMMA |
53443c95 | 774 | { $$ = $list; } |
581f9a7a | 775 | | siglist[list] PERLY_COMMA sigelem[element] |
30d9c59b | 776 | { |
53443c95 | 777 | $$ = op_append_list(OP_LINESEQ, $list, $element); |
30d9c59b | 778 | } |
53443c95 BZ |
779 | | sigelem[element] %prec PREC_LOW |
780 | { $$ = $element; } | |
30d9c59b Z |
781 | ; |
782 | ||
d3d9da4a DM |
783 | /* () or (....) */ |
784 | siglistornull: /* NULL */ | |
a9f5ab8d | 785 | { $$ = NULL; } |
d3d9da4a | 786 | | siglist |
53443c95 | 787 | { $$ = $siglist; } |
d3d9da4a | 788 | |
75230cc1 DM |
789 | /* optional subroutine signature */ |
790 | optsubsignature: /* NULL */ | |
791 | { $$ = NULL; } | |
792 | | subsignature | |
53443c95 | 793 | { $$ = $subsignature; } |
75230cc1 | 794 | |
d3d9da4a | 795 | /* Subroutine signature */ |
04884b68 | 796 | subsignature: PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE |
53443c95 | 797 | { $$ = $subsigguts; } |
996b0cb8 PLE |
798 | |
799 | subsigguts: | |
d3d9da4a DM |
800 | { |
801 | ENTER; | |
036bbc13 FC |
802 | SAVEIV(parser->sig_elems); |
803 | SAVEIV(parser->sig_optelems); | |
804 | SAVEI8(parser->sig_slurpy); | |
805 | parser->sig_elems = 0; | |
806 | parser->sig_optelems = 0; | |
807 | parser->sig_slurpy = 0; | |
49fb8620 | 808 | parser->in_my = KEY_sigvar; |
d3d9da4a DM |
809 | } |
810 | siglistornull | |
d3d9da4a | 811 | { |
53443c95 | 812 | OP *sigops = $siglistornull; |
f417cfa9 | 813 | struct op_argcheck_aux *aux; |
4fa06845 | 814 | OP *check; |
d3d9da4a | 815 | |
894f226e DM |
816 | if (!FEATURE_SIGNATURES_IS_ENABLED) |
817 | Perl_croak(aTHX_ "Experimental " | |
818 | "subroutine signatures not enabled"); | |
d3d9da4a DM |
819 | |
820 | /* We shouldn't get here otherwise */ | |
821 | Perl_ck_warner_d(aTHX_ | |
822 | packWARN(WARN_EXPERIMENTAL__SIGNATURES), | |
823 | "The signatures feature is experimental"); | |
824 | ||
f417cfa9 DM |
825 | aux = (struct op_argcheck_aux*) |
826 | PerlMemShared_malloc( | |
827 | sizeof(struct op_argcheck_aux)); | |
828 | aux->params = parser->sig_elems; | |
829 | aux->opt_params = parser->sig_optelems; | |
830 | aux->slurpy = parser->sig_slurpy; | |
831 | check = newUNOP_AUX(OP_ARGCHECK, 0, NULL, | |
832 | (UNOP_AUX_item *)aux); | |
4fa06845 DM |
833 | sigops = op_prepend_elem(OP_LINESEQ, check, sigops); |
834 | sigops = op_prepend_elem(OP_LINESEQ, | |
835 | newSTATEOP(0, NULL, NULL), | |
836 | sigops); | |
837 | /* a nextstate at the end handles context | |
838 | * correctly for an empty sub body */ | |
4df85778 | 839 | sigops = op_append_elem(OP_LINESEQ, |
4fa06845 DM |
840 | sigops, |
841 | newSTATEOP(0, NULL, NULL)); | |
4df85778 DM |
842 | /* wrap the list of arg ops in a NULL aux op. |
843 | This serves two purposes. First, it makes | |
844 | the arg list a separate subtree from the | |
845 | body of the sub, and secondly the null op | |
846 | may in future be upgraded to an OP_SIGNATURE | |
847 | when implemented. For now leave it as | |
848 | ex-argcheck */ | |
849 | $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL); | |
850 | op_null($$); | |
d3d9da4a | 851 | |
49fb8620 | 852 | parser->in_my = 0; |
a8c56356 DM |
853 | /* tell the toker that attrributes can follow |
854 | * this sig, but only so that the toker | |
855 | * can skip through any (illegal) trailing | |
856 | * attribute text then give a useful error | |
857 | * message about "attributes before sig", | |
858 | * rather than falling over ina mess at | |
859 | * unrecognised syntax. | |
860 | */ | |
861 | parser->expect = XATTRBLOCK; | |
862 | parser->sig_seen = TRUE; | |
d3d9da4a DM |
863 | LEAVE; |
864 | } | |
865 | ; | |
866 | ||
75230cc1 | 867 | /* Optional subroutine body (for named subroutine declaration) */ |
53443c95 | 868 | optsubbody: subbody { $$ = $subbody; } |
5adeeefb | 869 | | PERLY_SEMICOLON { $$ = NULL; } |
75230cc1 DM |
870 | ; |
871 | ||
872 | ||
873 | /* Subroutine body (without signature) */ | |
d0a6a9c7 | 874 | subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE |
75230cc1 | 875 | { |
c588171e BZ |
876 | if (parser->copline > (line_t)$PERLY_BRACE_OPEN) |
877 | parser->copline = (line_t)$PERLY_BRACE_OPEN; | |
53443c95 | 878 | $$ = block_end($remember, $stmtseq); |
75230cc1 DM |
879 | } |
880 | ; | |
881 | ||
882 | ||
883 | /* optional [ Subroutine body with optional signature ] (for named | |
884 | * subroutine declaration) */ | |
53443c95 | 885 | optsigsubbody: sigsubbody { $$ = $sigsubbody; } |
5adeeefb | 886 | | PERLY_SEMICOLON { $$ = NULL; } |
d3d9da4a | 887 | |
75230cc1 | 888 | /* Subroutine body with optional signature */ |
d0a6a9c7 | 889 | sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE |
894f226e | 890 | { |
c588171e BZ |
891 | if (parser->copline > (line_t)$PERLY_BRACE_OPEN) |
892 | parser->copline = (line_t)$PERLY_BRACE_OPEN; | |
53443c95 BZ |
893 | $$ = block_end($remember, |
894 | op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq)); | |
894f226e DM |
895 | } |
896 | ; | |
897 | ||
d3d9da4a | 898 | |
891be019 | 899 | /* Ordinary expressions; logical combinations */ |
53443c95 BZ |
900 | expr : expr[lhs] ANDOP expr[rhs] |
901 | { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); } | |
902 | | expr[lhs] OROP[operator] expr[rhs] | |
903 | { $$ = newLOGOP($operator, 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 | } | |
bfa838cc | 1249 | | term[operand] ARROW PERLY_DOLLAR 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; } |
77b0379f | 1354 | | PERLY_SLASH 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 | ||
bfa838cc | 1381 | scalar : PERLY_DOLLAR 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 | ; |