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