-/* $RCSfile: perly.y,v $$Revision: 4.0.1.4 $$Date: 92/06/08 17:33:25 $
+/* perly.y
*
- * Copyright (c) 1991, Larry Wall
+ * Copyright (c) 1991-2002, 2003, 2004, 2005, 2006 Larry Wall
+ * Copyright (c) 2007, 2008 by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
- * $Log: perly.y,v $
- * Revision 4.0.1.4 92/06/08 17:33:25 lwall
- * patch20: one of the backdoors to expectterm was on the wrong reduction
- *
- * Revision 4.0.1.3 92/06/08 15:18:16 lwall
- * patch20: an expression may now start with a bareword
- * patch20: relaxed requirement for semicolon at the end of a block
- * patch20: added ... as variant on ..
- * patch20: fixed double debug break in foreach with implicit array assignment
- * patch20: if {block} {block} didn't work any more
- * patch20: deleted some minor memory leaks
- *
- * Revision 4.0.1.2 91/11/05 18:17:38 lwall
- * patch11: extra comma at end of list is now allowed in more places (Hi, Felix!)
- * patch11: once-thru blocks didn't display right in the debugger
- * patch11: debugger got confused over nested subroutine definitions
- *
- * Revision 4.0.1.1 91/06/07 11:42:34 lwall
- * patch4: new copyright notice
- *
- * Revision 4.0 91/03/20 01:38:40 lwall
- * 4.0 baseline.
- *
*/
-%{
-#include "INTERN.h"
-#include "perl.h"
+/*
+ * 'I see,' laughed Strider. 'I look foul and feel fair. Is that it?
+ * All that is gold does not glitter, not all those who wander are lost.'
+ *
+ * [p.171 of _The Lord of the Rings_, I/x: "Strider"]
+ */
+
+/*
+ * This file holds the grammar for the Perl language. If edited, you need
+ * to run regen_perly.pl, which re-creates the files perly.h, perly.tab
+ * and perly.act which are derived from this.
+ *
+ * Note that these derived files are included and compiled twice; once
+ * from perly.c, and once from madly.c. The second time, a number of MAD
+ * macros are defined, which compile in extra code that allows the parse
+ * tree to be accurately dumped. In particular:
+ *
+ * MAD defined if compiling madly.c
+ * DO_MAD(A) expands to A under madly.c, to null otherwise
+ * IF_MAD(a,b) expands to A under madly.c, to B otherwise
+ * TOKEN_GETMAD() expands to token_getmad() under madly.c, to null otherwise
+ * TOKEN_FREE() similarly
+ * OP_GETMAD() similarly
+ * IVAL(i) expands to (i)->tk_lval.ival or (i)
+ * PVAL(p) expands to (p)->tk_lval.pval or (p)
+ *
+ * The main job of of this grammar is to call the various newFOO()
+ * functions in op.c to build a syntax tree of OP structs.
+ * It relies on the lexer in toke.c to do the tokenizing.
+ *
+ * Note: due to the way that the cleanup code works WRT to freeing ops on
+ * the parse stack, it is dangerous to assign to the $n variables within
+ * an action.
+ */
-/*SUPPRESS 530*/
-/*SUPPRESS 593*/
-/*SUPPRESS 595*/
+/* Make the parser re-entrant. */
-STAB *scrstab;
-ARG *arg4; /* rarely used arguments to make_op() */
-ARG *arg5;
+%pure_parser
-%}
+/* FIXME for MAD - is the new mintro on while and until important? */
%start prog
%union {
- int ival;
- char *cval;
- ARG *arg;
- CMD *cmdval;
- struct compcmd compval;
- STAB *stabval;
- FCMD *formval;
+ I32 ival; /* __DEFAULT__ (marker for regen_perly.pl;
+ must always be 1st union member) */
+ char *pval;
+ OP *opval;
+ GV *gvval;
+#ifdef PERL_IN_MADLY_C
+ TOKEN* p_tkval;
+ TOKEN* i_tkval;
+#else
+ char *p_tkval;
+ I32 i_tkval;
+#endif
+#ifdef PERL_MAD
+ TOKEN* tkval;
+#endif
}
-%token <ival> '{' ')'
-
-%token <cval> WORD LABEL
-%token <ival> APPEND OPEN SSELECT LOOPEX DOTDOT
-%token <ival> USING FORMAT DO SHIFT PUSH POP LVALFUN
-%token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE SPLIT FLIST
-%token <ival> FOR FILOP FILOP2 FILOP3 FILOP4 FILOP22 FILOP25
-%token <ival> FUNC0 FUNC1 FUNC2 FUNC2x FUNC3 FUNC4 FUNC5 HSHFUN HSHFUN3
-%token <ival> FLIST2 SUB FILETEST LOCAL DELETE
-%token <ival> RELOP EQOP MULOP ADDOP PACKAGE AMPER
-%token <formval> FORMLIST
-%token <stabval> REG ARYLEN ARY HSH STAR
-%token <arg> SUBST PATTERN
-%token <arg> RSTRING TRANS
-
-%type <ival> prog decl format remember crp
-%type <cmdval> block lineseq line loop cond sideff nexpr else
-%type <arg> expr sexpr cexpr csexpr term handle aryword hshword
-%type <arg> texpr listop bareword
-%type <cval> label
-%type <compval> compblock
-
-%nonassoc <ival> LISTOP
-%left ','
-%right '='
-%right '?' ':'
-%nonassoc DOTDOT
-%left OROR
-%left ANDAND
-%left '|' '^'
-%left '&'
+%token <i_tkval> '{' '}' '[' ']' '-' '+' '$' '@' '%' '*' '&' ';'
+
+%token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF
+%token <opval> FUNC0SUB UNIOPSUB LSTOPSUB
+%token <p_tkval> LABEL
+%token <i_tkval> FORMAT SUB ANONSUB PACKAGE USE
+%token <i_tkval> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
+%token <i_tkval> GIVEN WHEN DEFAULT
+%token <i_tkval> LOOPEX DOTDOT YADAYADA
+%token <i_tkval> FUNC0 FUNC1 FUNC UNIOP LSTOP
+%token <i_tkval> RELOP EQOP MULOP ADDOP
+%token <i_tkval> DOLSHARP DO HASHBRACK NOAMP
+%token <i_tkval> LOCAL MY MYSUB REQUIRE
+%token <i_tkval> COLONATTR
+
+%type <ival> prog progstart remember mremember
+%type <ival> startsub startanonsub startformsub
+/* FIXME for MAD - are these two ival? */
+%type <ival> mydefsv mintro
+
+%type <opval> decl format subrout mysubrout package use peg
+
+%type <opval> block mblock lineseq line loop cond else
+%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
+%type <opval> argexpr nexpr texpr iexpr mexpr mnexpr miexpr
+%type <opval> listexpr listexprcom indirob listop method
+%type <opval> formname subname proto subbody cont my_scalar
+%type <opval> subattrlist myattrlist myattrterm myterm
+%type <opval> termbinop termunop anonymous termdo
+%type <opval> switch case
+%type <p_tkval> label
+
+%nonassoc <i_tkval> PREC_LOW
+%nonassoc LOOPEX
+
+%left <i_tkval> OROP DOROP
+%left <i_tkval> ANDOP
+%right <i_tkval> NOTOP
+%nonassoc LSTOP LSTOPSUB
+%left <i_tkval> ','
+%right <i_tkval> ASSIGNOP
+%right <i_tkval> '?' ':'
+%nonassoc DOTDOT YADAYADA
+%left <i_tkval> OROR DORDOR
+%left <i_tkval> ANDAND
+%left <i_tkval> BITOROP
+%left <i_tkval> BITANDOP
%nonassoc EQOP
%nonassoc RELOP
-%nonassoc <ival> UNIOP
-%nonassoc FILETEST
-%left LS RS
+%nonassoc UNIOP UNIOPSUB
+%nonassoc REQUIRE
+%left <i_tkval> SHIFTOP
%left ADDOP
%left MULOP
-%left MATCH NMATCH
-%right '!' '~' UMINUS
-%right POW
-%nonassoc INC DEC
-%left '('
+%left <i_tkval> MATCHOP
+%right <i_tkval> '!' '~' UMINUS REFGEN
+%right <i_tkval> POWOP
+%nonassoc <i_tkval> PREINC PREDEC POSTINC POSTDEC
+%left <i_tkval> ARROW
+%nonassoc <i_tkval> ')'
+%left <i_tkval> '('
+%left '[' '{'
+
+%token <i_tkval> PEG
%% /* RULES */
-prog : /* NULL */
- {
-#if defined(YYDEBUG) && defined(DEBUGGING)
- yydebug = (debug & 1);
- expectterm = 2;
-#endif
- }
+/* The whole program */
+prog : progstart
/*CONTINUED*/ lineseq
- { if (in_eval)
- eval_root = block_head($2);
- else
- main_root = block_head($2); }
+ { $$ = $1; newPROG(block_end($1,$2)); }
;
-compblock: block CONTINUE block
- { $$.comp_true = $1; $$.comp_alt = $3; }
- | block else
- { $$.comp_true = $1; $$.comp_alt = $2; }
+/* An ordinary block */
+block : '{' remember lineseq '}'
+ { if (PL_parser->copline > (line_t)IVAL($1))
+ PL_parser->copline = (line_t)IVAL($1);
+ $$ = block_end($2, $3);
+ TOKEN_GETMAD($1,$$,'{');
+ TOKEN_GETMAD($4,$$,'}');
+ }
;
-else : /* NULL */
- { $$ = Nullcmd; }
- | ELSE block
- { $$ = $2; }
- | ELSIF '(' expr ')' compblock
- { cmdline = $1;
- $$ = make_ccmd(C_ELSIF,1,$3,$5); }
+remember: /* NULL */ /* start a full lexical scope */
+ { $$ = block_start(TRUE); }
;
-block : '{' remember lineseq '}'
- { $$ = block_head($3);
- if (cmdline > (line_t)$1)
- cmdline = $1;
- if (savestack->ary_fill > $2)
- restorelist($2);
- expectterm = 2; }
+mydefsv: /* NULL */ /* lexicalize $_ */
+ { $$ = (I32) allocmy("$_"); }
+ ;
+
+progstart:
+ {
+ PL_parser->expect = XSTATE; $$ = block_start(TRUE);
+ }
;
-remember: /* NULL */ /* in case they push a package name */
- { $$ = savestack->ary_fill; }
+
+mblock : '{' mremember lineseq '}'
+ { if (PL_parser->copline > (line_t)IVAL($1))
+ PL_parser->copline = (line_t)IVAL($1);
+ $$ = block_end($2, $3);
+ TOKEN_GETMAD($1,$$,'{');
+ TOKEN_GETMAD($4,$$,'}');
+ }
;
+mremember: /* NULL */ /* start a partial lexical scope */
+ { $$ = block_start(FALSE); }
+ ;
+
+/* A collection of "lines" in the program */
lineseq : /* NULL */
- { $$ = Nullcmd; }
+ { $$ = (OP*)NULL; }
+ | lineseq decl
+ {
+ $$ = IF_MAD(
+ append_list(OP_LINESEQ,
+ (LISTOP*)$1, (LISTOP*)$2),
+ $1);
+ }
| lineseq line
- { $$ = append_line($1,$2); }
+ { $$ = append_list(OP_LINESEQ,
+ (LISTOP*)$1, (LISTOP*)$2);
+ PL_pad_reset_pending = TRUE;
+ if ($1 && $2)
+ PL_hints |= HINT_BLOCK_SCOPE;
+ }
;
-line : decl
- { $$ = Nullcmd; }
- | label cond
- { $$ = add_label($1,$2); }
+/* A "line" in the program */
+line : label cond
+ { $$ = newSTATEOP(0, PVAL($1), $2);
+ TOKEN_GETMAD($1,((LISTOP*)$$)->op_first,'L'); }
| loop /* loops add their own labels */
+ | switch /* ... and so do switches */
+ { $$ = $1; }
+ | label case
+ { $$ = newSTATEOP(0, PVAL($1), $2); }
| label ';'
- { if ($1 != Nullch) {
- $$ = add_label($1, make_acmd(C_EXPR, Nullstab,
- Nullarg, Nullarg) );
- }
- else {
- $$ = Nullcmd;
- cmdline = NOLINE;
- }
- expectterm = 2; }
+ {
+ if (PVAL($1)) {
+ $$ = newSTATEOP(0, PVAL($1), newOP(OP_NULL, 0));
+ TOKEN_GETMAD($1,$$,'L');
+ TOKEN_GETMAD($2,((LISTOP*)$$)->op_first,';');
+ }
+ else {
+ $$ = IF_MAD(
+ newOP(OP_NULL, 0),
+ (OP*)NULL);
+ PL_parser->copline = NOLINE;
+ TOKEN_FREE($1);
+ TOKEN_GETMAD($2,$$,';');
+ }
+ PL_parser->expect = XSTATE;
+ }
| label sideff ';'
- { $$ = add_label($1,$2);
- expectterm = 2; }
+ {
+ $$ = newSTATEOP(0, PVAL($1), $2);
+ PL_parser->expect = XSTATE;
+ DO_MAD({
+ /* sideff might already have a nexstate */
+ OP* op = ((LISTOP*)$$)->op_first;
+ if (op) {
+ while (op->op_sibling &&
+ op->op_sibling->op_type == OP_NEXTSTATE)
+ op = op->op_sibling;
+ token_getmad($1,op,'L');
+ token_getmad($3,op,';');
+ }
+ })
+ }
;
+/* An expression which may have a side-effect */
sideff : error
- { $$ = Nullcmd; }
+ { $$ = (OP*)NULL; }
| expr
- { $$ = make_acmd(C_EXPR, Nullstab, $1, Nullarg); }
+ { $$ = $1; }
| expr IF expr
- { $$ = addcond(
- make_acmd(C_EXPR, Nullstab, Nullarg, $1), $3); }
+ { $$ = newLOGOP(OP_AND, 0, $3, $1);
+ TOKEN_GETMAD($2,$$,'i');
+ }
| expr UNLESS expr
- { $$ = addcond(invert(
- make_acmd(C_EXPR, Nullstab, Nullarg, $1)), $3); }
+ { $$ = newLOGOP(OP_OR, 0, $3, $1);
+ TOKEN_GETMAD($2,$$,'i');
+ }
| expr WHILE expr
- { $$ = addloop(
- make_acmd(C_EXPR, Nullstab, Nullarg, $1), $3); }
- | expr UNTIL expr
- { $$ = addloop(invert(
- make_acmd(C_EXPR, Nullstab, Nullarg, $1)), $3); }
- ;
-
-cond : IF '(' expr ')' compblock
- { cmdline = $1;
- $$ = make_icmd(C_IF,$3,$5); }
- | UNLESS '(' expr ')' compblock
- { cmdline = $1;
- $$ = invert(make_icmd(C_IF,$3,$5)); }
- | IF block compblock
- { cmdline = $1;
- $$ = make_icmd(C_IF,cmd_to_arg($2),$3); }
- | UNLESS block compblock
- { cmdline = $1;
- $$ = invert(make_icmd(C_IF,cmd_to_arg($2),$3)); }
- ;
-
-loop : label WHILE '(' texpr ')' compblock
- { cmdline = $2;
- $$ = wopt(add_label($1,
- make_ccmd(C_WHILE,1,$4,$6) )); }
- | label UNTIL '(' expr ')' compblock
- { cmdline = $2;
- $$ = wopt(add_label($1,
- invert(make_ccmd(C_WHILE,1,$4,$6)) )); }
- | label WHILE block compblock
- { cmdline = $2;
- $$ = wopt(add_label($1,
- make_ccmd(C_WHILE, 1, cmd_to_arg($3),$4) )); }
- | label UNTIL block compblock
- { cmdline = $2;
- $$ = wopt(add_label($1,
- invert(make_ccmd(C_WHILE,1,cmd_to_arg($3),$4)) )); }
- | label FOR REG '(' expr crp compblock
- { cmdline = $2;
- /*
- * The following gobbledygook catches EXPRs that
- * aren't explicit array refs and translates
- * foreach VAR (EXPR) {
- * into
- * @ary = EXPR;
- * foreach VAR (@ary) {
- * where @ary is a hidden array made by genstab().
- * (Note that @ary may become a local array if
- * it is determined that it might be called
- * recursively. See cmd_tosave().)
- */
- if ($5->arg_type != O_ARRAY) {
- scrstab = aadd(genstab());
- $$ = append_line(
- make_acmd(C_EXPR, Nullstab,
- l(make_op(O_ASSIGN,2,
- listish(make_op(O_ARRAY, 1,
- stab2arg(A_STAB,scrstab),
- Nullarg,Nullarg )),
- listish(make_list($5)),
- Nullarg)),
- Nullarg),
- wopt(over($3,add_label($1,
- make_ccmd(C_WHILE, 0,
- make_op(O_ARRAY, 1,
- stab2arg(A_STAB,scrstab),
- Nullarg,Nullarg ),
- $7)))));
- $$->c_line = $2;
- $$->c_head->c_line = $2;
- }
- else {
- $$ = wopt(over($3,add_label($1,
- make_ccmd(C_WHILE,1,$5,$7) )));
- }
+ { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1);
+ TOKEN_GETMAD($2,$$,'w');
}
- | label FOR '(' expr crp compblock
- { cmdline = $2;
- if ($4->arg_type != O_ARRAY) {
- scrstab = aadd(genstab());
- $$ = append_line(
- make_acmd(C_EXPR, Nullstab,
- l(make_op(O_ASSIGN,2,
- listish(make_op(O_ARRAY, 1,
- stab2arg(A_STAB,scrstab),
- Nullarg,Nullarg )),
- listish(make_list($4)),
- Nullarg)),
- Nullarg),
- wopt(over(defstab,add_label($1,
- make_ccmd(C_WHILE, 0,
- make_op(O_ARRAY, 1,
- stab2arg(A_STAB,scrstab),
- Nullarg,Nullarg ),
- $6)))));
- $$->c_line = $2;
- $$->c_head->c_line = $2;
- }
- else { /* lisp, anyone? */
- $$ = wopt(over(defstab,add_label($1,
- make_ccmd(C_WHILE,1,$4,$6) )));
- }
+ | expr UNTIL iexpr
+ { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1);
+ TOKEN_GETMAD($2,$$,'w');
+ }
+ | expr FOR expr
+ { $$ = newFOROP(0, NULL, (line_t)IVAL($2),
+ (OP*)NULL, $3, $1, (OP*)NULL);
+ TOKEN_GETMAD($2,((LISTOP*)$$)->op_first->op_sibling,'w');
+ }
+ ;
+
+/* else and elsif blocks */
+else : /* NULL */
+ { $$ = (OP*)NULL; }
+ | ELSE mblock
+ { ($2)->op_flags |= OPf_PARENS; $$ = scope($2);
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | ELSIF '(' mexpr ')' mblock else
+ { PL_parser->copline = (line_t)IVAL($1);
+ $$ = newCONDOP(0, newSTATEOP(OPf_SPECIAL,NULL,$3), scope($5), $6);
+ PL_hints |= HINT_BLOCK_SCOPE;
+ TOKEN_GETMAD($1,$$,'I');
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($4,$$,')');
+ }
+ ;
+
+/* Real conditional expressions */
+cond : IF '(' remember mexpr ')' mblock else
+ { PL_parser->copline = (line_t)IVAL($1);
+ $$ = block_end($3,
+ newCONDOP(0, $4, scope($6), $7));
+ TOKEN_GETMAD($1,$$,'I');
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($5,$$,')');
+ }
+ | UNLESS '(' remember miexpr ')' mblock else
+ { PL_parser->copline = (line_t)IVAL($1);
+ $$ = block_end($3,
+ newCONDOP(0, $4, scope($6), $7));
+ TOKEN_GETMAD($1,$$,'I');
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($5,$$,')');
+ }
+ ;
+
+/* Cases for a switch statement */
+case : WHEN '(' remember mexpr ')' mblock
+ { $$ = block_end($3,
+ newWHENOP($4, scope($6))); }
+ | DEFAULT block
+ { $$ = newWHENOP(0, scope($2)); }
+ ;
+
+/* Continue blocks */
+cont : /* NULL */
+ { $$ = (OP*)NULL; }
+ | CONTINUE block
+ { $$ = scope($2);
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ ;
+
+/* Loops: while, until, for, and a bare block */
+loop : label WHILE '(' remember texpr ')' mintro mblock cont
+ { OP *innerop;
+ PL_parser->copline = (line_t)$2;
+ $$ = block_end($4,
+ newSTATEOP(0, PVAL($1),
+ innerop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
+ IVAL($2), $5, $8, $9, $7)));
+ TOKEN_GETMAD($1,innerop,'L');
+ TOKEN_GETMAD($2,innerop,'W');
+ TOKEN_GETMAD($3,innerop,'(');
+ TOKEN_GETMAD($6,innerop,')');
+ }
+
+ | label UNTIL '(' remember iexpr ')' mintro mblock cont
+ { OP *innerop;
+ PL_parser->copline = (line_t)$2;
+ $$ = block_end($4,
+ newSTATEOP(0, PVAL($1),
+ innerop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
+ IVAL($2), $5, $8, $9, $7)));
+ TOKEN_GETMAD($1,innerop,'L');
+ TOKEN_GETMAD($2,innerop,'W');
+ TOKEN_GETMAD($3,innerop,'(');
+ TOKEN_GETMAD($6,innerop,')');
+ }
+ | label FOR MY remember my_scalar '(' mexpr ')' mblock cont
+ { OP *innerop;
+ $$ = block_end($4,
+ innerop = newFOROP(0, PVAL($1), (line_t)IVAL($2),
+ $5, $7, $9, $10));
+ TOKEN_GETMAD($1,((LISTOP*)innerop)->op_first,'L');
+ TOKEN_GETMAD($2,((LISTOP*)innerop)->op_first->op_sibling,'W');
+ TOKEN_GETMAD($3,((LISTOP*)innerop)->op_first->op_sibling,'d');
+ TOKEN_GETMAD($6,((LISTOP*)innerop)->op_first->op_sibling,'(');
+ TOKEN_GETMAD($8,((LISTOP*)innerop)->op_first->op_sibling,')');
}
- | label FOR '(' nexpr ';' texpr ';' nexpr ')' block
+ | label FOR scalar '(' remember mexpr ')' mblock cont
+ { OP *innerop;
+ $$ = block_end($5,
+ innerop = newFOROP(0, PVAL($1), (line_t)IVAL($2),
+ mod($3, OP_ENTERLOOP), $6, $8, $9));
+ TOKEN_GETMAD($1,((LISTOP*)innerop)->op_first,'L');
+ TOKEN_GETMAD($2,((LISTOP*)innerop)->op_first->op_sibling,'W');
+ TOKEN_GETMAD($4,((LISTOP*)innerop)->op_first->op_sibling,'(');
+ TOKEN_GETMAD($7,((LISTOP*)innerop)->op_first->op_sibling,')');
+ }
+ | label FOR '(' remember mexpr ')' mblock cont
+ { OP *innerop;
+ $$ = block_end($4,
+ innerop = newFOROP(0, PVAL($1), (line_t)IVAL($2),
+ (OP*)NULL, $5, $7, $8));
+ TOKEN_GETMAD($1,((LISTOP*)innerop)->op_first,'L');
+ TOKEN_GETMAD($2,((LISTOP*)innerop)->op_first->op_sibling,'W');
+ TOKEN_GETMAD($3,((LISTOP*)innerop)->op_first->op_sibling,'(');
+ TOKEN_GETMAD($6,((LISTOP*)innerop)->op_first->op_sibling,')');
+ }
+ | label FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')'
+ mblock
/* basically fake up an initialize-while lineseq */
- { yyval.compval.comp_true = $10;
- yyval.compval.comp_alt = $8;
- cmdline = $2;
- $$ = append_line($4,wopt(add_label($1,
- make_ccmd(C_WHILE,1,$6,yyval.compval) ))); }
- | label compblock /* a block is a loop that happens once */
- { $$ = add_label($1,make_ccmd(C_BLOCK,1,Nullarg,$2)); }
+ { OP *forop;
+ PL_parser->copline = (line_t)IVAL($2);
+ forop = newSTATEOP(0, PVAL($1),
+ newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
+ IVAL($2), scalar($7),
+ $12, $10, $9));
+#ifdef MAD
+ forop = newUNOP(OP_NULL, 0, append_elem(OP_LINESEQ,
+ newSTATEOP(0,
+ CopLABEL_alloc(($1)->tk_lval.pval),
+ ($5 ? $5 : newOP(OP_NULL, 0)) ),
+ forop));
+
+ token_getmad($2,forop,'3');
+ token_getmad($3,forop,'(');
+ token_getmad($6,forop,'1');
+ token_getmad($8,forop,'2');
+ token_getmad($11,forop,')');
+ token_getmad($1,forop,'L');
+#else
+ if ($5) {
+ forop = append_elem(OP_LINESEQ,
+ newSTATEOP(0, CopLABEL_alloc($1), $5),
+ forop);
+ }
+
+
+#endif
+ $$ = block_end($4, forop); }
+ | label block cont /* a block is a loop that happens once */
+ { $$ = newSTATEOP(0, PVAL($1),
+ newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
+ NOLINE, (OP*)NULL, $2, $3, 0));
+ TOKEN_GETMAD($1,((LISTOP*)$$)->op_first,'L'); }
;
+/* Switch blocks */
+switch : label GIVEN '(' remember mydefsv mexpr ')' mblock
+ { PL_parser->copline = (line_t) $2;
+ $$ = block_end($4,
+ newSTATEOP(0, PVAL($1),
+ newGIVENOP($6, scope($8),
+ (PADOFFSET) $5) )); }
+ ;
+
+/* determine whether there are any new my declarations */
+mintro : /* NULL */
+ { $$ = (PL_min_intro_pending &&
+ PL_max_intro_pending >= PL_min_intro_pending);
+ intro_my(); }
+
+/* Normal expression */
nexpr : /* NULL */
- { $$ = Nullcmd; }
+ { $$ = (OP*)NULL; }
| sideff
;
+/* Boolean expression */
texpr : /* NULL means true */
- { (void)scanstr("1",SCAN_DEF); $$ = yylval.arg; }
+ { YYSTYPE tmplval;
+ (void)scan_num("1", &tmplval);
+ $$ = tmplval.opval; }
| expr
;
+/* Inverted boolean expression */
+iexpr : expr
+ { $$ = invert(scalar($1)); }
+ ;
+
+/* Expression with its own lexical scope */
+mexpr : expr
+ { $$ = $1; intro_my(); }
+ ;
+
+mnexpr : nexpr
+ { $$ = $1; intro_my(); }
+ ;
+
+miexpr : iexpr
+ { $$ = $1; intro_my(); }
+ ;
+
+/* Optional "MAIN:"-style loop labels */
label : /* empty */
- { $$ = Nullch; }
+ {
+#ifdef MAD
+ YYSTYPE tmplval;
+ tmplval.pval = NULL;
+ $$ = newTOKEN(OP_NULL, tmplval, 0);
+#else
+ $$ = NULL;
+#endif
+ }
| LABEL
;
+/* Some kind of declaration - just hang on peg in the parse tree */
decl : format
- { $$ = 0; }
+ { $$ = $1; }
| subrout
- { $$ = 0; }
+ { $$ = $1; }
+ | mysubrout
+ { $$ = $1; }
| package
- { $$ = 0; }
+ { $$ = $1; }
+ | use
+ { $$ = $1; }
+
+ /* these two are only used by MAD */
+
+ | peg
+ { $$ = $1; }
+ ;
+
+peg : PEG
+ { $$ = newOP(OP_NULL,0);
+ TOKEN_GETMAD($1,$$,'p');
+ }
+ ;
+
+format : FORMAT startformsub formname block
+ { SvREFCNT_inc_simple_void(PL_compcv);
+#ifdef MAD
+ $$ = newFORM($2, $3, $4);
+ prepend_madprops($1->tk_mad, $$, 'F');
+ $1->tk_mad = 0;
+ token_free($1);
+#else
+ newFORM($2, $3, $4);
+ $$ = (OP*)NULL;
+#endif
+ }
+ ;
+
+formname: WORD { $$ = $1; }
+ | /* NULL */ { $$ = (OP*)NULL; }
+ ;
+
+/* Unimplemented "my sub foo { }" */
+mysubrout: MYSUB startsub subname proto subattrlist subbody
+ { SvREFCNT_inc_simple_void(PL_compcv);
+#ifdef MAD
+ $$ = newMYSUB($2, $3, $4, $5, $6);
+ token_getmad($1,$$,'d');
+#else
+ newMYSUB($2, $3, $4, $5, $6);
+ $$ = (OP*)NULL;
+#endif
+ }
;
-format : FORMAT WORD '=' FORMLIST
- { if (strEQ($2,"stdout"))
- make_form(stabent("STDOUT",TRUE),$4);
- else if (strEQ($2,"stderr"))
- make_form(stabent("STDERR",TRUE),$4);
- else
- make_form(stabent($2,TRUE),$4);
- Safefree($2); $2 = Nullch; }
- | FORMAT '=' FORMLIST
- { make_form(stabent("STDOUT",TRUE),$3); }
+/* Subroutine definition */
+subrout : SUB startsub subname proto subattrlist subbody
+ { SvREFCNT_inc_simple_void(PL_compcv);
+#ifdef MAD
+ {
+ OP* o = newSVOP(OP_ANONCODE, 0,
+ (SV*)newATTRSUB($2, $3, $4, $5, $6));
+ $$ = newOP(OP_NULL,0);
+ op_getmad(o,$$,'&');
+ op_getmad($3,$$,'n');
+ op_getmad($4,$$,'s');
+ op_getmad($5,$$,'a');
+ token_getmad($1,$$,'d');
+ append_madprops($6->op_madprop, $$, 0);
+ $6->op_madprop = 0;
+ }
+#else
+ newATTRSUB($2, $3, $4, $5, $6);
+ $$ = (OP*)NULL;
+#endif
+ }
+ ;
+
+startsub: /* NULL */ /* start a regular subroutine scope */
+ { $$ = start_subparse(FALSE, 0);
+ SAVEFREESV(PL_compcv); }
+
+ ;
+
+startanonsub: /* NULL */ /* start an anonymous subroutine scope */
+ { $$ = start_subparse(FALSE, CVf_ANON);
+ SAVEFREESV(PL_compcv); }
+ ;
+
+startformsub: /* NULL */ /* start a format subroutine scope */
+ { $$ = start_subparse(TRUE, 0);
+ SAVEFREESV(PL_compcv); }
+ ;
+
+/* Name of a subroutine - must be a bareword, could be special */
+subname : WORD { const char *const name = SvPV_nolen_const(((SVOP*)$1)->op_sv);
+ if (strEQ(name, "BEGIN") || strEQ(name, "END")
+ || strEQ(name, "INIT") || strEQ(name, "CHECK")
+ || strEQ(name, "UNITCHECK"))
+ CvSPECIAL_on(PL_compcv);
+ $$ = $1; }
+ ;
+
+/* Subroutine prototype */
+proto : /* NULL */
+ { $$ = (OP*)NULL; }
+ | THING
+ ;
+
+/* Optional list of subroutine attributes */
+subattrlist: /* NULL */
+ { $$ = (OP*)NULL; }
+ | COLONATTR THING
+ { $$ = $2;
+ TOKEN_GETMAD($1,$$,':');
+ }
+ | COLONATTR
+ { $$ = IF_MAD(
+ newOP(OP_NULL, 0),
+ (OP*)NULL
+ );
+ TOKEN_GETMAD($1,$$,':');
+ }
;
-subrout : SUB WORD block
- { make_sub($2,$3);
- cmdline = NOLINE;
- if (savestack->ary_fill > $1)
- restorelist($1); }
+/* List of attributes for a "my" variable declaration */
+myattrlist: COLONATTR THING
+ { $$ = $2;
+ TOKEN_GETMAD($1,$$,':');
+ }
+ | COLONATTR
+ { $$ = IF_MAD(
+ newOP(OP_NULL, 0),
+ (OP*)NULL
+ );
+ TOKEN_GETMAD($1,$$,':');
+ }
+ ;
+
+/* Subroutine body - either null or a block */
+subbody : block { $$ = $1; }
+ | ';' { $$ = IF_MAD(
+ newOP(OP_NULL,0),
+ (OP*)NULL
+ );
+ PL_parser->expect = XSTATE;
+ TOKEN_GETMAD($1,$$,';');
+ }
;
package : PACKAGE WORD ';'
- { char tmpbuf[256];
- STAB *tmpstab;
-
- savehptr(&curstash);
- saveitem(curstname);
- str_set(curstname,$2);
- sprintf(tmpbuf,"'_%s",$2);
- tmpstab = stabent(tmpbuf,TRUE);
- if (!stab_xhash(tmpstab))
- stab_xhash(tmpstab) = hnew(0);
- curstash = stab_xhash(tmpstab);
- if (!curstash->tbl_name)
- curstash->tbl_name = savestr($2);
- curstash->tbl_coeffsize = 0;
- Safefree($2); $2 = Nullch;
- cmdline = NOLINE;
- expectterm = 2;
- }
- ;
-
-cexpr : ',' expr
- { $$ = $2; }
- ;
-
-expr : expr ',' sexpr
- { $$ = make_op(O_COMMA, 2, $1, $3, Nullarg); }
- | sexpr
- ;
-
-csexpr : ',' sexpr
- { $$ = $2; }
- ;
-
-sexpr : sexpr '=' sexpr
- { $1 = listish($1);
- if ($1->arg_type == O_ASSIGN && $1->arg_len == 1)
- $1->arg_type = O_ITEM; /* a local() */
- if ($1->arg_type == O_LIST)
- $3 = listish($3);
- $$ = l(make_op(O_ASSIGN, 2, $1, $3, Nullarg)); }
- | sexpr POW '=' sexpr
- { $$ = l(make_op(O_POW, 2, $1, $4, Nullarg)); }
- | sexpr MULOP '=' sexpr
- { $$ = l(make_op($2, 2, $1, $4, Nullarg)); }
- | sexpr ADDOP '=' sexpr
- { $$ = rcatmaybe(l(make_op($2, 2, $1, $4, Nullarg)));}
- | sexpr LS '=' sexpr
- { $$ = l(make_op(O_LEFT_SHIFT, 2, $1, $4, Nullarg)); }
- | sexpr RS '=' sexpr
- { $$ = l(make_op(O_RIGHT_SHIFT, 2, $1, $4, Nullarg)); }
- | sexpr '&' '=' sexpr
- { $$ = l(make_op(O_BIT_AND, 2, $1, $4, Nullarg)); }
- | sexpr '^' '=' sexpr
- { $$ = l(make_op(O_XOR, 2, $1, $4, Nullarg)); }
- | sexpr '|' '=' sexpr
- { $$ = l(make_op(O_BIT_OR, 2, $1, $4, Nullarg)); }
-
-
- | sexpr POW sexpr
- { $$ = make_op(O_POW, 2, $1, $3, Nullarg); }
- | sexpr MULOP sexpr
- { if ($2 == O_REPEAT)
- $1 = listish($1);
- $$ = make_op($2, 2, $1, $3, Nullarg);
- if ($2 == O_REPEAT) {
- if ($$[1].arg_type != A_EXPR ||
- $$[1].arg_ptr.arg_arg->arg_type != O_LIST)
- $$[1].arg_flags &= ~AF_ARYOK;
- } }
- | sexpr ADDOP sexpr
- { $$ = make_op($2, 2, $1, $3, Nullarg); }
- | sexpr LS sexpr
- { $$ = make_op(O_LEFT_SHIFT, 2, $1, $3, Nullarg); }
- | sexpr RS sexpr
- { $$ = make_op(O_RIGHT_SHIFT, 2, $1, $3, Nullarg); }
- | sexpr RELOP sexpr
- { $$ = make_op($2, 2, $1, $3, Nullarg); }
- | sexpr EQOP sexpr
- { $$ = make_op($2, 2, $1, $3, Nullarg); }
- | sexpr '&' sexpr
- { $$ = make_op(O_BIT_AND, 2, $1, $3, Nullarg); }
- | sexpr '^' sexpr
- { $$ = make_op(O_XOR, 2, $1, $3, Nullarg); }
- | sexpr '|' sexpr
- { $$ = make_op(O_BIT_OR, 2, $1, $3, Nullarg); }
- | sexpr DOTDOT sexpr
- { arg4 = Nullarg;
- $$ = make_op(O_F_OR_R, 4, $1, $3, Nullarg);
- $$[0].arg_flags |= $2; }
- | sexpr ANDAND sexpr
- { $$ = make_op(O_AND, 2, $1, $3, Nullarg); }
- | sexpr OROR sexpr
- { $$ = make_op(O_OR, 2, $1, $3, Nullarg); }
- | sexpr '?' sexpr ':' sexpr
- { $$ = make_op(O_COND_EXPR, 3, $1, $3, $5); }
- | sexpr MATCH sexpr
- { $$ = mod_match(O_MATCH, $1, $3); }
- | sexpr NMATCH sexpr
- { $$ = mod_match(O_NMATCH, $1, $3); }
- | term
- { $$ = $1; }
+ {
+#ifdef MAD
+ $$ = package($2);
+ token_getmad($1,$$,'o');
+ token_getmad($3,$$,';');
+#else
+ package($2);
+ $$ = (OP*)NULL;
+#endif
+ }
+ ;
+
+use : USE startsub
+ { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
+ WORD WORD listexpr ';'
+ { SvREFCNT_inc_simple_void(PL_compcv);
+#ifdef MAD
+ $$ = utilize(IVAL($1), $2, $4, $5, $6);
+ token_getmad($1,$$,'o');
+ token_getmad($7,$$,';');
+ if (PL_parser->rsfp_filters &&
+ AvFILLp(PL_parser->rsfp_filters) >= 0)
+ append_madprops(newMADPROP('!', MAD_PV, "", 0), $$, 0);
+#else
+ utilize(IVAL($1), $2, $4, $5, $6);
+ $$ = (OP*)NULL;
+#endif
+ }
;
-term : '-' term %prec UMINUS
- { $$ = make_op(O_NEGATE, 1, $2, Nullarg, Nullarg); }
- | '+' term %prec UMINUS
- { $$ = $2; }
- | '!' term
- { $$ = make_op(O_NOT, 1, $2, Nullarg, Nullarg); }
- | '~' term
- { $$ = make_op(O_COMPLEMENT, 1, $2, Nullarg, Nullarg);}
- | term INC
- { $$ = addflags(1, AF_POST|AF_UP,
- l(make_op(O_ITEM,1,$1,Nullarg,Nullarg))); }
- | term DEC
- { $$ = addflags(1, AF_POST,
- l(make_op(O_ITEM,1,$1,Nullarg,Nullarg))); }
- | INC term
- { $$ = addflags(1, AF_PRE|AF_UP,
- l(make_op(O_ITEM,1,$2,Nullarg,Nullarg))); }
- | DEC term
- { $$ = addflags(1, AF_PRE,
- l(make_op(O_ITEM,1,$2,Nullarg,Nullarg))); }
- | FILETEST WORD
- { opargs[$1] = 0; /* force it special */
- $$ = make_op($1, 1,
- stab2arg(A_STAB,stabent($2,TRUE)),
- Nullarg, Nullarg);
- Safefree($2); $2 = Nullch;
- }
- | FILETEST sexpr
- { opargs[$1] = 1;
- $$ = make_op($1, 1, $2, Nullarg, Nullarg); }
- | FILETEST
- { opargs[$1] = ($1 != O_FTTTY);
- $$ = make_op($1, 1,
- stab2arg(A_STAB,
- $1 == O_FTTTY?stabent("STDIN",TRUE):defstab),
- Nullarg, Nullarg); }
- | LOCAL '(' expr crp
- { $$ = l(localize(make_op(O_ASSIGN, 1,
- localize(listish(make_list($3))),
- Nullarg,Nullarg))); }
- | '(' expr crp
- { $$ = make_list($2); }
+/* Ordinary expressions; logical combinations */
+expr : expr ANDOP expr
+ { $$ = newLOGOP(OP_AND, 0, $1, $3);
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | expr OROP expr
+ { $$ = newLOGOP(IVAL($2), 0, $1, $3);
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | expr DOROP expr
+ { $$ = newLOGOP(OP_DOR, 0, $1, $3);
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | argexpr %prec PREC_LOW
+ ;
+
+/* Expressions are a list of terms joined by commas */
+argexpr : argexpr ','
+ {
+#ifdef MAD
+ OP* op = newNULLLIST();
+ token_getmad($2,op,',');
+ $$ = append_elem(OP_LIST, $1, op);
+#else
+ $$ = $1;
+#endif
+ }
+ | argexpr ',' term
+ {
+ OP* term = $3;
+ DO_MAD(
+ term = newUNOP(OP_NULL, 0, term);
+ token_getmad($2,term,',');
+ )
+ $$ = append_elem(OP_LIST, $1, term);
+ }
+ | term %prec PREC_LOW
+ ;
+
+/* List operators */
+listop : LSTOP indirob argexpr /* map {...} @args or print $fh @args */
+ { $$ = convert(IVAL($1), OPf_STACKED,
+ prepend_elem(OP_LIST, newGVREF(IVAL($1),$2), $3) );
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | FUNC '(' indirob expr ')' /* print ($fh @args */
+ { $$ = convert(IVAL($1), OPf_STACKED,
+ prepend_elem(OP_LIST, newGVREF(IVAL($1),$3), $4) );
+ TOKEN_GETMAD($1,$$,'o');
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($5,$$,')');
+ }
+ | term ARROW method '(' listexprcom ')' /* $foo->bar(list) */
+ { $$ = convert(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST,
+ prepend_elem(OP_LIST, scalar($1), $5),
+ newUNOP(OP_METHOD, 0, $3)));
+ TOKEN_GETMAD($2,$$,'A');
+ TOKEN_GETMAD($4,$$,'(');
+ TOKEN_GETMAD($6,$$,')');
+ }
+ | term ARROW method /* $foo->bar */
+ { $$ = convert(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST, scalar($1),
+ newUNOP(OP_METHOD, 0, $3)));
+ TOKEN_GETMAD($2,$$,'A');
+ }
+ | METHOD indirob listexpr /* new Class @args */
+ { $$ = convert(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST,
+ prepend_elem(OP_LIST, $2, $3),
+ newUNOP(OP_METHOD, 0, $1)));
+ }
+ | FUNCMETH indirob '(' listexprcom ')' /* method $object (@args) */
+ { $$ = convert(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST,
+ prepend_elem(OP_LIST, $2, $4),
+ newUNOP(OP_METHOD, 0, $1)));
+ TOKEN_GETMAD($3,$$,'(');
+ TOKEN_GETMAD($5,$$,')');
+ }
+ | LSTOP listexpr /* print @args */
+ { $$ = convert(IVAL($1), 0, $2);
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | FUNC '(' listexprcom ')' /* print (@args) */
+ { $$ = convert(IVAL($1), 0, $3);
+ TOKEN_GETMAD($1,$$,'o');
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($4,$$,')');
+ }
+ | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
+ { SvREFCNT_inc_simple_void(PL_compcv);
+ $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
+ listexpr %prec LSTOP /* ... @bar */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST,
+ prepend_elem(OP_LIST, $<opval>4, $5), $1));
+ }
+ ;
+
+/* Names of methods. May use $object->$methodname */
+method : METHOD
+ | scalar
+ ;
+
+/* Some kind of subscripted expression */
+subscripted: star '{' expr ';' '}' /* *main::{something} */
+ /* In this and all the hash accessors, ';' is
+ * provided by the tokeniser */
+ { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3));
+ PL_parser->expect = XOPERATOR;
+ TOKEN_GETMAD($2,$$,'{');
+ TOKEN_GETMAD($4,$$,';');
+ TOKEN_GETMAD($5,$$,'}');
+ }
+ | scalar '[' expr ']' /* $array[$element] */
+ { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
+ TOKEN_GETMAD($2,$$,'[');
+ TOKEN_GETMAD($4,$$,']');
+ }
+ | term ARROW '[' expr ']' /* somearef->[$element] */
+ { $$ = newBINOP(OP_AELEM, 0,
+ ref(newAVREF($1),OP_RV2AV),
+ scalar($4));
+ TOKEN_GETMAD($2,$$,'a');
+ TOKEN_GETMAD($3,$$,'[');
+ TOKEN_GETMAD($5,$$,']');
+ }
+ | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
+ { $$ = newBINOP(OP_AELEM, 0,
+ ref(newAVREF($1),OP_RV2AV),
+ scalar($3));
+ TOKEN_GETMAD($2,$$,'[');
+ TOKEN_GETMAD($4,$$,']');
+ }
+ | scalar '{' expr ';' '}' /* $foo->{bar();} */
+ { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
+ PL_parser->expect = XOPERATOR;
+ TOKEN_GETMAD($2,$$,'{');
+ TOKEN_GETMAD($4,$$,';');
+ TOKEN_GETMAD($5,$$,'}');
+ }
+ | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
+ { $$ = newBINOP(OP_HELEM, 0,
+ ref(newHVREF($1),OP_RV2HV),
+ jmaybe($4));
+ PL_parser->expect = XOPERATOR;
+ TOKEN_GETMAD($2,$$,'a');
+ TOKEN_GETMAD($3,$$,'{');
+ TOKEN_GETMAD($5,$$,';');
+ TOKEN_GETMAD($6,$$,'}');
+ }
+ | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
+ { $$ = newBINOP(OP_HELEM, 0,
+ ref(newHVREF($1),OP_RV2HV),
+ jmaybe($3));
+ PL_parser->expect = XOPERATOR;
+ TOKEN_GETMAD($2,$$,'{');
+ TOKEN_GETMAD($4,$$,';');
+ TOKEN_GETMAD($5,$$,'}');
+ }
+ | term ARROW '(' ')' /* $subref->() */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
+ newCVREF(0, scalar($1)));
+ TOKEN_GETMAD($2,$$,'a');
+ TOKEN_GETMAD($3,$$,'(');
+ TOKEN_GETMAD($4,$$,')');
+ }
+ | term ARROW '(' expr ')' /* $subref->(@args) */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST, $4,
+ newCVREF(0, scalar($1))));
+ TOKEN_GETMAD($2,$$,'a');
+ TOKEN_GETMAD($3,$$,'(');
+ TOKEN_GETMAD($5,$$,')');
+ }
+
+ | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST, $3,
+ newCVREF(0, scalar($1))));
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($4,$$,')');
+ }
+ | subscripted '(' ')' /* $foo->{bar}->() */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
+ newCVREF(0, scalar($1)));
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($3,$$,')');
+ }
+ | '(' expr ')' '[' expr ']' /* list slice */
+ { $$ = newSLICEOP(0, $5, $2);
+ TOKEN_GETMAD($1,$$,'(');
+ TOKEN_GETMAD($3,$$,')');
+ TOKEN_GETMAD($4,$$,'[');
+ TOKEN_GETMAD($6,$$,']');
+ }
+ | '(' ')' '[' expr ']' /* empty list slice! */
+ { $$ = newSLICEOP(0, $4, (OP*)NULL);
+ TOKEN_GETMAD($1,$$,'(');
+ TOKEN_GETMAD($2,$$,')');
+ TOKEN_GETMAD($3,$$,'[');
+ TOKEN_GETMAD($5,$$,']');
+ }
+ ;
+
+/* Binary operators between terms */
+termbinop: term ASSIGNOP term /* $x = $y */
+ { $$ = newASSIGNOP(OPf_STACKED, $1, IVAL($2), $3);
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term POWOP term /* $x ** $y */
+ { $$ = newBINOP(IVAL($2), 0, scalar($1), scalar($3));
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term MULOP term /* $x * $y, $x x $y */
+ { if (IVAL($2) != OP_REPEAT)
+ scalar($1);
+ $$ = newBINOP(IVAL($2), 0, $1, scalar($3));
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term ADDOP term /* $x + $y */
+ { $$ = newBINOP(IVAL($2), 0, scalar($1), scalar($3));
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term SHIFTOP term /* $x >> $y, $x << $y */
+ { $$ = newBINOP(IVAL($2), 0, scalar($1), scalar($3));
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term RELOP term /* $x > $y, etc. */
+ { $$ = newBINOP(IVAL($2), 0, scalar($1), scalar($3));
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term EQOP term /* $x == $y, $x eq $y */
+ { $$ = newBINOP(IVAL($2), 0, scalar($1), scalar($3));
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term BITANDOP term /* $x & $y */
+ { $$ = newBINOP(IVAL($2), 0, scalar($1), scalar($3));
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term BITOROP term /* $x | $y */
+ { $$ = newBINOP(IVAL($2), 0, scalar($1), scalar($3));
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term DOTDOT term /* $x..$y, $x...$y */
+ {
+ $$ = newRANGE(IVAL($2), scalar($1), scalar($3));
+ DO_MAD({
+ UNOP *op;
+ op = (UNOP*)$$;
+ op = (UNOP*)op->op_first; /* get to flop */
+ op = (UNOP*)op->op_first; /* get to flip */
+ op = (UNOP*)op->op_first; /* get to range */
+ token_getmad($2,(OP*)op,'o');
+ })
+ }
+ | term ANDAND term /* $x && $y */
+ { $$ = newLOGOP(OP_AND, 0, $1, $3);
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term OROR term /* $x || $y */
+ { $$ = newLOGOP(OP_OR, 0, $1, $3);
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term DORDOR term /* $x // $y */
+ { $$ = newLOGOP(OP_DOR, 0, $1, $3);
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term MATCHOP term /* $x =~ /$y/ */
+ { $$ = bind_match(IVAL($2), $1, $3);
+ TOKEN_GETMAD($2,
+ ($$->op_type == OP_NOT
+ ? ((UNOP*)$$)->op_first : $$),
+ '~');
+ }
+ ;
+
+/* Unary operators and terms */
+termunop : '-' term %prec UMINUS /* -$x */
+ { $$ = newUNOP(OP_NEGATE, 0, scalar($2));
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | '+' term %prec UMINUS /* +$x */
+ { $$ = IF_MAD(
+ newUNOP(OP_NULL, 0, $2),
+ $2
+ );
+ TOKEN_GETMAD($1,$$,'+');
+ }
+ | '!' term /* !$x */
+ { $$ = newUNOP(OP_NOT, 0, scalar($2));
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | '~' term /* ~$x */
+ { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2));
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | term POSTINC /* $x++ */
+ { $$ = newUNOP(OP_POSTINC, 0,
+ mod(scalar($1), OP_POSTINC));
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | term POSTDEC /* $x-- */
+ { $$ = newUNOP(OP_POSTDEC, 0,
+ mod(scalar($1), OP_POSTDEC));
+ TOKEN_GETMAD($2,$$,'o');
+ }
+ | PREINC term /* ++$x */
+ { $$ = newUNOP(OP_PREINC, 0,
+ mod(scalar($2), OP_PREINC));
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | PREDEC term /* --$x */
+ { $$ = newUNOP(OP_PREDEC, 0,
+ mod(scalar($2), OP_PREDEC));
+ TOKEN_GETMAD($1,$$,'o');
+ }
+
+ ;
+
+/* Constructors for anonymous data */
+anonymous: '[' expr ']'
+ { $$ = newANONLIST($2);
+ TOKEN_GETMAD($1,$$,'[');
+ TOKEN_GETMAD($3,$$,']');
+ }
+ | '[' ']'
+ { $$ = newANONLIST((OP*)NULL);
+ TOKEN_GETMAD($1,$$,'[');
+ TOKEN_GETMAD($2,$$,']');
+ }
+ | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
+ { $$ = newANONHASH($2);
+ TOKEN_GETMAD($1,$$,'{');
+ TOKEN_GETMAD($3,$$,';');
+ TOKEN_GETMAD($4,$$,'}');
+ }
+ | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
+ { $$ = newANONHASH((OP*)NULL);
+ TOKEN_GETMAD($1,$$,'{');
+ TOKEN_GETMAD($2,$$,';');
+ TOKEN_GETMAD($3,$$,'}');
+ }
+ | ANONSUB startanonsub proto subattrlist block %prec '('
+ { SvREFCNT_inc_simple_void(PL_compcv);
+ $$ = newANONATTRSUB($2, $3, $4, $5);
+ TOKEN_GETMAD($1,$$,'o');
+ OP_GETMAD($3,$$,'s');
+ OP_GETMAD($4,$$,'a');
+ }
+
+ ;
+
+/* Things called with "do" */
+termdo : DO term %prec UNIOP /* do $filename */
+ { $$ = dofile($2, IVAL($1));
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | DO block %prec '(' /* do { code */
+ { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2));
+ TOKEN_GETMAD($1,$$,'D');
+ }
+ | DO WORD '(' ')' /* do somesub() */
+ { $$ = newUNOP(OP_ENTERSUB,
+ OPf_SPECIAL|OPf_STACKED,
+ prepend_elem(OP_LIST,
+ scalar(newCVREF(
+ (OPpENTERSUB_AMPER<<8),
+ scalar($2)
+ )),(OP*)NULL)); dep();
+ TOKEN_GETMAD($1,$$,'o');
+ TOKEN_GETMAD($3,$$,'(');
+ TOKEN_GETMAD($4,$$,')');
+ }
+ | DO WORD '(' expr ')' /* do somesub(@args) */
+ { $$ = newUNOP(OP_ENTERSUB,
+ OPf_SPECIAL|OPf_STACKED,
+ append_elem(OP_LIST,
+ $4,
+ scalar(newCVREF(
+ (OPpENTERSUB_AMPER<<8),
+ scalar($2)
+ )))); dep();
+ TOKEN_GETMAD($1,$$,'o');
+ TOKEN_GETMAD($3,$$,'(');
+ TOKEN_GETMAD($5,$$,')');
+ }
+ | DO scalar '(' ')' /* do $subref () */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
+ prepend_elem(OP_LIST,
+ scalar(newCVREF(0,scalar($2))), (OP*)NULL)); dep();
+ TOKEN_GETMAD($1,$$,'o');
+ TOKEN_GETMAD($3,$$,'(');
+ TOKEN_GETMAD($4,$$,')');
+ }
+ | DO scalar '(' expr ')' /* do $subref (@args) */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
+ prepend_elem(OP_LIST,
+ $4,
+ scalar(newCVREF(0,scalar($2))))); dep();
+ TOKEN_GETMAD($1,$$,'o');
+ TOKEN_GETMAD($3,$$,'(');
+ TOKEN_GETMAD($5,$$,')');
+ }
+
+ ;
+
+term : termbinop
+ | termunop
+ | anonymous
+ | termdo
+ | term '?' term ':' term
+ { $$ = newCONDOP(0, $1, $3, $5);
+ TOKEN_GETMAD($2,$$,'?');
+ TOKEN_GETMAD($4,$$,':');
+ }
+ | REFGEN term /* \$x, \@y, \%z */
+ { $$ = newUNOP(OP_REFGEN, 0, mod($2,OP_REFGEN));
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | myattrterm %prec UNIOP
+ { $$ = $1; }
+ | LOCAL term %prec UNIOP
+ { $$ = localize($2,IVAL($1));
+ TOKEN_GETMAD($1,$$,'k');
+ }
+ | '(' expr ')'
+ { $$ = sawparens(IF_MAD(newUNOP(OP_NULL,0,$2), $2));
+ TOKEN_GETMAD($1,$$,'(');
+ TOKEN_GETMAD($3,$$,')');
+ }
| '(' ')'
- { $$ = make_list(Nullarg); }
- | DO sexpr %prec FILETEST
- { $$ = make_op(O_DOFILE,2,$2,Nullarg,Nullarg);
- allstabs = TRUE;}
- | DO block %prec '('
- { $$ = cmd_to_arg($2); }
- | REG %prec '('
- { $$ = stab2arg(A_STAB,$1); }
- | STAR %prec '('
- { $$ = stab2arg(A_STAR,$1); }
- | REG '[' expr ']' %prec '('
- { $$ = make_op(O_AELEM, 2,
- stab2arg(A_STAB,aadd($1)), $3, Nullarg); }
- | HSH %prec '('
- { $$ = make_op(O_HASH, 1,
- stab2arg(A_STAB,$1),
- Nullarg, Nullarg); }
- | ARY %prec '('
- { $$ = make_op(O_ARRAY, 1,
- stab2arg(A_STAB,$1),
- Nullarg, Nullarg); }
- | REG '{' expr ';' '}' %prec '('
- { $$ = make_op(O_HELEM, 2,
- stab2arg(A_STAB,hadd($1)),
- jmaybe($3),
- Nullarg);
- expectterm = FALSE; }
- | '(' expr crp '[' expr ']' %prec '('
- { $$ = make_op(O_LSLICE, 3,
- Nullarg,
- listish(make_list($5)),
- listish(make_list($2))); }
- | '(' ')' '[' expr ']' %prec '('
- { $$ = make_op(O_LSLICE, 3,
- Nullarg,
- listish(make_list($4)),
- Nullarg); }
- | ARY '[' expr ']' %prec '('
- { $$ = make_op(O_ASLICE, 2,
- stab2arg(A_STAB,aadd($1)),
- listish(make_list($3)),
- Nullarg); }
- | ARY '{' expr ';' '}' %prec '('
- { $$ = make_op(O_HSLICE, 2,
- stab2arg(A_STAB,hadd($1)),
- listish(make_list($3)),
- Nullarg);
- expectterm = FALSE; }
- | DELETE REG '{' expr ';' '}' %prec '('
- { $$ = make_op(O_DELETE, 2,
- stab2arg(A_STAB,hadd($2)),
- jmaybe($4),
- Nullarg);
- expectterm = FALSE; }
- | DELETE '(' REG '{' expr ';' '}' ')' %prec '('
- { $$ = make_op(O_DELETE, 2,
- stab2arg(A_STAB,hadd($3)),
- jmaybe($4),
- Nullarg);
- expectterm = FALSE; }
- | ARYLEN %prec '('
- { $$ = stab2arg(A_ARYLEN,$1); }
- | RSTRING %prec '('
+ { $$ = sawparens(newNULLLIST());
+ TOKEN_GETMAD($1,$$,'(');
+ TOKEN_GETMAD($2,$$,')');
+ }
+ | scalar %prec '('
+ { $$ = $1; }
+ | star %prec '('
{ $$ = $1; }
- | PATTERN %prec '('
+ | hsh %prec '('
{ $$ = $1; }
- | SUBST %prec '('
+ | ary %prec '('
{ $$ = $1; }
- | TRANS %prec '('
+ | arylen %prec '(' /* $#x, $#{ something } */
+ { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
+ | subscripted
+ { $$ = $1; }
+ | ary '[' expr ']' /* array slice */
+ { $$ = prepend_elem(OP_ASLICE,
+ newOP(OP_PUSHMARK, 0),
+ newLISTOP(OP_ASLICE, 0,
+ list($3),
+ ref($1, OP_ASLICE)));
+ TOKEN_GETMAD($2,$$,'[');
+ TOKEN_GETMAD($4,$$,']');
+ }
+ | ary '{' expr ';' '}' /* @hash{@keys} */
+ { $$ = prepend_elem(OP_HSLICE,
+ newOP(OP_PUSHMARK, 0),
+ newLISTOP(OP_HSLICE, 0,
+ list($3),
+ ref(oopsHV($1), OP_HSLICE)));
+ PL_parser->expect = XOPERATOR;
+ TOKEN_GETMAD($2,$$,'{');
+ TOKEN_GETMAD($4,$$,';');
+ TOKEN_GETMAD($5,$$,'}');
+ }
+ | THING %prec '('
{ $$ = $1; }
- | DO WORD '(' expr crp
- { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
- stab2arg(A_WORD,stabent($2,MULTI)),
- make_list($4),
- Nullarg); Safefree($2); $2 = Nullch;
- $$->arg_flags |= AF_DEPR; }
- | AMPER WORD '(' expr crp
- { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
- stab2arg(A_WORD,stabent($2,MULTI)),
- make_list($4),
- Nullarg); Safefree($2); $2 = Nullch; }
- | DO WORD '(' ')'
- { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
- stab2arg(A_WORD,stabent($2,MULTI)),
- make_list(Nullarg),
- Nullarg);
- Safefree($2); $2 = Nullch;
- $$->arg_flags |= AF_DEPR; }
- | AMPER WORD '(' ')'
- { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
- stab2arg(A_WORD,stabent($2,MULTI)),
- make_list(Nullarg),
- Nullarg);
- Safefree($2); $2 = Nullch;
- }
- | AMPER WORD
- { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
- stab2arg(A_WORD,stabent($2,MULTI)),
- Nullarg,
- Nullarg);
- Safefree($2); $2 = Nullch;
- }
- | DO REG '(' expr crp
- { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
- stab2arg(A_STAB,$2),
- make_list($4),
- Nullarg);
- $$->arg_flags |= AF_DEPR; }
- | AMPER REG '(' expr crp
- { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
- stab2arg(A_STAB,$2),
- make_list($4),
- Nullarg); }
- | DO REG '(' ')'
- { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
- stab2arg(A_STAB,$2),
- make_list(Nullarg),
- Nullarg);
- $$->arg_flags |= AF_DEPR; }
- | AMPER REG '(' ')'
- { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
- stab2arg(A_STAB,$2),
- make_list(Nullarg),
- Nullarg); }
- | AMPER REG
- { $$ = make_op((perldb ? O_DBSUBR : O_SUBR), 2,
- stab2arg(A_STAB,$2),
- Nullarg,
- Nullarg); }
- | LOOPEX
- { $$ = make_op($1,0,Nullarg,Nullarg,Nullarg); }
- | LOOPEX WORD
- { $$ = make_op($1,1,cval_to_arg($2),
- Nullarg,Nullarg); }
- | UNIOP
- { $$ = make_op($1,0,Nullarg,Nullarg,Nullarg); }
- | UNIOP block
- { $$ = make_op($1,1,cmd_to_arg($2),Nullarg,Nullarg); }
- | UNIOP sexpr
- { $$ = make_op($1,1,$2,Nullarg,Nullarg); }
- | SSELECT
- { $$ = make_op(O_SELECT, 0, Nullarg, Nullarg, Nullarg);}
- | SSELECT WORD
- { $$ = make_op(O_SELECT, 1,
- stab2arg(A_WORD,stabent($2,TRUE)),
- Nullarg,
- Nullarg);
- Safefree($2); $2 = Nullch; }
- | SSELECT '(' handle ')'
- { $$ = make_op(O_SELECT, 1, $3, Nullarg, Nullarg); }
- | SSELECT '(' sexpr csexpr csexpr csexpr ')'
- { arg4 = $6;
- $$ = make_op(O_SSELECT, 4, $3, $4, $5); }
- | OPEN WORD %prec '('
- { $$ = make_op(O_OPEN, 2,
- stab2arg(A_WORD,stabent($2,TRUE)),
- stab2arg(A_STAB,stabent($2,TRUE)),
- Nullarg);
- Safefree($2); $2 = Nullch;
- }
- | OPEN '(' WORD ')'
- { $$ = make_op(O_OPEN, 2,
- stab2arg(A_WORD,stabent($3,TRUE)),
- stab2arg(A_STAB,stabent($3,TRUE)),
- Nullarg);
- Safefree($3); $3 = Nullch;
- }
- | OPEN '(' handle cexpr ')'
- { $$ = make_op(O_OPEN, 2,
- $3,
- $4, Nullarg); }
- | FILOP '(' handle ')'
- { $$ = make_op($1, 1,
- $3,
- Nullarg, Nullarg); }
- | FILOP WORD
- { $$ = make_op($1, 1,
- stab2arg(A_WORD,stabent($2,TRUE)),
- Nullarg, Nullarg);
- Safefree($2); $2 = Nullch; }
- | FILOP REG
- { $$ = make_op($1, 1,
- stab2arg(A_STAB,$2),
- Nullarg, Nullarg); }
- | FILOP '(' ')'
- { $$ = make_op($1, 1,
- stab2arg(A_WORD,Nullstab),
- Nullarg, Nullarg); }
- | FILOP %prec '('
- { $$ = make_op($1, 0,
- Nullarg, Nullarg, Nullarg); }
- | FILOP2 '(' handle cexpr ')'
- { $$ = make_op($1, 2, $3, $4, Nullarg); }
- | FILOP3 '(' handle csexpr cexpr ')'
- { $$ = make_op($1, 3, $3, $4, make_list($5)); }
- | FILOP22 '(' handle ',' handle ')'
- { $$ = make_op($1, 2, $3, $5, Nullarg); }
- | FILOP4 '(' handle csexpr csexpr cexpr ')'
- { arg4 = $6; $$ = make_op($1, 4, $3, $4, $5); }
- | FILOP25 '(' handle ',' handle csexpr csexpr cexpr ')'
- { arg4 = $7; arg5 = $8;
- $$ = make_op($1, 5, $3, $5, $6); }
- | PUSH '(' aryword ',' expr crp
- { $$ = make_op($1, 2,
- $3,
- make_list($5),
- Nullarg); }
- | POP aryword %prec '('
- { $$ = make_op(O_POP, 1, $2, Nullarg, Nullarg); }
- | POP '(' aryword ')'
- { $$ = make_op(O_POP, 1, $3, Nullarg, Nullarg); }
- | SHIFT aryword %prec '('
- { $$ = make_op(O_SHIFT, 1, $2, Nullarg, Nullarg); }
- | SHIFT '(' aryword ')'
- { $$ = make_op(O_SHIFT, 1, $3, Nullarg, Nullarg); }
- | SHIFT %prec '('
- { $$ = make_op(O_SHIFT, 1,
- stab2arg(A_STAB,
- aadd(stabent(subline ? "_" : "ARGV", TRUE))),
- Nullarg, Nullarg); }
- | SPLIT %prec '('
- { static char p[]="/\\s+/";
- char *oldend = bufend;
- ARG *oldarg = yylval.arg;
-
- bufend=p+5;
- (void)scanpat(p);
- bufend=oldend;
- $$ = make_split(defstab,yylval.arg,Nullarg);
- yylval.arg = oldarg; }
- | SPLIT '(' sexpr csexpr csexpr ')'
- { $$ = mod_match(O_MATCH, $4,
- make_split(defstab,$3,$5));}
- | SPLIT '(' sexpr csexpr ')'
- { $$ = mod_match(O_MATCH, $4,
- make_split(defstab,$3,Nullarg) ); }
- | SPLIT '(' sexpr ')'
- { $$ = mod_match(O_MATCH,
- stab2arg(A_STAB,defstab),
- make_split(defstab,$3,Nullarg) ); }
- | FLIST2 '(' sexpr cexpr ')'
- { $$ = make_op($1, 2,
- $3,
- listish(make_list($4)),
- Nullarg); }
- | FLIST '(' expr crp
- { $$ = make_op($1, 1,
- make_list($3),
- Nullarg,
- Nullarg); }
- | LVALFUN sexpr %prec '('
- { $$ = l(make_op($1, 1, fixl($1,$2),
- Nullarg, Nullarg)); }
- | LVALFUN
- { $$ = l(make_op($1, 1,
- stab2arg(A_STAB,defstab),
- Nullarg, Nullarg)); }
- | FUNC0
- { $$ = make_op($1, 0, Nullarg, Nullarg, Nullarg); }
+ | amper /* &foo; */
+ { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
+ | amper '(' ')' /* &foo() */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($3,$$,')');
+ }
+ | amper '(' expr ')' /* &foo(@args) */
+ {
+ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST, $3, scalar($1)));
+ DO_MAD({
+ OP* op = $$;
+ if (op->op_type == OP_CONST) { /* defeat const fold */
+ op = (OP*)op->op_madprop->mad_val;
+ }
+ token_getmad($2,op,'(');
+ token_getmad($4,op,')');
+ })
+ }
+ | NOAMP WORD listexpr /* foo(@args) */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST, $3, scalar($2)));
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | LOOPEX /* loop exiting command (goto, last, dump, etc) */
+ { $$ = newOP(IVAL($1), OPf_SPECIAL);
+ PL_hints |= HINT_BLOCK_SCOPE;
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | LOOPEX term
+ { $$ = newLOOPEX(IVAL($1),$2);
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | NOTOP argexpr /* not $foo */
+ { $$ = newUNOP(OP_NOT, 0, scalar($2));
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | UNIOP /* Unary op, $_ implied */
+ { $$ = newOP(IVAL($1), 0);
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | UNIOP block /* eval { foo }* */
+ { $$ = newUNOP(IVAL($1), 0, $2);
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | UNIOP term /* Unary op */
+ { $$ = newUNOP(IVAL($1), 0, $2);
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | REQUIRE /* require, $_ implied */
+ { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0);
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | REQUIRE term /* require Foo */
+ { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2);
+ TOKEN_GETMAD($1,$$,'o');
+ }
+ | UNIOPSUB
+ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
+ | UNIOPSUB term /* Sub treated as unop */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
+ append_elem(OP_LIST, $2, scalar($1))); }
+ | FUNC0 /* Nullary operator */
+ { $$ = newOP(IVAL($1), 0);
+ TOKEN_GETMAD($1,$$,'o');
+ }
| FUNC0 '(' ')'
- { $$ = make_op($1, 0, Nullarg, Nullarg, Nullarg); }
- | FUNC1 '(' ')'
- { $$ = make_op($1, 0, Nullarg, Nullarg, Nullarg); }
- | FUNC1 '(' expr ')'
- { $$ = make_op($1, 1, $3, Nullarg, Nullarg); }
- | FUNC2 '(' sexpr cexpr ')'
- { $$ = make_op($1, 2, $3, $4, Nullarg);
- if ($1 == O_INDEX && $$[2].arg_type == A_SINGLE)
- fbmcompile($$[2].arg_ptr.arg_str,0); }
- | FUNC2x '(' sexpr csexpr ')'
- { $$ = make_op($1, 2, $3, $4, Nullarg);
- if ($1 == O_INDEX && $$[2].arg_type == A_SINGLE)
- fbmcompile($$[2].arg_ptr.arg_str,0); }
- | FUNC2x '(' sexpr csexpr cexpr ')'
- { $$ = make_op($1, 3, $3, $4, $5);
- if ($1 == O_INDEX && $$[2].arg_type == A_SINGLE)
- fbmcompile($$[2].arg_ptr.arg_str,0); }
- | FUNC3 '(' sexpr csexpr cexpr ')'
- { $$ = make_op($1, 3, $3, $4, $5); }
- | FUNC4 '(' sexpr csexpr csexpr cexpr ')'
- { arg4 = $6;
- $$ = make_op($1, 4, $3, $4, $5); }
- | FUNC5 '(' sexpr csexpr csexpr csexpr cexpr ')'
- { arg4 = $6; arg5 = $7;
- $$ = make_op($1, 5, $3, $4, $5); }
- | HSHFUN '(' hshword ')'
- { $$ = make_op($1, 1,
- $3,
- Nullarg,
- Nullarg); }
- | HSHFUN hshword
- { $$ = make_op($1, 1,
- $2,
- Nullarg,
- Nullarg); }
- | HSHFUN3 '(' hshword csexpr cexpr ')'
- { $$ = make_op($1, 3, $3, $4, $5); }
- | bareword
+ { $$ = newOP(IVAL($1), 0);
+ TOKEN_GETMAD($1,$$,'o');
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($3,$$,')');
+ }
+ | FUNC0SUB /* Sub treated as nullop */
+ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
+ scalar($1)); }
+ | FUNC1 '(' ')' /* not () */
+ { $$ = (IVAL($1) == OP_NOT)
+ ? newUNOP(IVAL($1), 0, newSVOP(OP_CONST, 0, newSViv(0)))
+ : newOP(IVAL($1), OPf_SPECIAL);
+
+ TOKEN_GETMAD($1,$$,'o');
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($3,$$,')');
+ }
+ | FUNC1 '(' expr ')' /* not($foo) */
+ { $$ = newUNOP(IVAL($1), 0, $3);
+ TOKEN_GETMAD($1,$$,'o');
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($4,$$,')');
+ }
+ | PMFUNC '(' argexpr ')' /* m//, s///, tr/// */
+ { $$ = pmruntime($1, $3, 1);
+ TOKEN_GETMAD($2,$$,'(');
+ TOKEN_GETMAD($4,$$,')');
+ }
+ | WORD
| listop
+ | YADAYADA
+ {
+ $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
+ newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
+ }
;
-listop : LISTOP
- { $$ = make_op($1,2,
- stab2arg(A_WORD,Nullstab),
- stab2arg(A_STAB,defstab),
- Nullarg); }
- | LISTOP expr
- { $$ = make_op($1,2,
- stab2arg(A_WORD,Nullstab),
- maybelistish($1,make_list($2)),
- Nullarg); }
- | LISTOP WORD
- { $$ = make_op($1,2,
- stab2arg(A_WORD,stabent($2,TRUE)),
- stab2arg(A_STAB,defstab),
- Nullarg);
- Safefree($2); $2 = Nullch;
- }
- | LISTOP WORD expr
- { $$ = make_op($1,2,
- stab2arg(A_WORD,stabent($2,TRUE)),
- maybelistish($1,make_list($3)),
- Nullarg); Safefree($2); $2 = Nullch; }
- | LISTOP REG expr
- { $$ = make_op($1,2,
- stab2arg(A_STAB,$2),
- maybelistish($1,make_list($3)),
- Nullarg); }
- | LISTOP block expr
- { $$ = make_op($1,2,
- cmd_to_arg($2),
- maybelistish($1,make_list($3)),
- Nullarg); }
- ;
-
-handle : WORD
- { $$ = stab2arg(A_WORD,stabent($1,TRUE));
- Safefree($1); $1 = Nullch;}
- | sexpr
- ;
-
-aryword : WORD
- { $$ = stab2arg(A_WORD,aadd(stabent($1,TRUE)));
- Safefree($1); $1 = Nullch; }
- | ARY
- { $$ = stab2arg(A_STAB,$1); }
- ;
-
-hshword : WORD
- { $$ = stab2arg(A_WORD,hadd(stabent($1,TRUE)));
- Safefree($1); $1 = Nullch; }
- | HSH
- { $$ = stab2arg(A_STAB,$1); }
- ;
-
-crp : ',' ')'
- { $$ = 1; }
- | ')'
- { $$ = 0; }
+/* "my" declarations, with optional attributes */
+myattrterm: MY myterm myattrlist
+ { $$ = my_attrs($2,$3);
+ DO_MAD(
+ token_getmad($1,$$,'d');
+ append_madprops($3->op_madprop, $$, 'a');
+ $3->op_madprop = 0;
+ )
+ }
+ | MY myterm
+ { $$ = localize($2,IVAL($1));
+ TOKEN_GETMAD($1,$$,'d');
+ }
;
-/*
- * NOTE: The following entry must stay at the end of the file so that
- * reduce/reduce conflicts resolve to it only if it's the only option.
- */
+/* Things that can be "my"'d */
+myterm : '(' expr ')'
+ { $$ = sawparens($2);
+ TOKEN_GETMAD($1,$$,'(');
+ TOKEN_GETMAD($3,$$,')');
+ }
+ | '(' ')'
+ { $$ = sawparens(newNULLLIST());
+ TOKEN_GETMAD($1,$$,'(');
+ TOKEN_GETMAD($2,$$,')');
+ }
+ | scalar %prec '('
+ { $$ = $1; }
+ | hsh %prec '('
+ { $$ = $1; }
+ | ary %prec '('
+ { $$ = $1; }
+ ;
+
+/* Basic list expressions */
+listexpr: /* NULL */ %prec PREC_LOW
+ { $$ = (OP*)NULL; }
+ | argexpr %prec PREC_LOW
+ { $$ = $1; }
+ ;
+
+listexprcom: /* NULL */
+ { $$ = (OP*)NULL; }
+ | expr
+ { $$ = $1; }
+ | expr ','
+ {
+#ifdef MAD
+ OP* op = newNULLLIST();
+ token_getmad($2,op,',');
+ $$ = append_elem(OP_LIST, $1, op);
+#else
+ $$ = $1;
+#endif
+
+ }
+ ;
+
+/* A little bit of trickery to make "for my $foo (@bar)" actually be
+ lexical */
+my_scalar: scalar
+ { PL_parser->in_my = 0; $$ = my($1); }
+ ;
+
+amper : '&' indirob
+ { $$ = newCVREF(IVAL($1),$2);
+ TOKEN_GETMAD($1,$$,'&');
+ }
+ ;
-bareword: WORD
- { char *s;
- $$ = op_new(1);
- $$->arg_type = O_ITEM;
- $$[1].arg_type = A_SINGLE;
- $$[1].arg_ptr.arg_str = str_make($1,0);
- for (s = $1; *s && isLOWER(*s); s++) ;
- if (dowarn && !*s)
- warn(
- "\"%s\" may clash with future reserved word",
- $1 );
- Safefree($1); $1 = Nullch;
- }
- ;
-%% /* PROGRAM */
+scalar : '$' indirob
+ { $$ = newSVREF($2);
+ TOKEN_GETMAD($1,$$,'$');
+ }
+ ;
+
+ary : '@' indirob
+ { $$ = newAVREF($2);
+ TOKEN_GETMAD($1,$$,'@');
+ }
+ ;
+
+hsh : '%' indirob
+ { $$ = newHVREF($2);
+ TOKEN_GETMAD($1,$$,'%');
+ }
+ ;
+
+arylen : DOLSHARP indirob
+ { $$ = newAVREF($2);
+ TOKEN_GETMAD($1,$$,'l');
+ }
+ ;
+
+star : '*' indirob
+ { $$ = newGVREF(0,$2);
+ TOKEN_GETMAD($1,$$,'*');
+ }
+ ;
+
+/* Indirect objects */
+indirob : WORD
+ { $$ = scalar($1); }
+ | scalar %prec PREC_LOW
+ { $$ = scalar($1); }
+ | block
+ { $$ = scope($1); }
+
+ | PRIVATEREF
+ { $$ = $1; }
+ ;