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