Mercurial > hg > Members > anatofuz > test_perl1_alpine
comparison perl.y @ 0:0240ed5457bb
init
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 13 Jun 2019 18:56:19 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0240ed5457bb |
---|---|
1 /* $Header: perl.y,v 1.0.1.4 88/03/02 12:37:25 root Exp $ | |
2 * | |
3 * $Log: perl.y,v $ | |
4 * Revision 1.0.1.4 88/03/02 12:37:25 root | |
5 * patch24: made stab_to_* unique in 7 chars | |
6 * patch24: added file tests | |
7 * patch24: added line numbers for runtime errors | |
8 * | |
9 * Revision 1.0.1.3 88/02/25 11:45:20 root | |
10 * patch23: label on null statement can cause core dump. | |
11 * | |
12 * Revision 1.0.1.2 88/02/04 11:17:12 root | |
13 * patch18: regularized includes. | |
14 * | |
15 * Revision 1.0.1.1 88/01/28 10:25:31 root | |
16 * patch8: added eval operator. | |
17 * | |
18 * Revision 1.0 87/12/18 15:48:59 root | |
19 * Initial revision | |
20 * | |
21 */ | |
22 | |
23 %{ | |
24 #include "INTERN.h" | |
25 #include "perl.h" | |
26 | |
27 char *tokename[] = { | |
28 "256", | |
29 "word", | |
30 "append","open","write","select","close","loopctl", | |
31 "using","format","do","shift","push","pop","chop", | |
32 "while","until","if","unless","else","elsif","continue","split","sprintf", | |
33 "for", "eof", "tell", "seek", "stat", | |
34 "function(no args)","function(1 arg)","function(2 args)","function(3 args)","array function", | |
35 "join", "sub", "file test", | |
36 "format lines", | |
37 "register","array_length", "array", | |
38 "s","pattern", | |
39 "string","y", | |
40 "print", "unary operation", | |
41 "..", | |
42 "||", | |
43 "&&", | |
44 "==","!=", "EQ", "NE", | |
45 "<=",">=", "LT", "GT", "LE", "GE", | |
46 "<<",">>", | |
47 "=~","!~", | |
48 "unary -", | |
49 "++", "--", | |
50 "???" | |
51 }; | |
52 | |
53 %} | |
54 | |
55 %start prog | |
56 | |
57 %union { | |
58 int ival; | |
59 char *cval; | |
60 ARG *arg; | |
61 CMD *cmdval; | |
62 struct compcmd compval; | |
63 STAB *stabval; | |
64 FCMD *formval; | |
65 } | |
66 | |
67 %token <cval> WORD | |
68 %token <ival> APPEND OPEN WRITE SELECT CLOSE LOOPEX | |
69 %token <ival> USING FORMAT DO SHIFT PUSH POP CHOP | |
70 %token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE SPLIT SPRINTF | |
71 %token <ival> FOR FEOF TELL SEEK STAT | |
72 %token <ival> FUNC0 FUNC1 FUNC2 FUNC3 STABFUN | |
73 %token <ival> JOIN SUB FILETEST | |
74 %token <formval> FORMLIST | |
75 %token <stabval> REG ARYLEN ARY | |
76 %token <arg> SUBST PATTERN | |
77 %token <arg> RSTRING TRANS | |
78 | |
79 %type <ival> prog decl format | |
80 %type <cmdval> block lineseq line loop cond sideff nexpr else | |
81 %type <arg> expr sexpr term | |
82 %type <arg> condmod loopmod cexpr | |
83 %type <arg> texpr print | |
84 %type <cval> label | |
85 %type <compval> compblock | |
86 | |
87 %nonassoc <ival> PRINT | |
88 %left ',' | |
89 %nonassoc <ival> UNIOP | |
90 %right '=' | |
91 %right '?' ':' | |
92 %nonassoc DOTDOT | |
93 %left OROR | |
94 %left ANDAND | |
95 %left '|' '^' | |
96 %left '&' | |
97 %nonassoc EQ NE SEQ SNE | |
98 %nonassoc '<' '>' LE GE SLT SGT SLE SGE | |
99 %nonassoc FILETEST | |
100 %left LS RS | |
101 %left '+' '-' '.' | |
102 %left '*' '/' '%' 'x' | |
103 %left MATCH NMATCH | |
104 %right '!' '~' UMINUS | |
105 %nonassoc INC DEC | |
106 %left '(' | |
107 | |
108 %% /* RULES */ | |
109 | |
110 prog : lineseq | |
111 { if (in_eval) | |
112 eval_root = block_head($1); | |
113 else | |
114 main_root = block_head($1); } | |
115 ; | |
116 | |
117 compblock: block CONTINUE block | |
118 { $$.comp_true = $1; $$.comp_alt = $3; } | |
119 | block else | |
120 { $$.comp_true = $1; $$.comp_alt = $2; } | |
121 ; | |
122 | |
123 else : /* NULL */ | |
124 { $$ = Nullcmd; } | |
125 | ELSE block | |
126 { $$ = $2; } | |
127 | ELSIF '(' expr ')' compblock | |
128 { cmdline = $1; | |
129 $$ = make_ccmd(C_IF,$3,$5); } | |
130 ; | |
131 | |
132 block : '{' lineseq '}' | |
133 { $$ = block_head($2); } | |
134 ; | |
135 | |
136 lineseq : /* NULL */ | |
137 { $$ = Nullcmd; } | |
138 | lineseq line | |
139 { $$ = append_line($1,$2); } | |
140 ; | |
141 | |
142 line : decl | |
143 { $$ = Nullcmd; } | |
144 | label cond | |
145 { $$ = add_label($1,$2); } | |
146 | loop /* loops add their own labels */ | |
147 | label ';' | |
148 { if ($1 != Nullch) { | |
149 $$ = add_label($1, make_acmd(C_EXPR, Nullstab, | |
150 Nullarg, Nullarg) ); | |
151 } else | |
152 $$ = Nullcmd; } | |
153 | label sideff ';' | |
154 { $$ = add_label($1,$2); } | |
155 ; | |
156 | |
157 sideff : expr | |
158 { $$ = make_acmd(C_EXPR, Nullstab, $1, Nullarg); } | |
159 | expr condmod | |
160 { $$ = addcond( | |
161 make_acmd(C_EXPR, Nullstab, Nullarg, $1), $2); } | |
162 | expr loopmod | |
163 { $$ = addloop( | |
164 make_acmd(C_EXPR, Nullstab, Nullarg, $1), $2); } | |
165 ; | |
166 | |
167 cond : IF '(' expr ')' compblock | |
168 { cmdline = $1; | |
169 $$ = make_ccmd(C_IF,$3,$5); } | |
170 | UNLESS '(' expr ')' compblock | |
171 { cmdline = $1; | |
172 $$ = invert(make_ccmd(C_IF,$3,$5)); } | |
173 | IF block compblock | |
174 { cmdline = $1; | |
175 $$ = make_ccmd(C_IF,cmd_to_arg($2),$3); } | |
176 | UNLESS block compblock | |
177 { cmdline = $1; | |
178 $$ = invert(make_ccmd(C_IF,cmd_to_arg($2),$3)); } | |
179 ; | |
180 | |
181 loop : label WHILE '(' texpr ')' compblock | |
182 { cmdline = $2; | |
183 $$ = wopt(add_label($1, | |
184 make_ccmd(C_WHILE,$4,$6) )); } | |
185 | label UNTIL '(' expr ')' compblock | |
186 { cmdline = $2; | |
187 $$ = wopt(add_label($1, | |
188 invert(make_ccmd(C_WHILE,$4,$6)) )); } | |
189 | label WHILE block compblock | |
190 { cmdline = $2; | |
191 $$ = wopt(add_label($1, | |
192 make_ccmd(C_WHILE, cmd_to_arg($3),$4) )); } | |
193 | label UNTIL block compblock | |
194 { cmdline = $2; | |
195 $$ = wopt(add_label($1, | |
196 invert(make_ccmd(C_WHILE, cmd_to_arg($3),$4)) )); } | |
197 | label FOR '(' nexpr ';' texpr ';' nexpr ')' block | |
198 /* basically fake up an initialize-while lineseq */ | |
199 { yyval.compval.comp_true = $10; | |
200 yyval.compval.comp_alt = $8; | |
201 cmdline = $2; | |
202 $$ = append_line($4,wopt(add_label($1, | |
203 make_ccmd(C_WHILE,$6,yyval.compval) ))); } | |
204 | label compblock /* a block is a loop that happens once */ | |
205 { $$ = add_label($1,make_ccmd(C_BLOCK,Nullarg,$2)); } | |
206 ; | |
207 | |
208 nexpr : /* NULL */ | |
209 { $$ = Nullcmd; } | |
210 | sideff | |
211 ; | |
212 | |
213 texpr : /* NULL means true */ | |
214 { scanstr("1"); $$ = yylval.arg; } | |
215 | expr | |
216 ; | |
217 | |
218 label : /* empty */ | |
219 { $$ = Nullch; } | |
220 | WORD ':' | |
221 ; | |
222 | |
223 loopmod : WHILE expr | |
224 { $$ = $2; } | |
225 | UNTIL expr | |
226 { $$ = make_op(O_NOT,1,$2,Nullarg,Nullarg,0); } | |
227 ; | |
228 | |
229 condmod : IF expr | |
230 { $$ = $2; } | |
231 | UNLESS expr | |
232 { $$ = make_op(O_NOT,1,$2,Nullarg,Nullarg,0); } | |
233 ; | |
234 | |
235 decl : format | |
236 { $$ = 0; } | |
237 | subrout | |
238 { $$ = 0; } | |
239 ; | |
240 | |
241 format : FORMAT WORD '=' FORMLIST '.' | |
242 { stabent($2,TRUE)->stab_form = $4; safefree($2); } | |
243 | FORMAT '=' FORMLIST '.' | |
244 { stabent("stdout",TRUE)->stab_form = $3; } | |
245 ; | |
246 | |
247 subrout : SUB WORD block | |
248 { stabent($2,TRUE)->stab_sub = $3; } | |
249 ; | |
250 | |
251 expr : print | |
252 | cexpr | |
253 ; | |
254 | |
255 cexpr : sexpr ',' cexpr | |
256 { $$ = make_op(O_COMMA, 2, $1, $3, Nullarg,0); } | |
257 | sexpr | |
258 ; | |
259 | |
260 sexpr : sexpr '=' sexpr | |
261 { $1 = listish($1); | |
262 if ($1->arg_type == O_LIST) | |
263 $3 = listish($3); | |
264 $$ = l(make_op(O_ASSIGN, 2, $1, $3, Nullarg,1)); } | |
265 | sexpr '*' '=' sexpr | |
266 { $$ = l(make_op(O_MULTIPLY, 2, $1, $4, Nullarg,0)); } | |
267 | sexpr '/' '=' sexpr | |
268 { $$ = l(make_op(O_DIVIDE, 2, $1, $4, Nullarg,0)); } | |
269 | sexpr '%' '=' sexpr | |
270 { $$ = l(make_op(O_MODULO, 2, $1, $4, Nullarg,0)); } | |
271 | sexpr 'x' '=' sexpr | |
272 { $$ = l(make_op(O_REPEAT, 2, $1, $4, Nullarg,0)); } | |
273 | sexpr '+' '=' sexpr | |
274 { $$ = l(make_op(O_ADD, 2, $1, $4, Nullarg,0)); } | |
275 | sexpr '-' '=' sexpr | |
276 { $$ = l(make_op(O_SUBTRACT, 2, $1, $4, Nullarg,0)); } | |
277 | sexpr LS '=' sexpr | |
278 { $$ = l(make_op(O_LEFT_SHIFT, 2, $1, $4, Nullarg,0)); } | |
279 | sexpr RS '=' sexpr | |
280 { $$ = l(make_op(O_RIGHT_SHIFT, 2, $1, $4, Nullarg,0)); } | |
281 | sexpr '&' '=' sexpr | |
282 { $$ = l(make_op(O_BIT_AND, 2, $1, $4, Nullarg,0)); } | |
283 | sexpr '^' '=' sexpr | |
284 { $$ = l(make_op(O_XOR, 2, $1, $4, Nullarg,0)); } | |
285 | sexpr '|' '=' sexpr | |
286 { $$ = l(make_op(O_BIT_OR, 2, $1, $4, Nullarg,0)); } | |
287 | sexpr '.' '=' sexpr | |
288 { $$ = l(make_op(O_CONCAT, 2, $1, $4, Nullarg,0)); } | |
289 | |
290 | |
291 | sexpr '*' sexpr | |
292 { $$ = make_op(O_MULTIPLY, 2, $1, $3, Nullarg,0); } | |
293 | sexpr '/' sexpr | |
294 { $$ = make_op(O_DIVIDE, 2, $1, $3, Nullarg,0); } | |
295 | sexpr '%' sexpr | |
296 { $$ = make_op(O_MODULO, 2, $1, $3, Nullarg,0); } | |
297 | sexpr 'x' sexpr | |
298 { $$ = make_op(O_REPEAT, 2, $1, $3, Nullarg,0); } | |
299 | sexpr '+' sexpr | |
300 { $$ = make_op(O_ADD, 2, $1, $3, Nullarg,0); } | |
301 | sexpr '-' sexpr | |
302 { $$ = make_op(O_SUBTRACT, 2, $1, $3, Nullarg,0); } | |
303 | sexpr LS sexpr | |
304 { $$ = make_op(O_LEFT_SHIFT, 2, $1, $3, Nullarg,0); } | |
305 | sexpr RS sexpr | |
306 { $$ = make_op(O_RIGHT_SHIFT, 2, $1, $3, Nullarg,0); } | |
307 | sexpr '<' sexpr | |
308 { $$ = make_op(O_LT, 2, $1, $3, Nullarg,0); } | |
309 | sexpr '>' sexpr | |
310 { $$ = make_op(O_GT, 2, $1, $3, Nullarg,0); } | |
311 | sexpr LE sexpr | |
312 { $$ = make_op(O_LE, 2, $1, $3, Nullarg,0); } | |
313 | sexpr GE sexpr | |
314 { $$ = make_op(O_GE, 2, $1, $3, Nullarg,0); } | |
315 | sexpr EQ sexpr | |
316 { $$ = make_op(O_EQ, 2, $1, $3, Nullarg,0); } | |
317 | sexpr NE sexpr | |
318 { $$ = make_op(O_NE, 2, $1, $3, Nullarg,0); } | |
319 | sexpr SLT sexpr | |
320 { $$ = make_op(O_SLT, 2, $1, $3, Nullarg,0); } | |
321 | sexpr SGT sexpr | |
322 { $$ = make_op(O_SGT, 2, $1, $3, Nullarg,0); } | |
323 | sexpr SLE sexpr | |
324 { $$ = make_op(O_SLE, 2, $1, $3, Nullarg,0); } | |
325 | sexpr SGE sexpr | |
326 { $$ = make_op(O_SGE, 2, $1, $3, Nullarg,0); } | |
327 | sexpr SEQ sexpr | |
328 { $$ = make_op(O_SEQ, 2, $1, $3, Nullarg,0); } | |
329 | sexpr SNE sexpr | |
330 { $$ = make_op(O_SNE, 2, $1, $3, Nullarg,0); } | |
331 | sexpr '&' sexpr | |
332 { $$ = make_op(O_BIT_AND, 2, $1, $3, Nullarg,0); } | |
333 | sexpr '^' sexpr | |
334 { $$ = make_op(O_XOR, 2, $1, $3, Nullarg,0); } | |
335 | sexpr '|' sexpr | |
336 { $$ = make_op(O_BIT_OR, 2, $1, $3, Nullarg,0); } | |
337 | sexpr DOTDOT sexpr | |
338 { $$ = make_op(O_FLIP, 4, | |
339 flipflip($1), | |
340 flipflip($3), | |
341 Nullarg,0);} | |
342 | sexpr ANDAND sexpr | |
343 { $$ = make_op(O_AND, 2, $1, $3, Nullarg,0); } | |
344 | sexpr OROR sexpr | |
345 { $$ = make_op(O_OR, 2, $1, $3, Nullarg,0); } | |
346 | sexpr '?' sexpr ':' sexpr | |
347 { $$ = make_op(O_COND_EXPR, 3, $1, $3, $5,0); } | |
348 | sexpr '.' sexpr | |
349 { $$ = make_op(O_CONCAT, 2, $1, $3, Nullarg,0); } | |
350 | sexpr MATCH sexpr | |
351 { $$ = mod_match(O_MATCH, $1, $3); } | |
352 | sexpr NMATCH sexpr | |
353 { $$ = mod_match(O_NMATCH, $1, $3); } | |
354 | term INC | |
355 { $$ = addflags(1, AF_POST|AF_UP, | |
356 l(make_op(O_ITEM,1,$1,Nullarg,Nullarg,0))); } | |
357 | term DEC | |
358 { $$ = addflags(1, AF_POST, | |
359 l(make_op(O_ITEM,1,$1,Nullarg,Nullarg,0))); } | |
360 | INC term | |
361 { $$ = addflags(1, AF_PRE|AF_UP, | |
362 l(make_op(O_ITEM,1,$2,Nullarg,Nullarg,0))); } | |
363 | DEC term | |
364 { $$ = addflags(1, AF_PRE, | |
365 l(make_op(O_ITEM,1,$2,Nullarg,Nullarg,0))); } | |
366 | term | |
367 { $$ = $1; } | |
368 ; | |
369 | |
370 term : '-' term %prec UMINUS | |
371 { $$ = make_op(O_NEGATE, 1, $2, Nullarg, Nullarg,0); } | |
372 | '!' term | |
373 { $$ = make_op(O_NOT, 1, $2, Nullarg, Nullarg,0); } | |
374 | '~' term | |
375 { $$ = make_op(O_COMPLEMENT, 1, $2, Nullarg, Nullarg,0);} | |
376 | FILETEST sexpr | |
377 { $$ = make_op($1, 1, $2, Nullarg, Nullarg,0); } | |
378 | '(' expr ')' | |
379 { $$ = make_list(hide_ary($2)); } | |
380 | '(' ')' | |
381 { $$ = make_list(Nullarg); } | |
382 | DO block %prec '(' | |
383 { $$ = cmd_to_arg($2); } | |
384 | REG %prec '(' | |
385 { $$ = stab2arg(A_STAB,$1); } | |
386 | REG '[' expr ']' %prec '(' | |
387 { $$ = make_op(O_ARRAY, 2, | |
388 $3, stab2arg(A_STAB,aadd($1)), Nullarg,0); } | |
389 | ARY %prec '(' | |
390 { $$ = make_op(O_ARRAY, 1, | |
391 stab2arg(A_STAB,$1), | |
392 Nullarg, Nullarg, 1); } | |
393 | REG '{' expr '}' %prec '(' | |
394 { $$ = make_op(O_HASH, 2, | |
395 $3, stab2arg(A_STAB,hadd($1)), Nullarg,0); } | |
396 | ARYLEN %prec '(' | |
397 { $$ = stab2arg(A_ARYLEN,$1); } | |
398 | RSTRING %prec '(' | |
399 { $$ = $1; } | |
400 | PATTERN %prec '(' | |
401 { $$ = $1; } | |
402 | SUBST %prec '(' | |
403 { $$ = $1; } | |
404 | TRANS %prec '(' | |
405 { $$ = $1; } | |
406 | DO WORD '(' expr ')' | |
407 { $$ = make_op(O_SUBR, 2, | |
408 make_list($4), | |
409 stab2arg(A_STAB,stabent($2,TRUE)), | |
410 Nullarg,1); } | |
411 | DO WORD '(' ')' | |
412 { $$ = make_op(O_SUBR, 2, | |
413 make_list(Nullarg), | |
414 stab2arg(A_STAB,stabent($2,TRUE)), | |
415 Nullarg,1); } | |
416 | LOOPEX | |
417 { $$ = make_op($1,0,Nullarg,Nullarg,Nullarg,0); } | |
418 | LOOPEX WORD | |
419 { $$ = make_op($1,1,cval_to_arg($2), | |
420 Nullarg,Nullarg,0); } | |
421 | UNIOP | |
422 { $$ = make_op($1,1,Nullarg,Nullarg,Nullarg,0); } | |
423 | UNIOP sexpr | |
424 { $$ = make_op($1,1,$2,Nullarg,Nullarg,0); } | |
425 | WRITE | |
426 { $$ = make_op(O_WRITE, 0, | |
427 Nullarg, Nullarg, Nullarg,0); } | |
428 | WRITE '(' ')' | |
429 { $$ = make_op(O_WRITE, 0, | |
430 Nullarg, Nullarg, Nullarg,0); } | |
431 | WRITE '(' WORD ')' | |
432 { $$ = l(make_op(O_WRITE, 1, | |
433 stab2arg(A_STAB,stabent($3,TRUE)), | |
434 Nullarg, Nullarg,0)); safefree($3); } | |
435 | WRITE '(' expr ')' | |
436 { $$ = make_op(O_WRITE, 1, $3, Nullarg, Nullarg,0); } | |
437 | SELECT '(' WORD ')' | |
438 { $$ = l(make_op(O_SELECT, 1, | |
439 stab2arg(A_STAB,stabent($3,TRUE)), | |
440 Nullarg, Nullarg,0)); safefree($3); } | |
441 | SELECT '(' expr ')' | |
442 { $$ = make_op(O_SELECT, 1, $3, Nullarg, Nullarg,0); } | |
443 | OPEN WORD %prec '(' | |
444 { $$ = make_op(O_OPEN, 2, | |
445 stab2arg(A_STAB,stabent($2,TRUE)), | |
446 stab2arg(A_STAB,stabent($2,TRUE)), | |
447 Nullarg,0); } | |
448 | OPEN '(' WORD ')' | |
449 { $$ = make_op(O_OPEN, 2, | |
450 stab2arg(A_STAB,stabent($3,TRUE)), | |
451 stab2arg(A_STAB,stabent($3,TRUE)), | |
452 Nullarg,0); } | |
453 | OPEN '(' WORD ',' expr ')' | |
454 { $$ = make_op(O_OPEN, 2, | |
455 stab2arg(A_STAB,stabent($3,TRUE)), | |
456 $5, Nullarg,0); } | |
457 | CLOSE '(' WORD ')' | |
458 { $$ = make_op(O_CLOSE, 1, | |
459 stab2arg(A_STAB,stabent($3,TRUE)), | |
460 Nullarg, Nullarg,0); } | |
461 | CLOSE WORD %prec '(' | |
462 { $$ = make_op(O_CLOSE, 1, | |
463 stab2arg(A_STAB,stabent($2,TRUE)), | |
464 Nullarg, Nullarg,0); } | |
465 | FEOF '(' WORD ')' | |
466 { $$ = make_op(O_EOF, 1, | |
467 stab2arg(A_STAB,stabent($3,TRUE)), | |
468 Nullarg, Nullarg,0); } | |
469 | FEOF '(' ')' | |
470 { $$ = make_op(O_EOF, 0, | |
471 stab2arg(A_STAB,stabent("ARGV",TRUE)), | |
472 Nullarg, Nullarg,0); } | |
473 | FEOF | |
474 { $$ = make_op(O_EOF, 0, | |
475 Nullarg, Nullarg, Nullarg,0); } | |
476 | TELL '(' WORD ')' | |
477 { $$ = make_op(O_TELL, 1, | |
478 stab2arg(A_STAB,stabent($3,TRUE)), | |
479 Nullarg, Nullarg,0); } | |
480 | TELL | |
481 { $$ = make_op(O_TELL, 0, | |
482 Nullarg, Nullarg, Nullarg,0); } | |
483 | SEEK '(' WORD ',' sexpr ',' expr ')' | |
484 { $$ = make_op(O_SEEK, 3, | |
485 stab2arg(A_STAB,stabent($3,TRUE)), | |
486 $5, $7,1); } | |
487 | PUSH '(' WORD ',' expr ')' | |
488 { $$ = make_op($1, 2, | |
489 make_list($5), | |
490 stab2arg(A_STAB,aadd(stabent($3,TRUE))), | |
491 Nullarg,1); } | |
492 | PUSH '(' ARY ',' expr ')' | |
493 { $$ = make_op($1, 2, | |
494 make_list($5), | |
495 stab2arg(A_STAB,$3), | |
496 Nullarg,1); } | |
497 | POP WORD %prec '(' | |
498 { $$ = make_op(O_POP, 1, | |
499 stab2arg(A_STAB,aadd(stabent($2,TRUE))), | |
500 Nullarg, Nullarg,0); } | |
501 | POP '(' WORD ')' | |
502 { $$ = make_op(O_POP, 1, | |
503 stab2arg(A_STAB,aadd(stabent($3,TRUE))), | |
504 Nullarg, Nullarg,0); } | |
505 | POP ARY %prec '(' | |
506 { $$ = make_op(O_POP, 1, | |
507 stab2arg(A_STAB,$2), | |
508 Nullarg, | |
509 Nullarg, | |
510 0); } | |
511 | POP '(' ARY ')' | |
512 { $$ = make_op(O_POP, 1, | |
513 stab2arg(A_STAB,$3), | |
514 Nullarg, | |
515 Nullarg, | |
516 0); } | |
517 | SHIFT WORD %prec '(' | |
518 { $$ = make_op(O_SHIFT, 1, | |
519 stab2arg(A_STAB,aadd(stabent($2,TRUE))), | |
520 Nullarg, Nullarg,0); } | |
521 | SHIFT '(' WORD ')' | |
522 { $$ = make_op(O_SHIFT, 1, | |
523 stab2arg(A_STAB,aadd(stabent($3,TRUE))), | |
524 Nullarg, Nullarg,0); } | |
525 | SHIFT ARY %prec '(' | |
526 { $$ = make_op(O_SHIFT, 1, | |
527 stab2arg(A_STAB,$2), Nullarg, Nullarg,0); } | |
528 | SHIFT '(' ARY ')' | |
529 { $$ = make_op(O_SHIFT, 1, | |
530 stab2arg(A_STAB,$3), Nullarg, Nullarg,0); } | |
531 | SHIFT %prec '(' | |
532 { $$ = make_op(O_SHIFT, 1, | |
533 stab2arg(A_STAB,aadd(stabent("ARGV",TRUE))), | |
534 Nullarg, Nullarg,0); } | |
535 | SPLIT %prec '(' | |
536 { scanpat("/[ \t\n]+/"); | |
537 $$ = make_split(defstab,yylval.arg); } | |
538 | SPLIT '(' WORD ')' | |
539 { scanpat("/[ \t\n]+/"); | |
540 $$ = make_split(stabent($3,TRUE),yylval.arg); } | |
541 | SPLIT '(' WORD ',' PATTERN ')' | |
542 { $$ = make_split(stabent($3,TRUE),$5); } | |
543 | SPLIT '(' WORD ',' PATTERN ',' sexpr ')' | |
544 { $$ = mod_match(O_MATCH, | |
545 $7, | |
546 make_split(stabent($3,TRUE),$5) ); } | |
547 | SPLIT '(' sexpr ',' sexpr ')' | |
548 { $$ = mod_match(O_MATCH, $5, make_split(defstab,$3) ); } | |
549 | SPLIT '(' sexpr ')' | |
550 { $$ = mod_match(O_MATCH, | |
551 stab2arg(A_STAB,defstab), | |
552 make_split(defstab,$3) ); } | |
553 | JOIN '(' WORD ',' expr ')' | |
554 { $$ = make_op(O_JOIN, 2, | |
555 $5, | |
556 stab2arg(A_STAB,aadd(stabent($3,TRUE))), | |
557 Nullarg,0); } | |
558 | JOIN '(' sexpr ',' expr ')' | |
559 { $$ = make_op(O_JOIN, 2, | |
560 $3, | |
561 make_list($5), | |
562 Nullarg,2); } | |
563 | SPRINTF '(' expr ')' | |
564 { $$ = make_op(O_SPRINTF, 1, | |
565 make_list($3), | |
566 Nullarg, | |
567 Nullarg,1); } | |
568 | STAT '(' WORD ')' | |
569 { $$ = l(make_op(O_STAT, 1, | |
570 stab2arg(A_STAB,stabent($3,TRUE)), | |
571 Nullarg, Nullarg,0)); } | |
572 | STAT '(' expr ')' | |
573 { $$ = make_op(O_STAT, 1, $3, Nullarg, Nullarg,0); } | |
574 | CHOP | |
575 { $$ = l(make_op(O_CHOP, 1, | |
576 stab2arg(A_STAB,defstab), | |
577 Nullarg, Nullarg,0)); } | |
578 | CHOP '(' expr ')' | |
579 { $$ = l(make_op(O_CHOP, 1, $3, Nullarg, Nullarg,0)); } | |
580 | FUNC0 | |
581 { $$ = make_op($1, 0, Nullarg, Nullarg, Nullarg,0); } | |
582 | FUNC1 '(' expr ')' | |
583 { $$ = make_op($1, 1, $3, Nullarg, Nullarg,0); } | |
584 | FUNC2 '(' sexpr ',' expr ')' | |
585 { $$ = make_op($1, 2, $3, $5, Nullarg, 0); } | |
586 | FUNC3 '(' sexpr ',' sexpr ',' expr ')' | |
587 { $$ = make_op($1, 3, $3, $5, $7, 0); } | |
588 | STABFUN '(' WORD ')' | |
589 { $$ = make_op($1, 1, | |
590 stab2arg(A_STAB,hadd(stabent($3,TRUE))), | |
591 Nullarg, | |
592 Nullarg, 0); } | |
593 ; | |
594 | |
595 print : PRINT | |
596 { $$ = make_op($1,2, | |
597 stab2arg(A_STAB,defstab), | |
598 stab2arg(A_STAB,Nullstab), | |
599 Nullarg,0); } | |
600 | PRINT expr | |
601 { $$ = make_op($1,2,make_list($2), | |
602 stab2arg(A_STAB,Nullstab), | |
603 Nullarg,1); } | |
604 | PRINT WORD | |
605 { $$ = make_op($1,2, | |
606 stab2arg(A_STAB,defstab), | |
607 stab2arg(A_STAB,stabent($2,TRUE)), | |
608 Nullarg,1); } | |
609 | PRINT WORD expr | |
610 { $$ = make_op($1,2,make_list($3), | |
611 stab2arg(A_STAB,stabent($2,TRUE)), | |
612 Nullarg,1); } | |
613 ; | |
614 | |
615 %% /* PROGRAM */ | |
616 #include "perly.c" |