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