X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=x2p%2Fa2p.y;h=74c42d8c199d5ca145661f49bc04cc094c0b6591;hb=756c5c2b691752248a1635194088c45476f496bb;hp=afe513ca2470dfc8434ba0f02709adfd767c7497;hpb=a687059cbaf2c6fdccb5e0fae2aee80ec15625a8;p=p5sagit%2Fp5-mst-13.2.git diff --git a/x2p/a2p.y b/x2p/a2p.y index afe513c..74c42d8 100644 --- a/x2p/a2p.y +++ b/x2p/a2p.y @@ -1,15 +1,13 @@ %{ -/* $Header: a2p.y,v 3.0 89/10/18 15:34:29 lwall Locked $ +/* $RCSfile: a2p.y,v $$Revision: 4.1 $$Date: 92/08/07 18:29:12 $ * - * Copyright (c) 1989, Larry Wall + * Copyright (C) 1991, 1992, 1993, 1994, 1996, 1997, 1999, 2000, + * by Larry Wall and others * - * You may distribute under the terms of the GNU General Public License - * as specified in the README file that comes with the perl 3.0 kit. + * You may distribute under the terms of either the GNU General Public + * License or the Artistic License, as specified in the README file. * * $Log: a2p.y,v $ - * Revision 3.0 89/10/18 15:34:29 lwall - * 3.0 baseline - * */ #include "INTERN.h" @@ -24,7 +22,7 @@ int ends = Nullop; %token REGEX %token SEMINEW NEWLINE COMMENT %token FUN1 FUNN GRGR -%token PRINT PRINTF SPRINTF SPLIT +%token PRINT PRINTF SPRINTF_OLD SPRINTF_NEW SPLIT %token IF ELSE WHILE FOR IN %token EXIT NEXT BREAK CONTINUE RET %token GETLINE DO SUB GSUB MATCH @@ -46,7 +44,7 @@ int ends = Nullop; %left NOT %right '^' %left INCR DECR -%left FIELD VFIELD +%left FIELD VFIELD SVFIELD %% @@ -87,32 +85,18 @@ arg_list: expr_list { $$ = rememberargs($$); } ; -patpat : pat +patpat : cond { $$ = oper1(OPAT,$1); } - | pat ',' pat + | cond ',' cond { $$ = oper2(ORANGE,$1,$3); } ; -pat : match - | rel - | compound_pat - ; - -compound_pat - : '(' compound_pat ')' - { $$ = oper1(OPPAREN,$2); } - | pat ANDAND maybe pat - { $$ = oper3(OPANDAND,$1,$3,$4); } - | pat OROR maybe pat - { $$ = oper3(OPOROR,$1,$3,$4); } - | NOT pat - { $$ = oper1(OPNOT,$2); } - ; - cond : expr | match | rel | compound_cond + | cond '?' expr ':' expr + { $$ = oper3(OCOND,$1,$3,$5); } ; compound_cond @@ -150,15 +134,21 @@ expr : term { $$ = $1; } | expr term { $$ = oper2(OCONCAT,$1,$2); } - | variable ASGNOP expr - { $$ = oper3(OASSIGN,$2,$1,$3); - if ((ops[$1].ival & 255) == OFLD) - lval_field = TRUE; - if ((ops[$1].ival & 255) == OVFLD) - lval_field = TRUE; + | expr '?' expr ':' expr + { $$ = oper3(OCOND,$1,$3,$5); } + | variable ASGNOP cond + { + $$ = oper3(OASSIGN,$2,$1,$3); + if ((ops[$1].ival & 255) == OFLD) + lval_field = TRUE; + else if ((ops[$1].ival & 255) == OVFLD) + lval_field = TRUE; } ; +sprintf : SPRINTF_NEW + | SPRINTF_OLD ; + term : variable { $$ = $1; } | NUMBER @@ -179,36 +169,58 @@ term : variable { $$ = oper2(OPOW,$1,$3); } | term IN VAR { $$ = oper2(ODEFINED,aryrefarg($3),$1); } - | term '?' term ':' term - { $$ = oper2(OCOND,$1,$3,$5); } | variable INCR - { $$ = oper1(OPOSTINCR,$1); } + { + $$ = oper1(OPOSTINCR,$1); + if ((ops[$1].ival & 255) == OFLD) + lval_field = TRUE; + else if ((ops[$1].ival & 255) == OVFLD) + lval_field = TRUE; + } | variable DECR - { $$ = oper1(OPOSTDECR,$1); } + { + $$ = oper1(OPOSTDECR,$1); + if ((ops[$1].ival & 255) == OFLD) + lval_field = TRUE; + else if ((ops[$1].ival & 255) == OVFLD) + lval_field = TRUE; + } | INCR variable - { $$ = oper1(OPREINCR,$2); } + { + $$ = oper1(OPREINCR,$2); + if ((ops[$2].ival & 255) == OFLD) + lval_field = TRUE; + else if ((ops[$2].ival & 255) == OVFLD) + lval_field = TRUE; + } | DECR variable - { $$ = oper1(OPREDECR,$2); } + { + $$ = oper1(OPREDECR,$2); + if ((ops[$2].ival & 255) == OFLD) + lval_field = TRUE; + else if ((ops[$2].ival & 255) == OVFLD) + lval_field = TRUE; + } | '-' term %prec UMINUS { $$ = oper1(OUMINUS,$2); } | '+' term %prec UMINUS { $$ = oper1(OUPLUS,$2); } - | '(' expr ')' + | '(' cond ')' { $$ = oper1(OPAREN,$2); } | GETLINE { $$ = oper0(OGETLINE); } - | GETLINE VAR + | GETLINE variable { $$ = oper1(OGETLINE,$2); } | GETLINE '<' expr { $$ = oper3(OGETLINE,Nullop,string("<",1),$3); if (ops[$3].ival != OSTR + (1<<8)) do_fancy_opens = TRUE; } - | GETLINE VAR '<' expr + | GETLINE variable '<' expr { $$ = oper3(OGETLINE,$2,string("<",1),$4); if (ops[$4].ival != OSTR + (1<<8)) do_fancy_opens = TRUE; } | term 'p' GETLINE { $$ = oper3(OGETLINE,Nullop,string("|",1),$1); if (ops[$1].ival != OSTR + (1<<8)) do_fancy_opens = TRUE; } - | term 'p' GETLINE VAR + | term 'p' GETLINE variable { $$ = oper3(OGETLINE,$4,string("|",1),$1); if (ops[$1].ival != OSTR + (1<<8)) do_fancy_opens = TRUE; } | FUN1 @@ -221,7 +233,9 @@ term : variable { $$ = oper1($1,$3); } | USERFUN '(' expr_list ')' { $$ = oper2(OUSERFUN,$1,$3); } - | SPRINTF expr_list + | SPRINTF_NEW '(' expr_list ')' + { $$ = oper1(OSPRINTF,$3); } + | sprintf expr_list { $$ = oper1(OSPRINTF,$2); } | SUBSTR '(' expr ',' expr ',' expr ')' { $$ = oper3(OSUBSTR,$3,$5,$7); } @@ -229,6 +243,8 @@ term : variable { $$ = oper2(OSUBSTR,$3,$5); } | SPLIT '(' expr ',' VAR ',' expr ')' { $$ = oper3(OSPLIT,$3,aryrefarg(numary($5)),$7); } + | SPLIT '(' expr ',' VAR ',' REGEX ')' + { $$ = oper3(OSPLIT,$3,aryrefarg(numary($5)),oper1(OREGEX,$7));} | SPLIT '(' expr ',' VAR ')' { $$ = oper2(OSPLIT,$3,aryrefarg(numary($5))); } | INDEX '(' expr ',' expr ')' @@ -261,6 +277,8 @@ variable: VAR { $$ = oper2(OVAR,aryrefarg($1),$3); } | FIELD { $$ = oper1(OFLD,$1); } + | SVFIELD + { $$ = oper1(OVFLD,oper1(OVAR,$1)); } | VFIELD term { $$ = oper1(OVFLD,$2); } ; @@ -376,12 +394,12 @@ simple { $$ = oper0(ORETURN); } | RET expr { $$ = oper1(ORETURN,$2); } - | DELETE VAR '[' expr ']' + | DELETE VAR '[' expr_list ']' { $$ = oper2(ODELETE,aryrefarg($2),$4); } ; redir : '>' %prec FIELD - { $$ = oper1(OREDIR,$1); } + { $$ = oper1(OREDIR,string(">",1)); } | GRGR { $$ = oper1(OREDIR,string(">>",2)); } | '|' @@ -408,4 +426,7 @@ compound ; %% + +int yyparse (void); + #include "a2py.c"