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