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