Commit | Line | Data |
a0d0e21e |
1 | /* perly.y |
a687059c |
2 | * |
9607fc9c |
3 | * Copyright (c) 1991-1997, Larry Wall |
a687059c |
4 | * |
9ef589d8 |
5 | * You may distribute under the terms of either the GNU General Public |
6 | * License or the Artistic License, as specified in the README file. |
8d063cd8 |
7 | * |
a0d0e21e |
8 | */ |
9 | |
10 | /* |
11 | * 'I see,' laughed Strider. 'I look foul and feel fair. Is that it? |
14a38fd5 |
12 | * All that is gold does not glitter, not all those who wander are lost.' |
8d063cd8 |
13 | */ |
14 | |
15 | %{ |
79072805 |
16 | #include "EXTERN.h" |
8d063cd8 |
17 | #include "perl.h" |
378cc40b |
18 | |
a0d0e21e |
19 | static void |
8ac85365 |
20 | dep(void) |
a0d0e21e |
21 | { |
22 | deprecate("\"do\" to call subroutines"); |
23 | } |
f0fcb552 |
24 | |
8d063cd8 |
25 | %} |
26 | |
27 | %start prog |
28 | |
9d116dd7 |
29 | %{ |
a1a0e61e |
30 | /* I sense a Big Blue pattern here... */ |
31 | #if !defined(OEMVS) && !defined(__OPEN_VM) && !defined(POSIX_BC) |
9d116dd7 |
32 | %} |
33 | |
8d063cd8 |
34 | %union { |
79072805 |
35 | I32 ival; |
36 | char *pval; |
37 | OP *opval; |
38 | GV *gvval; |
8d063cd8 |
39 | } |
40 | |
9d116dd7 |
41 | %{ |
a1a0e61e |
42 | #endif /* !OEMVS && !__OPEN_VM && !POSIX_BC */ |
43 | |
44 | #ifdef USE_PURE_BISON |
bee8cd07 |
45 | #define YYLEX_PARAM (&yychar) |
a1a0e61e |
46 | #endif |
9d116dd7 |
47 | %} |
48 | |
f0fcb552 |
49 | %token <ival> '{' ')' |
50 | |
a0d0e21e |
51 | %token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF |
4633a7c4 |
52 | %token <opval> FUNC0SUB UNIOPSUB LSTOPSUB |
79072805 |
53 | %token <pval> LABEL |
a0d0e21e |
54 | %token <ival> FORMAT SUB ANONSUB PACKAGE USE |
79072805 |
55 | %token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR |
56 | %token <ival> LOOPEX DOTDOT |
36477c24 |
57 | %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP |
79072805 |
58 | %token <ival> RELOP EQOP MULOP ADDOP |
55497cff |
59 | %token <ival> DOLSHARP DO HASHBRACK NOAMP |
60 | %token LOCAL MY |
79072805 |
61 | |
44a8e56a |
62 | %type <ival> prog decl local format startsub startanonsub startformsub |
28757baa |
63 | %type <ival> remember mremember '&' |
bbce6d69 |
64 | %type <opval> block mblock lineseq line loop cond else |
a0d0e21e |
65 | %type <opval> expr term scalar ary hsh arylen star amper sideff |
bbce6d69 |
66 | %type <opval> argexpr nexpr texpr iexpr mexpr mnexpr mtexpr miexpr |
44a8e56a |
67 | %type <opval> listexpr listexprcom indirob listop method |
68 | %type <opval> formname subname proto subbody cont my_scalar |
79072805 |
69 | %type <pval> label |
79072805 |
70 | |
a0d0e21e |
71 | %left <ival> OROP |
463ee0b2 |
72 | %left ANDOP |
c07a80fd |
73 | %right NOTOP |
36477c24 |
74 | %nonassoc LSTOP LSTOPSUB |
8d063cd8 |
75 | %left ',' |
a0d0e21e |
76 | %right <ival> ASSIGNOP |
8d063cd8 |
77 | %right '?' ':' |
78 | %nonassoc DOTDOT |
79 | %left OROR |
80 | %left ANDAND |
79072805 |
81 | %left <ival> BITOROP |
82 | %left <ival> BITANDOP |
a687059c |
83 | %nonassoc EQOP |
84 | %nonassoc RELOP |
36477c24 |
85 | %nonassoc UNIOP UNIOPSUB |
79072805 |
86 | %left <ival> SHIFTOP |
a687059c |
87 | %left ADDOP |
88 | %left MULOP |
8990e307 |
89 | %left <ival> MATCHOP |
79072805 |
90 | %right '!' '~' UMINUS REFGEN |
91 | %right <ival> POWOP |
92 | %nonassoc PREINC PREDEC POSTINC POSTDEC |
8990e307 |
93 | %left ARROW |
8d063cd8 |
94 | %left '(' |
95 | |
96 | %% /* RULES */ |
97 | |
ae986130 |
98 | prog : /* NULL */ |
99 | { |
100 | #if defined(YYDEBUG) && defined(DEBUGGING) |
3280af22 |
101 | yydebug = (PL_debug & 1); |
ae986130 |
102 | #endif |
3280af22 |
103 | PL_expect = XSTATE; |
ae986130 |
104 | } |
105 | /*CONTINUED*/ lineseq |
a0d0e21e |
106 | { newPROG($2); } |
8d063cd8 |
107 | ; |
108 | |
a687059c |
109 | block : '{' remember lineseq '}' |
3280af22 |
110 | { if (PL_copline > (line_t)$1) |
111 | PL_copline = $1; |
36477c24 |
112 | $$ = block_end($2, $3); } |
a0d0e21e |
113 | ; |
114 | |
55497cff |
115 | remember: /* NULL */ /* start a full lexical scope */ |
116 | { $$ = block_start(TRUE); } |
117 | ; |
118 | |
bbce6d69 |
119 | mblock : '{' mremember lineseq '}' |
3280af22 |
120 | { if (PL_copline > (line_t)$1) |
121 | PL_copline = $1; |
36477c24 |
122 | $$ = block_end($2, $3); } |
55497cff |
123 | ; |
124 | |
125 | mremember: /* NULL */ /* start a partial lexical scope */ |
126 | { $$ = block_start(FALSE); } |
8d063cd8 |
127 | ; |
128 | |
129 | lineseq : /* NULL */ |
79072805 |
130 | { $$ = Nullop; } |
131 | | lineseq decl |
132 | { $$ = $1; } |
8d063cd8 |
133 | | lineseq line |
463ee0b2 |
134 | { $$ = append_list(OP_LINESEQ, |
a0d0e21e |
135 | (LISTOP*)$1, (LISTOP*)$2); |
3280af22 |
136 | PL_pad_reset_pending = TRUE; |
137 | if ($1 && $2) PL_hints |= HINT_BLOCK_SCOPE; } |
8d063cd8 |
138 | ; |
139 | |
79072805 |
140 | line : label cond |
141 | { $$ = newSTATEOP(0, $1, $2); } |
8d063cd8 |
142 | | loop /* loops add their own labels */ |
143 | | label ';' |
144 | { if ($1 != Nullch) { |
79072805 |
145 | $$ = newSTATEOP(0, $1, newOP(OP_NULL, 0)); |
450a55e4 |
146 | } |
147 | else { |
79072805 |
148 | $$ = Nullop; |
3280af22 |
149 | PL_copline = NOLINE; |
32c2e4fb |
150 | } |
3280af22 |
151 | PL_expect = XSTATE; } |
8d063cd8 |
152 | | label sideff ';' |
79072805 |
153 | { $$ = newSTATEOP(0, $1, $2); |
3280af22 |
154 | PL_expect = XSTATE; } |
8d063cd8 |
155 | ; |
156 | |
a687059c |
157 | sideff : error |
79072805 |
158 | { $$ = Nullop; } |
a687059c |
159 | | expr |
79072805 |
160 | { $$ = $1; } |
a687059c |
161 | | expr IF expr |
79072805 |
162 | { $$ = newLOGOP(OP_AND, 0, $3, $1); } |
a687059c |
163 | | expr UNLESS expr |
79072805 |
164 | { $$ = newLOGOP(OP_OR, 0, $3, $1); } |
a687059c |
165 | | expr WHILE expr |
8990e307 |
166 | { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); } |
55497cff |
167 | | expr UNTIL iexpr |
168 | { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1);} |
ecca16b0 |
169 | | expr FOR expr |
170 | { $$ = newFOROP(0, Nullch, $2, |
171 | Nullop, $3, $1, Nullop); } |
79072805 |
172 | ; |
173 | |
174 | else : /* NULL */ |
175 | { $$ = Nullop; } |
55497cff |
176 | | ELSE mblock |
79072805 |
177 | { $$ = scope($2); } |
55497cff |
178 | | ELSIF '(' mexpr ')' mblock else |
3280af22 |
179 | { PL_copline = $1; |
bbce6d69 |
180 | $$ = newSTATEOP(0, Nullch, |
181 | newCONDOP(0, $3, scope($5), $6)); |
3280af22 |
182 | PL_hints |= HINT_BLOCK_SCOPE; } |
79072805 |
183 | ; |
184 | |
55497cff |
185 | cond : IF '(' remember mexpr ')' mblock else |
3280af22 |
186 | { PL_copline = $1; |
36477c24 |
187 | $$ = block_end($3, |
bbce6d69 |
188 | newCONDOP(0, $4, scope($6), $7)); } |
55497cff |
189 | | UNLESS '(' remember miexpr ')' mblock else |
3280af22 |
190 | { PL_copline = $1; |
36477c24 |
191 | $$ = block_end($3, |
bbce6d69 |
192 | newCONDOP(0, $4, scope($6), $7)); } |
79072805 |
193 | ; |
194 | |
195 | cont : /* NULL */ |
196 | { $$ = Nullop; } |
197 | | CONTINUE block |
198 | { $$ = scope($2); } |
199 | ; |
200 | |
55497cff |
201 | loop : label WHILE '(' remember mtexpr ')' mblock cont |
3280af22 |
202 | { PL_copline = $2; |
36477c24 |
203 | $$ = block_end($4, |
55497cff |
204 | newSTATEOP(0, $1, |
bbce6d69 |
205 | newWHILEOP(0, 1, (LOOP*)Nullop, |
fb73857a |
206 | $2, $5, $7, $8))); } |
55497cff |
207 | | label UNTIL '(' remember miexpr ')' mblock cont |
3280af22 |
208 | { PL_copline = $2; |
36477c24 |
209 | $$ = block_end($4, |
55497cff |
210 | newSTATEOP(0, $1, |
bbce6d69 |
211 | newWHILEOP(0, 1, (LOOP*)Nullop, |
fb73857a |
212 | $2, $5, $7, $8))); } |
bbce6d69 |
213 | | label FOR MY remember my_scalar '(' mexpr ')' mblock cont |
36477c24 |
214 | { $$ = block_end($4, |
bbce6d69 |
215 | newFOROP(0, $1, $2, $5, $7, $9, $10)); } |
216 | | label FOR scalar '(' remember mexpr ')' mblock cont |
36477c24 |
217 | { $$ = block_end($5, |
bbce6d69 |
218 | newFOROP(0, $1, $2, mod($3, OP_ENTERLOOP), |
219 | $6, $8, $9)); } |
220 | | label FOR '(' remember mexpr ')' mblock cont |
36477c24 |
221 | { $$ = block_end($4, |
55497cff |
222 | newFOROP(0, $1, $2, Nullop, $5, $7, $8)); } |
bbce6d69 |
223 | | label FOR '(' remember mnexpr ';' mtexpr ';' mnexpr ')' mblock |
8d063cd8 |
224 | /* basically fake up an initialize-while lineseq */ |
fb73857a |
225 | { OP *forop = append_elem(OP_LINESEQ, |
226 | scalar($5), |
227 | newWHILEOP(0, 1, (LOOP*)Nullop, |
228 | $2, scalar($7), |
229 | $11, scalar($9))); |
3280af22 |
230 | PL_copline = $2; |
fb73857a |
231 | $$ = block_end($4, newSTATEOP(0, $1, forop)); } |
79072805 |
232 | | label block cont /* a block is a loop that happens once */ |
fb73857a |
233 | { $$ = newSTATEOP(0, $1, |
234 | newWHILEOP(0, 1, (LOOP*)Nullop, |
235 | NOLINE, Nullop, $2, $3)); } |
8d063cd8 |
236 | ; |
237 | |
238 | nexpr : /* NULL */ |
79072805 |
239 | { $$ = Nullop; } |
8d063cd8 |
240 | | sideff |
241 | ; |
242 | |
243 | texpr : /* NULL means true */ |
79072805 |
244 | { (void)scan_num("1"); $$ = yylval.opval; } |
8d063cd8 |
245 | | expr |
246 | ; |
247 | |
55497cff |
248 | iexpr : expr |
249 | { $$ = invert(scalar($1)); } |
250 | ; |
251 | |
252 | mexpr : expr |
bbce6d69 |
253 | { $$ = $1; intro_my(); } |
254 | ; |
255 | |
256 | mnexpr : nexpr |
257 | { $$ = $1; intro_my(); } |
55497cff |
258 | ; |
259 | |
260 | mtexpr : texpr |
bbce6d69 |
261 | { $$ = $1; intro_my(); } |
55497cff |
262 | ; |
263 | |
264 | miexpr : iexpr |
bbce6d69 |
265 | { $$ = $1; intro_my(); } |
55497cff |
266 | ; |
267 | |
8d063cd8 |
268 | label : /* empty */ |
269 | { $$ = Nullch; } |
32c2e4fb |
270 | | LABEL |
8d063cd8 |
271 | ; |
272 | |
8d063cd8 |
273 | decl : format |
274 | { $$ = 0; } |
275 | | subrout |
276 | { $$ = 0; } |
a687059c |
277 | | package |
278 | { $$ = 0; } |
a0d0e21e |
279 | | use |
85e6fe83 |
280 | { $$ = 0; } |
8d063cd8 |
281 | ; |
282 | |
44a8e56a |
283 | format : FORMAT startformsub formname block |
a0d0e21e |
284 | { newFORM($2, $3, $4); } |
44a8e56a |
285 | ; |
286 | |
287 | formname: WORD { $$ = $1; } |
288 | | /* NULL */ { $$ = Nullop; } |
8d063cd8 |
289 | ; |
290 | |
28757baa |
291 | subrout : SUB startsub subname proto subbody |
4633a7c4 |
292 | { newSUB($2, $3, $4, $5); } |
28757baa |
293 | ; |
294 | |
fa83b5b6 |
295 | startsub: /* NULL */ /* start a regular subroutine scope */ |
774d564b |
296 | { $$ = start_subparse(FALSE, 0); } |
28757baa |
297 | ; |
298 | |
299 | startanonsub: /* NULL */ /* start an anonymous subroutine scope */ |
774d564b |
300 | { $$ = start_subparse(FALSE, CVf_ANON); } |
28757baa |
301 | ; |
302 | |
44a8e56a |
303 | startformsub: /* NULL */ /* start a format subroutine scope */ |
774d564b |
304 | { $$ = start_subparse(TRUE, 0); } |
44a8e56a |
305 | ; |
306 | |
3280af22 |
307 | subname : WORD { char *name = SvPV(((SVOP*)$1)->op_sv, PL_na); |
e858de61 |
308 | if (strEQ(name, "BEGIN") || strEQ(name, "END") |
7d07dbc2 |
309 | || strEQ(name, "INIT")) |
3280af22 |
310 | CvUNIQUE_on(PL_compcv); |
28757baa |
311 | $$ = $1; } |
a0d0e21e |
312 | ; |
313 | |
4633a7c4 |
314 | proto : /* NULL */ |
315 | { $$ = Nullop; } |
316 | | THING |
317 | ; |
28757baa |
318 | |
319 | subbody : block { $$ = $1; } |
3280af22 |
320 | | ';' { $$ = Nullop; PL_expect = XSTATE; } |
8d063cd8 |
321 | ; |
322 | |
a687059c |
323 | package : PACKAGE WORD ';' |
79072805 |
324 | { package($2); } |
93a17b20 |
325 | | PACKAGE ';' |
326 | { package(Nullop); } |
a687059c |
327 | ; |
328 | |
28757baa |
329 | use : USE startsub |
3280af22 |
330 | { CvUNIQUE_on(PL_compcv); /* It's a BEGIN {} */ } |
28757baa |
331 | WORD WORD listexpr ';' |
332 | { utilize($1, $2, $4, $5, $6); } |
85e6fe83 |
333 | ; |
334 | |
a0d0e21e |
335 | expr : expr ANDOP expr |
336 | { $$ = newLOGOP(OP_AND, 0, $1, $3); } |
337 | | expr OROP expr |
338 | { $$ = newLOGOP($2, 0, $1, $3); } |
a0d0e21e |
339 | | argexpr |
340 | ; |
341 | |
342 | argexpr : argexpr ',' |
343 | { $$ = $1; } |
344 | | argexpr ',' term |
79072805 |
345 | { $$ = append_elem(OP_LIST, $1, $3); } |
a0d0e21e |
346 | | term |
8d063cd8 |
347 | ; |
348 | |
a0d0e21e |
349 | listop : LSTOP indirob argexpr |
79072805 |
350 | { $$ = convert($1, OPf_STACKED, |
a0d0e21e |
351 | prepend_elem(OP_LIST, newGVREF($1,$2), $3) ); } |
352 | | FUNC '(' indirob expr ')' |
79072805 |
353 | { $$ = convert($1, OPf_STACKED, |
a0d0e21e |
354 | prepend_elem(OP_LIST, newGVREF($1,$3), $4) ); } |
355 | | term ARROW method '(' listexprcom ')' |
4633a7c4 |
356 | { $$ = convert(OP_ENTERSUB, OPf_STACKED, |
a0d0e21e |
357 | append_elem(OP_LIST, |
55497cff |
358 | prepend_elem(OP_LIST, scalar($1), $5), |
a0d0e21e |
359 | newUNOP(OP_METHOD, 0, $3))); } |
79072805 |
360 | | METHOD indirob listexpr |
4633a7c4 |
361 | { $$ = convert(OP_ENTERSUB, OPf_STACKED, |
a0d0e21e |
362 | append_elem(OP_LIST, |
4633a7c4 |
363 | prepend_elem(OP_LIST, $2, $3), |
a0d0e21e |
364 | newUNOP(OP_METHOD, 0, $1))); } |
365 | | FUNCMETH indirob '(' listexprcom ')' |
4633a7c4 |
366 | { $$ = convert(OP_ENTERSUB, OPf_STACKED, |
a0d0e21e |
367 | append_elem(OP_LIST, |
4633a7c4 |
368 | prepend_elem(OP_LIST, $2, $4), |
a0d0e21e |
369 | newUNOP(OP_METHOD, 0, $1))); } |
79072805 |
370 | | LSTOP listexpr |
371 | { $$ = convert($1, 0, $2); } |
a0d0e21e |
372 | | FUNC '(' listexprcom ')' |
79072805 |
373 | { $$ = convert($1, 0, $3); } |
28757baa |
374 | | LSTOPSUB startanonsub block |
375 | { $3 = newANONSUB($2, 0, $3); } |
376 | listexpr %prec LSTOP |
4633a7c4 |
377 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
28757baa |
378 | append_elem(OP_LIST, |
379 | prepend_elem(OP_LIST, $3, $5), $1)); } |
a687059c |
380 | ; |
381 | |
a0d0e21e |
382 | method : METHOD |
383 | | scalar |
384 | ; |
385 | |
386 | term : term ASSIGNOP term |
387 | { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); } |
388 | | term POWOP term |
79072805 |
389 | { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } |
a0d0e21e |
390 | | term MULOP term |
79072805 |
391 | { if ($2 != OP_REPEAT) |
392 | scalar($1); |
393 | $$ = newBINOP($2, 0, $1, scalar($3)); } |
a0d0e21e |
394 | | term ADDOP term |
79072805 |
395 | { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } |
a0d0e21e |
396 | | term SHIFTOP term |
79072805 |
397 | { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } |
a0d0e21e |
398 | | term RELOP term |
79072805 |
399 | { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } |
a0d0e21e |
400 | | term EQOP term |
79072805 |
401 | { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } |
a0d0e21e |
402 | | term BITANDOP term |
79072805 |
403 | { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } |
a0d0e21e |
404 | | term BITOROP term |
79072805 |
405 | { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } |
a0d0e21e |
406 | | term DOTDOT term |
79072805 |
407 | { $$ = newRANGE($2, scalar($1), scalar($3));} |
a0d0e21e |
408 | | term ANDAND term |
463ee0b2 |
409 | { $$ = newLOGOP(OP_AND, 0, $1, $3); } |
a0d0e21e |
410 | | term OROR term |
463ee0b2 |
411 | { $$ = newLOGOP(OP_OR, 0, $1, $3); } |
a0d0e21e |
412 | | term '?' term ':' term |
79072805 |
413 | { $$ = newCONDOP(0, $1, $3, $5); } |
a0d0e21e |
414 | | term MATCHOP term |
79072805 |
415 | { $$ = bind_match($2, $1, $3); } |
8d063cd8 |
416 | |
a0d0e21e |
417 | | '-' term %prec UMINUS |
79072805 |
418 | { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); } |
a687059c |
419 | | '+' term %prec UMINUS |
420 | { $$ = $2; } |
8d063cd8 |
421 | | '!' term |
79072805 |
422 | { $$ = newUNOP(OP_NOT, 0, scalar($2)); } |
8d063cd8 |
423 | | '~' term |
79072805 |
424 | { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2));} |
425 | | REFGEN term |
a0d0e21e |
426 | { $$ = newUNOP(OP_REFGEN, 0, mod($2,OP_REFGEN)); } |
79072805 |
427 | | term POSTINC |
428 | { $$ = newUNOP(OP_POSTINC, 0, |
463ee0b2 |
429 | mod(scalar($1), OP_POSTINC)); } |
79072805 |
430 | | term POSTDEC |
431 | { $$ = newUNOP(OP_POSTDEC, 0, |
463ee0b2 |
432 | mod(scalar($1), OP_POSTDEC)); } |
79072805 |
433 | | PREINC term |
434 | { $$ = newUNOP(OP_PREINC, 0, |
463ee0b2 |
435 | mod(scalar($2), OP_PREINC)); } |
79072805 |
436 | | PREDEC term |
437 | { $$ = newUNOP(OP_PREDEC, 0, |
463ee0b2 |
438 | mod(scalar($2), OP_PREDEC)); } |
55497cff |
439 | | local term %prec UNIOP |
93a17b20 |
440 | { $$ = localize($2,$1); } |
a0d0e21e |
441 | | '(' expr ')' |
79072805 |
442 | { $$ = sawparens($2); } |
8d063cd8 |
443 | | '(' ')' |
8990e307 |
444 | { $$ = sawparens(newNULLLIST()); } |
a0d0e21e |
445 | | '[' expr ']' %prec '(' |
79072805 |
446 | { $$ = newANONLIST($2); } |
447 | | '[' ']' %prec '(' |
448 | { $$ = newANONLIST(Nullop); } |
a0d0e21e |
449 | | HASHBRACK expr ';' '}' %prec '(' |
79072805 |
450 | { $$ = newANONHASH($2); } |
451 | | HASHBRACK ';' '}' %prec '(' |
452 | { $$ = newANONHASH(Nullop); } |
28757baa |
453 | | ANONSUB startanonsub proto block %prec '(' |
4633a7c4 |
454 | { $$ = newANONSUB($2, $3, $4); } |
79072805 |
455 | | scalar %prec '(' |
8d063cd8 |
456 | { $$ = $1; } |
c07a80fd |
457 | | star '{' expr ';' '}' |
640b9ef6 |
458 | { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); } |
79072805 |
459 | | star %prec '(' |
8d063cd8 |
460 | { $$ = $1; } |
79072805 |
461 | | scalar '[' expr ']' %prec '(' |
462 | { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); } |
463 | | term ARROW '[' expr ']' %prec '(' |
464 | { $$ = newBINOP(OP_AELEM, 0, |
8990e307 |
465 | ref(newAVREF($1),OP_RV2AV), |
79072805 |
466 | scalar($4));} |
463ee0b2 |
467 | | term '[' expr ']' %prec '(' |
a0d0e21e |
468 | { assertref($1); $$ = newBINOP(OP_AELEM, 0, |
8990e307 |
469 | ref(newAVREF($1),OP_RV2AV), |
463ee0b2 |
470 | scalar($3));} |
79072805 |
471 | | hsh %prec '(' |
8d063cd8 |
472 | { $$ = $1; } |
79072805 |
473 | | ary %prec '(' |
8d063cd8 |
474 | { $$ = $1; } |
79072805 |
475 | | arylen %prec '(' |
476 | { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));} |
477 | | scalar '{' expr ';' '}' %prec '(' |
478 | { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3)); |
3280af22 |
479 | PL_expect = XOPERATOR; } |
79072805 |
480 | | term ARROW '{' expr ';' '}' %prec '(' |
481 | { $$ = newBINOP(OP_HELEM, 0, |
8990e307 |
482 | ref(newHVREF($1),OP_RV2HV), |
79072805 |
483 | jmaybe($4)); |
3280af22 |
484 | PL_expect = XOPERATOR; } |
463ee0b2 |
485 | | term '{' expr ';' '}' %prec '(' |
a0d0e21e |
486 | { assertref($1); $$ = newBINOP(OP_HELEM, 0, |
8990e307 |
487 | ref(newHVREF($1),OP_RV2HV), |
463ee0b2 |
488 | jmaybe($3)); |
3280af22 |
489 | PL_expect = XOPERATOR; } |
a0d0e21e |
490 | | '(' expr ')' '[' expr ']' %prec '(' |
79072805 |
491 | { $$ = newSLICEOP(0, $5, $2); } |
492 | | '(' ')' '[' expr ']' %prec '(' |
493 | { $$ = newSLICEOP(0, $4, Nullop); } |
494 | | ary '[' expr ']' %prec '(' |
495 | { $$ = prepend_elem(OP_ASLICE, |
496 | newOP(OP_PUSHMARK, 0), |
79072805 |
497 | newLISTOP(OP_ASLICE, 0, |
498 | list($3), |
a0d0e21e |
499 | ref($1, OP_ASLICE))); } |
79072805 |
500 | | ary '{' expr ';' '}' %prec '(' |
501 | { $$ = prepend_elem(OP_HSLICE, |
502 | newOP(OP_PUSHMARK, 0), |
79072805 |
503 | newLISTOP(OP_HSLICE, 0, |
504 | list($3), |
a0d0e21e |
505 | ref(oopsHV($1), OP_HSLICE))); |
3280af22 |
506 | PL_expect = XOPERATOR; } |
79072805 |
507 | | THING %prec '(' |
508 | { $$ = $1; } |
509 | | amper |
c07a80fd |
510 | { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); } |
79072805 |
511 | | amper '(' ')' |
a0d0e21e |
512 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); } |
513 | | amper '(' expr ')' |
514 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
4633a7c4 |
515 | append_elem(OP_LIST, $3, scalar($1))); } |
93a17b20 |
516 | | NOAMP WORD listexpr |
a0d0e21e |
517 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
a5f75d66 |
518 | append_elem(OP_LIST, $3, scalar($2))); } |
a0d0e21e |
519 | | DO term %prec UNIOP |
78ca652e |
520 | { $$ = dofile($2); } |
79072805 |
521 | | DO block %prec '(' |
522 | { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2)); } |
8d063cd8 |
523 | | DO WORD '(' ')' |
c07a80fd |
524 | { $$ = newUNOP(OP_ENTERSUB, |
525 | OPf_SPECIAL|OPf_STACKED, |
4633a7c4 |
526 | prepend_elem(OP_LIST, |
c07a80fd |
527 | scalar(newCVREF( |
528 | (OPpENTERSUB_AMPER<<8), |
529 | scalar($2) |
530 | )),Nullop)); dep();} |
a0d0e21e |
531 | | DO WORD '(' expr ')' |
c07a80fd |
532 | { $$ = newUNOP(OP_ENTERSUB, |
533 | OPf_SPECIAL|OPf_STACKED, |
4633a7c4 |
534 | append_elem(OP_LIST, |
a0d0e21e |
535 | $4, |
c07a80fd |
536 | scalar(newCVREF( |
537 | (OPpENTERSUB_AMPER<<8), |
538 | scalar($2) |
539 | )))); dep();} |
79072805 |
540 | | DO scalar '(' ')' |
a0d0e21e |
541 | { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED, |
4633a7c4 |
542 | prepend_elem(OP_LIST, |
c07a80fd |
543 | scalar(newCVREF(0,scalar($2))), Nullop)); dep();} |
a0d0e21e |
544 | | DO scalar '(' expr ')' |
545 | { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED, |
4633a7c4 |
546 | prepend_elem(OP_LIST, |
a0d0e21e |
547 | $4, |
c07a80fd |
548 | scalar(newCVREF(0,scalar($2))))); dep();} |
6da72b64 |
549 | | term ARROW '(' ')' %prec '(' |
550 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
551 | newCVREF(0, scalar($1))); } |
552 | | term ARROW '(' expr ')' %prec '(' |
553 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
554 | append_elem(OP_LIST, $4, |
555 | newCVREF(0, scalar($1)))); } |
8d063cd8 |
556 | | LOOPEX |
85e6fe83 |
557 | { $$ = newOP($1, OPf_SPECIAL); |
3280af22 |
558 | PL_hints |= HINT_BLOCK_SCOPE; } |
a0d0e21e |
559 | | LOOPEX term |
8990e307 |
560 | { $$ = newLOOPEX($1,$2); } |
c07a80fd |
561 | | NOTOP argexpr |
562 | { $$ = newUNOP(OP_NOT, 0, scalar($2)); } |
8d063cd8 |
563 | | UNIOP |
79072805 |
564 | { $$ = newOP($1, 0); } |
f0fcb552 |
565 | | UNIOP block |
79072805 |
566 | { $$ = newUNOP($1, 0, $2); } |
a0d0e21e |
567 | | UNIOP term |
79072805 |
568 | { $$ = newUNOP($1, 0, $2); } |
4633a7c4 |
569 | | UNIOPSUB term |
570 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
571 | append_elem(OP_LIST, $2, scalar($1))); } |
8d063cd8 |
572 | | FUNC0 |
79072805 |
573 | { $$ = newOP($1, 0); } |
ae986130 |
574 | | FUNC0 '(' ')' |
79072805 |
575 | { $$ = newOP($1, 0); } |
4633a7c4 |
576 | | FUNC0SUB |
28757baa |
577 | { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, |
4633a7c4 |
578 | scalar($1)); } |
03a14243 |
579 | | FUNC1 '(' ')' |
79072805 |
580 | { $$ = newOP($1, OPf_SPECIAL); } |
8d063cd8 |
581 | | FUNC1 '(' expr ')' |
79072805 |
582 | { $$ = newUNOP($1, 0, $3); } |
a0d0e21e |
583 | | PMFUNC '(' term ')' |
79072805 |
584 | { $$ = pmruntime($1, $3, Nullop); } |
a0d0e21e |
585 | | PMFUNC '(' term ',' term ')' |
79072805 |
586 | { $$ = pmruntime($1, $3, $5); } |
587 | | WORD |
378cc40b |
588 | | listop |
8d063cd8 |
589 | ; |
590 | |
79072805 |
591 | listexpr: /* NULL */ |
8990e307 |
592 | { $$ = Nullop; } |
a0d0e21e |
593 | | argexpr |
594 | { $$ = $1; } |
595 | ; |
596 | |
597 | listexprcom: /* NULL */ |
598 | { $$ = Nullop; } |
79072805 |
599 | | expr |
600 | { $$ = $1; } |
a0d0e21e |
601 | | expr ',' |
602 | { $$ = $1; } |
79072805 |
603 | ; |
604 | |
55497cff |
605 | local : LOCAL { $$ = 0; } |
606 | | MY { $$ = 1; } |
607 | ; |
608 | |
609 | my_scalar: scalar |
3280af22 |
610 | { PL_in_my = 0; $$ = my($1); } |
55497cff |
611 | ; |
612 | |
79072805 |
613 | amper : '&' indirob |
c07a80fd |
614 | { $$ = newCVREF($1,$2); } |
a687059c |
615 | ; |
616 | |
79072805 |
617 | scalar : '$' indirob |
618 | { $$ = newSVREF($2); } |
a687059c |
619 | ; |
620 | |
79072805 |
621 | ary : '@' indirob |
622 | { $$ = newAVREF($2); } |
623 | ; |
624 | |
625 | hsh : '%' indirob |
626 | { $$ = newHVREF($2); } |
627 | ; |
628 | |
629 | arylen : DOLSHARP indirob |
630 | { $$ = newAVREF($2); } |
631 | ; |
632 | |
633 | star : '*' indirob |
a0d0e21e |
634 | { $$ = newGVREF(0,$2); } |
79072805 |
635 | ; |
636 | |
637 | indirob : WORD |
638 | { $$ = scalar($1); } |
639 | | scalar |
463ee0b2 |
640 | { $$ = scalar($1); } |
79072805 |
641 | | block |
a0d0e21e |
642 | { $$ = scope($1); } |
79072805 |
643 | |
93a17b20 |
644 | | PRIVATEREF |
645 | { $$ = $1; } |
8d063cd8 |
646 | ; |
647 | |
648 | %% /* PROGRAM */ |