X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=perly.y;h=b238276229a4c7fb4ef0e3b5bd7782c5483b817c;hb=79d01fbf58287276b77349e580651d9897f9b25c;hp=4c4f67a770f572f705cac362ffaa4634586eccd3;hpb=d58bf5aa3d3631a46847733b1ff1985b30140228;p=p5sagit%2Fp5-mst-13.2.git diff --git a/perly.y b/perly.y index 4c4f67a..b238276 100644 --- a/perly.y +++ b/perly.y @@ -14,18 +14,41 @@ %{ #include "EXTERN.h" +#define PERL_IN_PERLY_C #include "perl.h" -static void -dep() -{ - deprecate("\"do\" to call subroutines"); -} +#define dep() deprecate("\"do\" to call subroutines") + +/* stuff included here to make perly_c.diff apply better */ + +#define yydebug PL_yydebug +#define yynerrs PL_yynerrs +#define yyerrflag PL_yyerrflag +#define yychar PL_yychar +#define yyval PL_yyval +#define yylval PL_yylval + +struct ysv { + short* yyss; + YYSTYPE* yyvs; + int oldyydebug; + int oldyynerrs; + int oldyyerrflag; + int oldyychar; + YYSTYPE oldyyval; + YYSTYPE oldyylval; +}; + +static void yydestruct(pTHXo_ void *ptr); %} %start prog +%{ +#if 0 /* get this from perly.h instead */ +%} + %union { I32 ival; char *pval; @@ -33,7 +56,16 @@ dep() GV *gvval; } -%token '{' ')' +%{ +#endif /* 0 */ + +#ifdef USE_PURE_BISON +#define YYLEX_PARAM (&yychar) +#endif + +%} + +%token '{' %token WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF %token FUNC0SUB UNIOPSUB LSTOPSUB @@ -44,17 +76,22 @@ dep() %token FUNC0 FUNC1 FUNC UNIOP LSTOP %token RELOP EQOP MULOP ADDOP %token DOLSHARP DO HASHBRACK NOAMP -%token LOCAL MY +%token LOCAL MY MYSUB +%token COLONATTR -%type prog decl local format startsub startanonsub startformsub +%type prog decl format startsub startanonsub startformsub %type remember mremember '&' %type block mblock lineseq line loop cond else -%type expr term scalar ary hsh arylen star amper sideff +%type expr term subscripted scalar ary hsh arylen star amper sideff %type argexpr nexpr texpr iexpr mexpr mnexpr mtexpr miexpr %type listexpr listexprcom indirob listop method %type formname subname proto subbody cont my_scalar +%type subattrlist myattrlist mysubrout myattrterm myterm %type label +%nonassoc PREC_LOW +%nonassoc LOOPEX + %left OROP %left ANDOP %right NOTOP @@ -78,24 +115,26 @@ dep() %right POWOP %nonassoc PREINC PREDEC POSTINC POSTDEC %left ARROW +%nonassoc ')' %left '(' +%left '[' '{' %% /* RULES */ prog : /* NULL */ { #if defined(YYDEBUG) && defined(DEBUGGING) - yydebug = (debug & 1); + yydebug = (PL_debug & 1); #endif - expect = XSTATE; + PL_expect = XSTATE; } /*CONTINUED*/ lineseq { newPROG($2); } ; block : '{' remember lineseq '}' - { if (copline > (line_t)$1) - copline = $1; + { if (PL_copline > (line_t)$1) + PL_copline = $1; $$ = block_end($2, $3); } ; @@ -104,8 +143,8 @@ remember: /* NULL */ /* start a full lexical scope */ ; mblock : '{' mremember lineseq '}' - { if (copline > (line_t)$1) - copline = $1; + { if (PL_copline > (line_t)$1) + PL_copline = $1; $$ = block_end($2, $3); } ; @@ -120,8 +159,8 @@ lineseq : /* NULL */ | lineseq line { $$ = append_list(OP_LINESEQ, (LISTOP*)$1, (LISTOP*)$2); - pad_reset_pending = TRUE; - if ($1 && $2) hints |= HINT_BLOCK_SCOPE; } + PL_pad_reset_pending = TRUE; + if ($1 && $2) PL_hints |= HINT_BLOCK_SCOPE; } ; line : label cond @@ -133,12 +172,12 @@ line : label cond } else { $$ = Nullop; - copline = NOLINE; + PL_copline = NOLINE; } - expect = XSTATE; } + PL_expect = XSTATE; } | label sideff ';' { $$ = newSTATEOP(0, $1, $2); - expect = XSTATE; } + PL_expect = XSTATE; } ; sideff : error @@ -153,25 +192,27 @@ sideff : error { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); } | expr UNTIL iexpr { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1);} + | expr FOR expr + { $$ = newFOROP(0, Nullch, $2, + Nullop, $3, $1, Nullop); } ; else : /* NULL */ { $$ = Nullop; } | ELSE mblock - { $$ = scope($2); } + { ($2)->op_flags |= OPf_PARENS; $$ = scope($2); } | ELSIF '(' mexpr ')' mblock else - { copline = $1; - $$ = newSTATEOP(0, Nullch, - newCONDOP(0, $3, scope($5), $6)); - hints |= HINT_BLOCK_SCOPE; } + { PL_copline = $1; + $$ = newCONDOP(0, $3, scope($5), $6); + PL_hints |= HINT_BLOCK_SCOPE; } ; cond : IF '(' remember mexpr ')' mblock else - { copline = $1; + { PL_copline = $1; $$ = block_end($3, newCONDOP(0, $4, scope($6), $7)); } | UNLESS '(' remember miexpr ')' mblock else - { copline = $1; + { PL_copline = $1; $$ = block_end($3, newCONDOP(0, $4, scope($6), $7)); } ; @@ -183,13 +224,13 @@ cont : /* NULL */ ; loop : label WHILE '(' remember mtexpr ')' mblock cont - { copline = $2; + { PL_copline = $2; $$ = block_end($4, newSTATEOP(0, $1, newWHILEOP(0, 1, (LOOP*)Nullop, $2, $5, $7, $8))); } | label UNTIL '(' remember miexpr ')' mblock cont - { copline = $2; + { PL_copline = $2; $$ = block_end($4, newSTATEOP(0, $1, newWHILEOP(0, 1, (LOOP*)Nullop, @@ -211,7 +252,7 @@ loop : label WHILE '(' remember mtexpr ')' mblock cont newWHILEOP(0, 1, (LOOP*)Nullop, $2, scalar($7), $11, scalar($9))); - copline = $2; + PL_copline = $2; $$ = block_end($4, newSTATEOP(0, $1, forop)); } | label block cont /* a block is a loop that happens once */ { $$ = newSTATEOP(0, $1, @@ -258,6 +299,8 @@ decl : format { $$ = 0; } | subrout { $$ = 0; } + | mysubrout + { $$ = 0; } | package { $$ = 0; } | use @@ -272,8 +315,12 @@ formname: WORD { $$ = $1; } | /* NULL */ { $$ = Nullop; } ; -subrout : SUB startsub subname proto subbody - { newSUB($2, $3, $4, $5); } +mysubrout: MYSUB startsub subname proto subattrlist subbody + { newMYSUB($2, $3, $4, $5, $6); } + ; + +subrout : SUB startsub subname proto subattrlist subbody + { newATTRSUB($2, $3, $4, $5, $6); } ; startsub: /* NULL */ /* start a regular subroutine scope */ @@ -288,10 +335,10 @@ startformsub: /* NULL */ /* start a format subroutine scope */ { $$ = start_subparse(TRUE, 0); } ; -subname : WORD { char *name = SvPV(((SVOP*)$1)->op_sv, na); +subname : WORD { STRLEN n_a; char *name = SvPV(((SVOP*)$1)->op_sv,n_a); if (strEQ(name, "BEGIN") || strEQ(name, "END") - || strEQ(name, "INIT")) - CvUNIQUE_on(compcv); + || strEQ(name, "STOP") || strEQ(name, "INIT")) + CvSPECIAL_on(PL_compcv); $$ = $1; } ; @@ -300,8 +347,22 @@ proto : /* NULL */ | THING ; +subattrlist: /* NULL */ + { $$ = Nullop; } + | COLONATTR THING + { $$ = $2; } + | COLONATTR + { $$ = Nullop; } + ; + +myattrlist: COLONATTR THING + { $$ = $2; } + | COLONATTR + { $$ = Nullop; } + ; + subbody : block { $$ = $1; } - | ';' { $$ = Nullop; expect = XSTATE; } + | ';' { $$ = Nullop; PL_expect = XSTATE; } ; package : PACKAGE WORD ';' @@ -311,7 +372,7 @@ package : PACKAGE WORD ';' ; use : USE startsub - { CvUNIQUE_on(compcv); /* It's a BEGIN {} */ } + { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ } WORD WORD listexpr ';' { utilize($1, $2, $4, $5, $6); } ; @@ -320,14 +381,14 @@ expr : expr ANDOP expr { $$ = newLOGOP(OP_AND, 0, $1, $3); } | expr OROP expr { $$ = newLOGOP($2, 0, $1, $3); } - | argexpr + | argexpr %prec PREC_LOW ; argexpr : argexpr ',' { $$ = $1; } | argexpr ',' term { $$ = append_elem(OP_LIST, $1, $3); } - | term + | term %prec PREC_LOW ; listop : LSTOP indirob argexpr @@ -341,6 +402,10 @@ listop : LSTOP indirob argexpr append_elem(OP_LIST, prepend_elem(OP_LIST, scalar($1), $5), newUNOP(OP_METHOD, 0, $3))); } + | term ARROW method + { $$ = convert(OP_ENTERSUB, OPf_STACKED, + append_elem(OP_LIST, scalar($1), + newUNOP(OP_METHOD, 0, $3))); } | METHOD indirob listexpr { $$ = convert(OP_ENTERSUB, OPf_STACKED, append_elem(OP_LIST, @@ -356,7 +421,7 @@ listop : LSTOP indirob argexpr | FUNC '(' listexprcom ')' { $$ = convert($1, 0, $3); } | LSTOPSUB startanonsub block - { $3 = newANONSUB($2, 0, $3); } + { $3 = newANONATTRSUB($2, 0, Nullop, $3); } listexpr %prec LSTOP { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, append_elem(OP_LIST, @@ -367,6 +432,49 @@ method : METHOD | scalar ; +subscripted: star '{' expr ';' '}' + { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); } + | scalar '[' expr ']' + { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); } + | term ARROW '[' expr ']' + { $$ = newBINOP(OP_AELEM, 0, + ref(newAVREF($1),OP_RV2AV), + scalar($4));} + | subscripted '[' expr ']' + { $$ = newBINOP(OP_AELEM, 0, + ref(newAVREF($1),OP_RV2AV), + scalar($3));} + | scalar '{' expr ';' '}' + { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3)); + PL_expect = XOPERATOR; } + | term ARROW '{' expr ';' '}' + { $$ = newBINOP(OP_HELEM, 0, + ref(newHVREF($1),OP_RV2HV), + jmaybe($4)); + PL_expect = XOPERATOR; } + | subscripted '{' expr ';' '}' + { $$ = newBINOP(OP_HELEM, 0, + ref(newHVREF($1),OP_RV2HV), + jmaybe($3)); + PL_expect = XOPERATOR; } + | term ARROW '(' ')' + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, + newCVREF(0, scalar($1))); } + | term ARROW '(' expr ')' + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, + append_elem(OP_LIST, $4, + newCVREF(0, scalar($1)))); } + + | subscripted '(' expr ')' + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, + append_elem(OP_LIST, $3, + newCVREF(0, scalar($1)))); } + | subscripted '(' ')' + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, + newCVREF(0, scalar($1))); } + + + term : term ASSIGNOP term { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); } | term POWOP term @@ -420,74 +528,53 @@ term : term ASSIGNOP term | PREDEC term { $$ = newUNOP(OP_PREDEC, 0, mod(scalar($2), OP_PREDEC)); } - | local term %prec UNIOP + | myattrterm %prec UNIOP + { $$ = $1; } + | LOCAL term %prec UNIOP { $$ = localize($2,$1); } | '(' expr ')' { $$ = sawparens($2); } | '(' ')' { $$ = sawparens(newNULLLIST()); } - | '[' expr ']' %prec '(' + | '[' expr ']' { $$ = newANONLIST($2); } - | '[' ']' %prec '(' + | '[' ']' { $$ = newANONLIST(Nullop); } | HASHBRACK expr ';' '}' %prec '(' { $$ = newANONHASH($2); } | HASHBRACK ';' '}' %prec '(' { $$ = newANONHASH(Nullop); } - | ANONSUB startanonsub proto block %prec '(' - { $$ = newANONSUB($2, $3, $4); } + | ANONSUB startanonsub proto subattrlist block %prec '(' + { $$ = newANONATTRSUB($2, $3, $4, $5); } | scalar %prec '(' { $$ = $1; } - | star '{' expr ';' '}' - { $$ = newBINOP(OP_GELEM, 0, newGVREF(0,$1), $3); } | star %prec '(' { $$ = $1; } - | scalar '[' expr ']' %prec '(' - { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); } - | term ARROW '[' expr ']' %prec '(' - { $$ = newBINOP(OP_AELEM, 0, - ref(newAVREF($1),OP_RV2AV), - scalar($4));} - | term '[' expr ']' %prec '(' - { assertref($1); $$ = newBINOP(OP_AELEM, 0, - ref(newAVREF($1),OP_RV2AV), - scalar($3));} | hsh %prec '(' { $$ = $1; } | ary %prec '(' { $$ = $1; } | arylen %prec '(' { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));} - | scalar '{' expr ';' '}' %prec '(' - { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3)); - expect = XOPERATOR; } - | term ARROW '{' expr ';' '}' %prec '(' - { $$ = newBINOP(OP_HELEM, 0, - ref(newHVREF($1),OP_RV2HV), - jmaybe($4)); - expect = XOPERATOR; } - | term '{' expr ';' '}' %prec '(' - { assertref($1); $$ = newBINOP(OP_HELEM, 0, - ref(newHVREF($1),OP_RV2HV), - jmaybe($3)); - expect = XOPERATOR; } - | '(' expr ')' '[' expr ']' %prec '(' + | subscripted + { $$ = $1; } + | '(' expr ')' '[' expr ']' { $$ = newSLICEOP(0, $5, $2); } - | '(' ')' '[' expr ']' %prec '(' + | '(' ')' '[' expr ']' { $$ = newSLICEOP(0, $4, Nullop); } - | ary '[' expr ']' %prec '(' + | ary '[' expr ']' { $$ = prepend_elem(OP_ASLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_ASLICE, 0, list($3), ref($1, OP_ASLICE))); } - | ary '{' expr ';' '}' %prec '(' + | ary '{' expr ';' '}' { $$ = prepend_elem(OP_HSLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_HSLICE, 0, list($3), ref(oopsHV($1), OP_HSLICE))); - expect = XOPERATOR; } + PL_expect = XOPERATOR; } | THING %prec '(' { $$ = $1; } | amper @@ -501,7 +588,7 @@ term : term ASSIGNOP term { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, append_elem(OP_LIST, $3, scalar($2))); } | DO term %prec UNIOP - { $$ = newUNOP(OP_DOFILE, 0, scalar($2)); } + { $$ = dofile($2); } | DO block %prec '(' { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2)); } | DO WORD '(' ')' @@ -530,16 +617,9 @@ term : term ASSIGNOP term prepend_elem(OP_LIST, $4, scalar(newCVREF(0,scalar($2))))); dep();} - | term ARROW '(' ')' %prec '(' - { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - newCVREF(0, scalar($1))); } - | term ARROW '(' expr ')' %prec '(' - { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - append_elem(OP_LIST, $4, - newCVREF(0, scalar($1)))); } | LOOPEX { $$ = newOP($1, OPf_SPECIAL); - hints |= HINT_BLOCK_SCOPE; } + PL_hints |= HINT_BLOCK_SCOPE; } | LOOPEX term { $$ = newLOOPEX($1,$2); } | NOTOP argexpr @@ -572,9 +652,27 @@ term : term ASSIGNOP term | listop ; -listexpr: /* NULL */ +myattrterm: MY myterm myattrlist + { $$ = my_attrs($2,$3); } + | MY myterm + { $$ = localize($2,$1); } + ; + +myterm : '(' expr ')' + { $$ = sawparens($2); } + | '(' ')' + { $$ = sawparens(newNULLLIST()); } + | scalar %prec '(' + { $$ = $1; } + | hsh %prec '(' + { $$ = $1; } + | ary %prec '(' + { $$ = $1; } + ; + +listexpr: /* NULL */ %prec PREC_LOW { $$ = Nullop; } - | argexpr + | argexpr %prec PREC_LOW { $$ = $1; } ; @@ -586,12 +684,8 @@ listexprcom: /* NULL */ { $$ = $1; } ; -local : LOCAL { $$ = 0; } - | MY { $$ = 1; } - ; - my_scalar: scalar - { in_my = 0; $$ = my($1); } + { PL_in_my = 0; $$ = my($1); } ; amper : '&' indirob @@ -620,7 +714,7 @@ star : '*' indirob indirob : WORD { $$ = scalar($1); } - | scalar + | scalar %prec PREC_LOW { $$ = scalar($1); } | block { $$ = scope($1); } @@ -630,3 +724,11 @@ indirob : WORD ; %% /* PROGRAM */ + +/* more stuff added to make perly_c.diff easier to apply */ + +#ifdef yyparse +#undef yyparse +#endif +#define yyparse() Perl_yyparse(pTHX) +