From: Nicholas Clark Date: Fri, 10 Mar 2006 18:52:40 +0000 (+0000) Subject: Merge perly.y changes from 5.9.2 to now into madly.y. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=733849fa5cd712d80d0a3b77d0117b1e26dd6891;p=p5sagit%2Fp5-mst-13.2.git Merge perly.y changes from 5.9.2 to now into madly.y. p4raw-id: //depot/perl@27462 --- diff --git a/madly.y b/madly.y index 576319f..f10bf35 100644 --- a/madly.y +++ b/madly.y @@ -14,6 +14,7 @@ /* Make the parser re-entrant. */ +/* FIXME for MAD - is the new mintro on while and until important? */ %pure_parser %start prog @@ -33,15 +34,18 @@ %token LABEL %token FORMAT SUB ANONSUB PACKAGE USE %token WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR +%token GIVEN WHEN DEFAULT %token LOOPEX DOTDOT %token FUNC0 FUNC1 FUNC UNIOP LSTOP %token RELOP EQOP MULOP ADDOP %token DOLSHARP DO HASHBRACK NOAMP -%token LOCAL MY MYSUB +%token LOCAL MY MYSUB REQUIRE %token COLONATTR %type prog progstart remember mremember savescope -%type startsub startanonsub startformsub mintro +%type startsub startanonsub startformsub +/* FIXME for MAD - are these two ival? */ +%type mydefsv mintro %type '&' ';' @@ -54,6 +58,7 @@ %type formname subname proto subbody cont my_scalar %type subattrlist myattrlist myattrterm myterm %type termbinop termunop anonymous termdo +%type switch case %type label %nonassoc PREC_LOW @@ -74,6 +79,7 @@ %nonassoc EQOP %nonassoc RELOP %nonassoc UNIOP UNIOPSUB +%nonassoc REQUIRE %left SHIFTOP %left ADDOP %left MULOP @@ -110,6 +116,10 @@ remember: /* NULL */ /* start a full lexical scope */ { $$ = block_start(TRUE); } ; +mydefsv: /* NULL */ /* lexicalize $_ */ + { $$ = (I32) allocmy("$_"); } + ; + progstart: { PL_expect = XSTATE; $$ = block_start(TRUE); @@ -153,6 +163,10 @@ line : label cond { $$ = newSTATEOP(0, ($1)->tk_lval.pval, $2); token_getmad($1,((LISTOP*)$$)->op_first,'L'); } | loop /* loops add their own labels */ + | switch /* ... and so do switches */ + { $$ = $1; } + | label case + { $$ = newSTATEOP(0, ($1)->tk_lval.pval, $2); } | label ';' { if (($1)->tk_lval.pval) { @@ -248,6 +262,14 @@ cond : IF '(' remember mexpr ')' mblock else } ; +/* 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 */ { $$ = Nullop; } @@ -261,7 +283,7 @@ cont : /* NULL */ loop : label WHILE '(' remember texpr ')' mintro mblock cont { OP *innerop; PL_copline = (line_t)$2; - $$ = block_end($4, + $$ = block_end($4, newSTATEOP(0, ($1)->tk_lval.pval, innerop = newWHILEOP(0, 1, (LOOP*)Nullop, ($2)->tk_lval.ival, $5, $8, $9, $7))); @@ -270,12 +292,13 @@ loop : label WHILE '(' remember texpr ')' mintro mblock cont token_getmad($3,innerop,'('); token_getmad($6,innerop,')'); } + | label UNTIL '(' remember iexpr ')' mintro mblock cont { OP *innerop; PL_copline = (line_t)$2; - $$ = block_end($4, + $$ = block_end($4, newSTATEOP(0, ($1)->tk_lval.pval, - innerop = newWHILEOP(0, 1, (LOOP*)Nullop, + newWHILEOP(0, 1, (LOOP*)Nullop, ($2)->tk_lval.ival, $5, $8, $9, $7))); token_getmad($1,innerop,'L'); token_getmad($2,innerop,'W'); @@ -311,7 +334,8 @@ loop : label WHILE '(' remember texpr ')' mintro mblock cont 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 + | label FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')' + mblock /* basically fake up an initialize-while lineseq */ { OP *forop; PL_copline = (line_t)($2)->tk_lval.ival; @@ -334,8 +358,7 @@ loop : label WHILE '(' remember texpr ')' mintro mblock cont token_getmad($8,forop,'2'); token_getmad($11,forop,')'); token_getmad($1,forop,'L'); - $$ = block_end($4, forop); - } + $$ = block_end($4, forop); } | label block cont /* a block is a loop that happens once */ { $$ = newSTATEOP(0, ($1)->tk_lval.pval, newWHILEOP(0, 1, (LOOP*)Nullop, @@ -343,13 +366,21 @@ loop : label WHILE '(' remember texpr ')' mintro mblock cont token_getmad($1,((LISTOP*)$$)->op_first,'L'); } ; +/* Switch blocks */ +switch : label GIVEN '(' remember mydefsv mexpr ')' mblock + { PL_copline = (line_t) $2; + $$ = block_end($4, + newSTATEOP(0, ($1)->tk_lval.pval, + 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 */ { $$ = Nullop; } @@ -458,7 +489,7 @@ startformsub: /* NULL */ /* start a format subroutine scope */ ; /* Name of a subroutine - must be a bareword, could be special */ -subname : WORD { STRLEN n_a; char *name = SvPV(((SVOP*)$1)->op_sv,n_a); +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")) CvSPECIAL_on(PL_compcv); @@ -702,6 +733,20 @@ subscripted: star '{' expr ';' '}' /* *main::{something} */ 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, Nullop); + token_getmad($1,$$,'('); + token_getmad($2,$$,')'); + token_getmad($3,$$,'['); + token_getmad($5,$$,']'); + } ; /* Binary operators between terms */ @@ -940,20 +985,6 @@ term : termbinop { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));} | subscripted { $$ = $1; } - | '(' 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, Nullop); - token_getmad($1,$$,'('); - token_getmad($2,$$,')'); - token_getmad($3,$$,'['); - token_getmad($5,$$,']'); - } | ary '[' expr ']' /* array slice */ { $$ = prepend_elem(OP_ASLICE, newOP(OP_PUSHMARK, 0), @@ -1024,10 +1055,13 @@ term : termbinop { $$ = newUNOP(($1)->tk_lval.ival, 0, $2); token_getmad($1,$$,'o'); } + | REQUIRE /* require, $_ implied *//* FIMXE for MAD needed? */ + { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); } + | REQUIRE term /* require Foo *//* FIMXE for MAD needed? */ + { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); } | UNIOPSUB term /* Sub treated as unop */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - append_elem(OP_LIST, $2, scalar($1))); - } + append_elem(OP_LIST, $2, scalar($1))); } | FUNC0 /* Nullary operator */ { $$ = newOP(($1)->tk_lval.ival, 0); token_getmad($1,$$,'o');