# 2.11BSD#431 - /usr/src/new/PORT/perl.1.0.16/perl.y

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

Last modified: 2002-12-19 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1859 |