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