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