X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/b5a648148c71e82a615a5ed312204978f88e1def..d0a6a9c741483b2070b7815882f9135746610435:/perly.y diff --git a/perly.y b/perly.y index eab7de2..349ed4c 100644 --- a/perly.y +++ b/perly.y @@ -20,21 +20,7 @@ * 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() + * The main job 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. * @@ -45,9 +31,7 @@ /* Make the parser re-entrant. */ -%pure_parser - -/* FIXME for MAD - is the new mintro on while and until important? */ +%define api.pure %start grammar @@ -57,184 +41,218 @@ 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 GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ +%token GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ GRAMSUBSIGNATURE -%token '{' '}' '[' ']' '-' '+' '$' '@' '%' '*' '&' ';' +%token '[' ']' '-' '+' '@' '%' '&' '=' '.' +%token PERLY_BRACE_OPEN +%token PERLY_BRACE_CLOSE -%token WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST +%token BAREWORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST %token FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB %token PLUGEXPR PLUGSTMT -%token LABEL -%token FORMAT SUB ANONSUB PACKAGE USE -%token WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR -%token GIVEN WHEN DEFAULT -%token LOOPEX DOTDOT YADAYADA -%token FUNC0 FUNC1 FUNC UNIOP LSTOP -%token RELOP EQOP MULOP ADDOP -%token DOLSHARP DO HASHBRACK NOAMP -%token LOCAL MY MYSUB REQUIRE -%token COLONATTR +%token LABEL +%token FORMAT SUB SIGSUB ANONSUB ANON_SIGSUB PACKAGE USE +%token WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR +%token GIVEN WHEN DEFAULT +%token LOOPEX DOTDOT YADAYADA +%token FUNC0 FUNC1 FUNC UNIOP LSTOP +%token MULOP ADDOP +%token DOLSHARP DO HASHBRACK NOAMP +%token LOCAL MY REQUIRE +%token COLONATTR FORMLBRACK FORMRBRACK +%token SUBLEXSTART SUBLEXEND %type grammar remember mremember %type startsub startanonsub startformsub -/* FIXME for MAD - are these two ival? */ + %type mintro %type stmtseq fullstmt labfullstmt barestmt block mblock else %type expr term subscripted scalar ary hsh arylen star amper sideff -%type listexpr nexpr texpr iexpr mexpr mnexpr miexpr -%type optlistexpr optexpr indirob listop method -%type formname subname proto subbody cont my_scalar +%type condition +%type sliceme kvslice gelem +%type listexpr nexpr texpr iexpr mexpr mnexpr +%type optlistexpr optexpr optrepl indirob listop method +%type formname subname proto cont my_scalar my_var +%type refgen_topic formblock %type subattrlist myattrlist myattrterm myterm %type termbinop termunop anonymous termdo - -%nonassoc PREC_LOW +%type termrelop relopchain termeqop eqopchain +%type sigslurpsigil +%type sigvarname sigdefault sigscalarelem sigslurpelem +%type sigelem siglist siglistornull subsigguts subsignature optsubsignature +%type subbody optsubbody sigsubbody optsigsubbody +%type formstmtseq formline formarg + +%nonassoc PREC_LOW %nonassoc LOOPEX -%left OROP DOROP -%left ANDOP -%right NOTOP +%left OROP DOROP +%left ANDOP +%right NOTOP %nonassoc LSTOP LSTOPSUB -%left ',' -%right ASSIGNOP -%right '?' ':' -%nonassoc DOTDOT YADAYADA -%left OROR DORDOR -%left ANDAND -%left BITOROP -%left BITANDOP -%nonassoc EQOP -%nonassoc RELOP +%left ',' +%right ASSIGNOP +%right '?' ':' +%nonassoc DOTDOT +%left OROR DORDOR +%left ANDAND +%left BITOROP +%left BITANDOP +%left CHEQOP NCEQOP +%left CHRELOP NCRELOP %nonassoc UNIOP UNIOPSUB %nonassoc REQUIRE -%left SHIFTOP +%left SHIFTOP %left ADDOP %left MULOP -%left MATCHOP -%right '!' '~' UMINUS REFGEN -%right POWOP -%nonassoc PREINC PREDEC POSTINC POSTDEC -%left ARROW -%nonassoc ')' -%left '(' -%left '[' '{' - -%token PEG +%left MATCHOP +%right '!' '~' UMINUS REFGEN +%right POWOP +%nonassoc PREINC PREDEC POSTINC POSTDEC POSTJOIN +%left ARROW +%nonassoc ')' +%left '(' +%left '[' PERLY_BRACE_OPEN %% /* RULES */ /* Top-level choice of what kind of thing yyparse was called to parse */ grammar : GRAMPROG { - PL_parser->expect = XSTATE; + parser->expect = XSTATE; + $$ = 0; } remember stmtseq { - newPROG(block_end($3,$4)); + newPROG(block_end($remember,$stmtseq)); + PL_compiling.cop_seq = 0; $$ = 0; } | GRAMEXPR { parser->expect = XTERM; + $$ = 0; } optexpr { - PL_eval_root = $3; + PL_eval_root = $optexpr; $$ = 0; } | GRAMBLOCK { parser->expect = XBLOCK; + $$ = 0; } block { PL_pad_reset_pending = TRUE; - PL_eval_root = $3; + PL_eval_root = $block; $$ = 0; yyunlex(); - parser->yychar = YYEOF; + parser->yychar = yytoken = YYEOF; } | GRAMBARESTMT { parser->expect = XSTATE; + $$ = 0; } barestmt { PL_pad_reset_pending = TRUE; - PL_eval_root = $3; + PL_eval_root = $barestmt; $$ = 0; yyunlex(); - parser->yychar = YYEOF; + parser->yychar = yytoken = YYEOF; } | GRAMFULLSTMT { parser->expect = XSTATE; + $$ = 0; } fullstmt { PL_pad_reset_pending = TRUE; - PL_eval_root = $3; + PL_eval_root = $fullstmt; $$ = 0; yyunlex(); - parser->yychar = YYEOF; + parser->yychar = yytoken = YYEOF; } | GRAMSTMTSEQ { parser->expect = XSTATE; + $$ = 0; } stmtseq { - PL_eval_root = $3; + PL_eval_root = $stmtseq; + $$ = 0; + } + | GRAMSUBSIGNATURE + { + parser->expect = XSTATE; + $$ = 0; + } + subsigguts + { + PL_eval_root = $subsigguts; $$ = 0; } ; /* An ordinary block */ -block : '{' remember stmtseq '}' - { 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,$$,'}'); +block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE + { if (parser->copline > (line_t)$PERLY_BRACE_OPEN) + parser->copline = (line_t)$PERLY_BRACE_OPEN; + $$ = block_end($remember, $stmtseq); + } + ; + +/* format body */ +formblock: '=' remember ';' FORMRBRACK formstmtseq ';' '.' + { if (parser->copline > (line_t)$1) + parser->copline = (line_t)$1; + $$ = block_end($remember, $formstmtseq); } ; remember: /* NULL */ /* start a full lexical scope */ - { $$ = block_start(TRUE); } + { $$ = block_start(TRUE); + parser->parsed_sub = 0; } ; -mblock : '{' mremember stmtseq '}' - { 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,$$,'}'); +mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE + { if (parser->copline > (line_t)$PERLY_BRACE_OPEN) + parser->copline = (line_t)$PERLY_BRACE_OPEN; + $$ = block_end($mremember, $stmtseq); } ; mremember: /* NULL */ /* start a partial lexical scope */ - { $$ = block_start(FALSE); } + { $$ = block_start(FALSE); + parser->parsed_sub = 0; } ; /* A sequence of statements in the program */ stmtseq : /* NULL */ - { $$ = (OP*)NULL; } - | stmtseq fullstmt - { $$ = op_append_list(OP_LINESEQ, $1, $2); + { $$ = NULL; } + | stmtseq[list] fullstmt + { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt); + PL_pad_reset_pending = TRUE; + if ($list && $fullstmt) + PL_hints |= HINT_BLOCK_SCOPE; + } + ; + +/* A sequence of format lines */ +formstmtseq: /* NULL */ + { $$ = NULL; } + | formstmtseq[list] formline + { $$ = op_append_list(OP_LINESEQ, $list, $formline); PL_pad_reset_pending = TRUE; - if ($1 && $2) + if ($list && $formline) PL_hints |= HINT_BLOCK_SCOPE; } ; @@ -242,320 +260,298 @@ stmtseq : /* NULL */ /* A statement in the program, including optional labels */ fullstmt: barestmt { - if($1) { - $$ = newSTATEOP(0, NULL, $1); - } else { - $$ = IF_MAD(newOP(OP_NULL, 0), NULL); - } + $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL; } | labfullstmt - { $$ = $1; } + { $$ = $labfullstmt; } ; labfullstmt: LABEL barestmt { - $$ = newSTATEOP(SvUTF8(((SVOP*)$1)->op_sv), - savepv(SvPVX(((SVOP*)$1)->op_sv)), $2); - TOKEN_GETMAD($1, - $2 ? cLISTOPx($$)->op_first : $$, 'L'); + SV *label = cSVOPx_sv($LABEL); + $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8, + savepv(SvPVX_const(label)), $barestmt); + op_free($LABEL); } - | LABEL labfullstmt + | LABEL labfullstmt[list] { - $$ = newSTATEOP(SvUTF8(((SVOP*)$1)->op_sv), - savepv(SvPVX(((SVOP*)$1)->op_sv)), $2); - TOKEN_GETMAD($1, cLISTOPx($$)->op_first, 'L'); + SV *label = cSVOPx_sv($LABEL); + $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8, + savepv(SvPVX_const(label)), $list); + op_free($LABEL); } ; /* A bare statement, lacking label and other aspects of state op */ barestmt: PLUGSTMT - { $$ = $1; } - | PEG - { - $$ = newOP(OP_NULL,0); - TOKEN_GETMAD($1,$$,'p'); - } - | FORMAT startformsub formname block + { $$ = $PLUGSTMT; } + | FORMAT startformsub formname formblock { CV *fmtcv = PL_compcv; - 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 + newFORM($startformsub, $formname, $formblock); + $$ = NULL; if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) { - SvREFCNT_inc_simple_void(fmtcv); - pad_add_anon(fmtcv, OP_NULL); + pad_add_weakref(fmtcv); } + parser->parsed_sub = 1; + } + | SUB subname startsub + /* sub declaration or definition not within scope + of 'use feature "signatures"'*/ + { + init_named_cv(PL_compcv, $subname); + parser->in_my = 0; + parser->in_my_stash = NULL; } - | SUB startsub subname proto subattrlist subbody + proto subattrlist optsubbody { 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 + $subname->op_type == OP_CONST + ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody) + : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody) + ; + $$ = NULL; + intro_my(); + parser->parsed_sub = 1; + } + | SIGSUB subname startsub + /* sub declaration or definition under 'use feature + * "signatures"'. (Note that a signature isn't + * allowed in a declaration) + */ + { + init_named_cv(PL_compcv, $subname); + parser->in_my = 0; + parser->in_my_stash = NULL; } - | MYSUB startsub subname proto subattrlist subbody + subattrlist optsigsubbody { - /* Unimplemented "my sub foo { }" */ 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 - } - | PACKAGE WORD WORD ';' + $subname->op_type == OP_CONST + ? newATTRSUB($startsub, $subname, NULL, $subattrlist, $optsigsubbody) + : newMYSUB( $startsub, $subname, NULL, $subattrlist, $optsigsubbody) + ; + $$ = NULL; + intro_my(); + parser->parsed_sub = 1; + } + | PACKAGE BAREWORD[version] BAREWORD[package] ';' { -#ifdef MAD - $$ = package($3); - token_getmad($1,$$,'o'); - if ($2) - package_version($2); - token_getmad($4,$$,';'); -#else - package($3); - if ($2) - package_version($2); - $$ = (OP*)NULL; -#endif + package($package); + if ($version) + package_version($version); + $$ = NULL; } | USE startsub { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ } - WORD WORD optlistexpr ';' + BAREWORD[version] BAREWORD[module] optlistexpr ';' { 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_NULL, NULL, 0), $$, 0); -#else - utilize(IVAL($1), $2, $4, $5, $6); - $$ = (OP*)NULL; -#endif + utilize($USE, $startsub, $version, $module, $optlistexpr); + parser->parsed_sub = 1; + $$ = NULL; } | IF '(' remember mexpr ')' mblock else { - $$ = block_end($3, - newCONDOP(0, $4, op_scope($6), $7)); - TOKEN_GETMAD($1,$$,'I'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($5,$$,')'); - PL_parser->copline = (line_t)IVAL($1); - } - | UNLESS '(' remember miexpr ')' mblock else + $$ = block_end($remember, + newCONDOP(0, $mexpr, op_scope($mblock), $else)); + parser->copline = (line_t)$IF; + } + | UNLESS '(' remember mexpr ')' mblock else { - $$ = block_end($3, - newCONDOP(0, $4, op_scope($6), $7)); - TOKEN_GETMAD($1,$$,'I'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($5,$$,')'); - PL_parser->copline = (line_t)IVAL($1); + $$ = block_end($remember, + newCONDOP(0, $mexpr, $else, op_scope($mblock))); + parser->copline = (line_t)$UNLESS; } | GIVEN '(' remember mexpr ')' mblock { - const PADOFFSET offset = pad_findmy_pvs("$_", 0); - $$ = block_end($3, - newGIVENOP($4, op_scope($6), - offset == NOT_IN_PAD - || PAD_COMPNAME_FLAGS_isOUR(offset) - ? 0 - : offset)); - PL_parser->copline = (line_t)IVAL($1); + $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0)); + parser->copline = (line_t)$GIVEN; } | WHEN '(' remember mexpr ')' mblock - { $$ = block_end($3, newWHENOP($4, op_scope($6))); } + { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); } | DEFAULT block - { $$ = newWHENOP(0, op_scope($2)); } + { $$ = newWHENOP(0, op_scope($block)); } | WHILE '(' remember texpr ')' mintro mblock cont { - $$ = block_end($3, - newWHILEOP(0, 1, (LOOP*)(OP*)NULL, - $4, $7, $8, $6)); - TOKEN_GETMAD($1,$$,'W'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($5,$$,')'); - PL_parser->copline = (line_t)IVAL($1); + $$ = block_end($remember, + newWHILEOP(0, 1, NULL, + $texpr, $mblock, $cont, $mintro)); + parser->copline = (line_t)$WHILE; } | UNTIL '(' remember iexpr ')' mintro mblock cont { - $$ = block_end($3, - newWHILEOP(0, 1, (LOOP*)(OP*)NULL, - $4, $7, $8, $6)); - TOKEN_GETMAD($1,$$,'W'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($5,$$,')'); - PL_parser->copline = (line_t)IVAL($1); - } - | FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')' + $$ = block_end($remember, + newWHILEOP(0, 1, NULL, + $iexpr, $mblock, $cont, $mintro)); + parser->copline = (line_t)$UNTIL; + } + | FOR '(' remember mnexpr[init_mnexpr] ';' + { parser->expect = XTERM; } + texpr ';' + { parser->expect = XTERM; } + mintro mnexpr[iterate_mnexpr] ')' mblock { - OP *initop = IF_MAD($4 ? $4 : newOP(OP_NULL, 0), $4); - OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL, - scalar($6), $11, $9, $8); + OP *initop = $init_mnexpr; + OP *forop = newWHILEOP(0, 1, NULL, + scalar($texpr), $mblock, $iterate_mnexpr, $mintro); if (initop) { forop = op_prepend_elem(OP_LINESEQ, initop, op_append_elem(OP_LINESEQ, newOP(OP_UNSTACK, OPf_SPECIAL), forop)); } - DO_MAD({ forop = newUNOP(OP_NULL, 0, forop); }) - $$ = block_end($3, forop); - TOKEN_GETMAD($1,$$,'3'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($5,$$,'1'); - TOKEN_GETMAD($7,$$,'2'); - TOKEN_GETMAD($10,$$,')'); - PL_parser->copline = (line_t)IVAL($1); + PL_hints |= HINT_BLOCK_SCOPE; + $$ = block_end($remember, forop); + parser->copline = (line_t)$FOR; } | FOR MY remember my_scalar '(' mexpr ')' mblock cont { - $$ = block_end($3, newFOROP(0, $4, $6, $8, $9)); - TOKEN_GETMAD($1,$$,'W'); - TOKEN_GETMAD($2,$$,'d'); - TOKEN_GETMAD($5,$$,'('); - TOKEN_GETMAD($7,$$,')'); - PL_parser->copline = (line_t)IVAL($1); + $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont)); + parser->copline = (line_t)$FOR; } | FOR scalar '(' remember mexpr ')' mblock cont { - $$ = block_end($4, newFOROP(0, - op_lvalue($2, OP_ENTERLOOP), $5, $7, $8)); - TOKEN_GETMAD($1,$$,'W'); - TOKEN_GETMAD($3,$$,'('); - TOKEN_GETMAD($6,$$,')'); - PL_parser->copline = (line_t)IVAL($1); + $$ = block_end($remember, newFOROP(0, + op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont)); + parser->copline = (line_t)$FOR; + } + | FOR my_refgen remember my_var + { parser->in_my = 0; $$ = my($my_var); }[variable] + '(' mexpr ')' mblock cont + { + $$ = block_end( + $remember, + newFOROP(0, + op_lvalue( + newUNOP(OP_REFGEN, 0, + $variable), + OP_ENTERLOOP), + $mexpr, $mblock, $cont) + ); + parser->copline = (line_t)$FOR; + } + | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont + { + $$ = block_end($remember, newFOROP( + 0, op_lvalue(newUNOP(OP_REFGEN, 0, + $refgen_topic), + OP_ENTERLOOP), $mexpr, $mblock, $cont)); + parser->copline = (line_t)$FOR; } | FOR '(' remember mexpr ')' mblock cont { - $$ = block_end($3, - newFOROP(0, (OP*)NULL, $4, $6, $7)); - TOKEN_GETMAD($1,$$,'W'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($5,$$,')'); - PL_parser->copline = (line_t)IVAL($1); + $$ = block_end($remember, + newFOROP(0, NULL, $mexpr, $mblock, $cont)); + parser->copline = (line_t)$FOR; } | block cont { /* a block is a loop that happens once */ - $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL, - (OP*)NULL, $1, $2, 0); + $$ = newWHILEOP(0, 1, NULL, + NULL, $block, $cont, 0); } - | PACKAGE WORD WORD '{' remember + | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember { - package($3); - if ($2) { - package_version($2); + package($package); + if ($version) { + package_version($version); } } - stmtseq '}' + stmtseq PERLY_BRACE_CLOSE { /* a block is a loop that happens once */ - $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL, - (OP*)NULL, block_end($5, $7), (OP*)NULL, 0); - TOKEN_GETMAD($4,$$,'{'); - TOKEN_GETMAD($8,$$,'}'); - if (PL_parser->copline > (line_t)IVAL($4)) - PL_parser->copline = (line_t)IVAL($4); + $$ = newWHILEOP(0, 1, NULL, + NULL, block_end($remember, $stmtseq), NULL, 0); + if (parser->copline > (line_t)$PERLY_BRACE_OPEN) + parser->copline = (line_t)$PERLY_BRACE_OPEN; } | sideff ';' { - PL_parser->expect = XSTATE; - $$ = $1; - TOKEN_GETMAD($2,$$,';'); + $$ = $sideff; + } + | YADAYADA ';' + { + $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0), + newSVOP(OP_CONST, 0, newSVpvs("Unimplemented"))); } | ';' { - PL_parser->expect = XSTATE; - $$ = IF_MAD(newOP(OP_NULL, 0), (OP*)NULL); - TOKEN_GETMAD($1,$$,';'); - PL_parser->copline = NOLINE; + $$ = NULL; + parser->copline = NOLINE; } ; +/* Format line */ +formline: THING formarg + { OP *list; + if ($formarg) { + OP *term = $formarg; + list = op_append_elem(OP_LIST, $THING, term); + } + else { + list = $THING; + } + if (parser->copline == NOLINE) + parser->copline = CopLINE(PL_curcop)-1; + else parser->copline--; + $$ = newSTATEOP(0, NULL, + op_convert_list(OP_FORMLINE, 0, list)); + } + ; + +formarg : /* NULL */ + { $$ = NULL; } + | FORMLBRACK stmtseq FORMRBRACK + { $$ = op_unscope($stmtseq); } + ; + +condition: expr +; + /* An expression which may have a side-effect */ sideff : error - { $$ = (OP*)NULL; } - | expr - { $$ = $1; } - | expr IF expr - { $$ = newLOGOP(OP_AND, 0, $3, $1); - TOKEN_GETMAD($2,$$,'i'); - } - | expr UNLESS expr - { $$ = newLOGOP(OP_OR, 0, $3, $1); - TOKEN_GETMAD($2,$$,'i'); - } - | expr WHILE expr - { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); - TOKEN_GETMAD($2,$$,'w'); - } - | expr UNTIL iexpr - { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); - TOKEN_GETMAD($2,$$,'w'); - } - | expr FOR expr - { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL); - TOKEN_GETMAD($2,$$,'w'); - PL_parser->copline = (line_t)IVAL($2); - } - | expr WHEN expr - { $$ = newWHENOP($3, op_scope($1)); } + { $$ = NULL; } + | expr[body] + { $$ = $body; } + | expr[body] IF condition + { $$ = newLOGOP(OP_AND, 0, $condition, $body); } + | expr[body] UNLESS condition + { $$ = newLOGOP(OP_OR, 0, $condition, $body); } + | expr[body] WHILE condition + { $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); } + | expr[body] UNTIL iexpr + { $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); } + | expr[body] FOR condition + { $$ = newFOROP(0, NULL, $condition, $body, NULL); + parser->copline = (line_t)$FOR; } + | expr[body] WHEN condition + { $$ = newWHENOP($condition, op_scope($body)); } ; /* else and elsif blocks */ else : /* NULL */ - { $$ = (OP*)NULL; } + { $$ = NULL; } | ELSE mblock { - ($2)->op_flags |= OPf_PARENS; - $$ = op_scope($2); - TOKEN_GETMAD($1,$$,'o'); + ($mblock)->op_flags |= OPf_PARENS; + $$ = op_scope($mblock); } - | ELSIF '(' mexpr ')' mblock else - { PL_parser->copline = (line_t)IVAL($1); + | ELSIF '(' mexpr ')' mblock else[else.recurse] + { parser->copline = (line_t)$ELSIF; $$ = newCONDOP(0, - newSTATEOP(OPf_SPECIAL,NULL,$3), - op_scope($5), $6); + newSTATEOP(OPf_SPECIAL,NULL,$mexpr), + op_scope($mblock), $[else.recurse]); PL_hints |= HINT_BLOCK_SCOPE; - TOKEN_GETMAD($1,$$,'I'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($4,$$,')'); } ; /* Continue blocks */ cont : /* NULL */ - { $$ = (OP*)NULL; } + { $$ = NULL; } | CONTINUE block - { - $$ = op_scope($2); - TOKEN_GETMAD($1,$$,'o'); - } + { $$ = op_scope($block); } ; /* determine whether there are any new my declarations */ @@ -566,7 +562,7 @@ mintro : /* NULL */ /* Normal expression */ nexpr : /* NULL */ - { $$ = (OP*)NULL; } + { $$ = NULL; } | sideff ; @@ -580,24 +576,20 @@ texpr : /* NULL means true */ /* Inverted boolean expression */ iexpr : expr - { $$ = invert(scalar($1)); } + { $$ = invert(scalar($expr)); } ; /* Expression with its own lexical scope */ mexpr : expr - { $$ = $1; intro_my(); } + { $$ = $expr; intro_my(); } ; mnexpr : nexpr - { $$ = $1; intro_my(); } - ; - -miexpr : iexpr - { $$ = $1; intro_my(); } + { $$ = $nexpr; intro_my(); } ; -formname: WORD { $$ = $1; } - | /* NULL */ { $$ = (OP*)NULL; } +formname: BAREWORD { $$ = $BAREWORD; } + | /* NULL */ { $$ = NULL; } ; startsub: /* NULL */ /* start a regular subroutine scope */ @@ -617,159 +609,346 @@ startformsub: /* NULL */ /* start a format subroutine scope */ ; /* 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; } +subname : BAREWORD + | PRIVATEREF ; /* Subroutine prototype */ proto : /* NULL */ - { $$ = (OP*)NULL; } + { $$ = NULL; } | THING ; /* Optional list of subroutine attributes */ subattrlist: /* NULL */ - { $$ = (OP*)NULL; } + { $$ = NULL; } | COLONATTR THING - { $$ = $2; - TOKEN_GETMAD($1,$$,':'); - } + { $$ = $THING; } | COLONATTR - { $$ = IF_MAD( - newOP(OP_NULL, 0), - (OP*)NULL - ); - TOKEN_GETMAD($1,$$,':'); - } + { $$ = NULL; } ; /* List of attributes for a "my" variable declaration */ myattrlist: COLONATTR THING - { $$ = $2; - TOKEN_GETMAD($1,$$,':'); - } + { $$ = $THING; } | COLONATTR - { $$ = IF_MAD( - newOP(OP_NULL, 0), - (OP*)NULL - ); - TOKEN_GETMAD($1,$$,':'); - } + { $$ = NULL; } ; -/* 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,$$,';'); - } + + +/* -------------------------------------- + * subroutine signature parsing + */ + +/* the '' or 'foo' part of a '$' or '@foo' etc signature variable */ +sigvarname: /* NULL */ + { parser->in_my = 0; $$ = NULL; } + | PRIVATEREF + { parser->in_my = 0; $$ = $PRIVATEREF; } ; -/* Ordinary expressions; logical combinations */ -expr : expr ANDOP expr - { $$ = newLOGOP(OP_AND, 0, $1, $3); - TOKEN_GETMAD($2,$$,'o'); +sigslurpsigil: + '@' + { $$ = '@'; } + | '%' + { $$ = '%'; } + +/* @, %, @foo, %foo */ +sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */ + { + I32 sigil = $sigslurpsigil; + OP *var = $sigvarname; + OP *defexpr = $sigdefault; + + if (parser->sig_slurpy) + yyerror("Multiple slurpy parameters not allowed"); + parser->sig_slurpy = (char)sigil; + + if (defexpr) + yyerror("A slurpy parameter may not have " + "a default value"); + + $$ = var ? newSTATEOP(0, NULL, var) : NULL; + } + ; + +/* default part of sub signature scalar element: i.e. '= default_expr' */ +sigdefault: /* NULL */ + { $$ = NULL; } + | ASSIGNOP + { $$ = newOP(OP_NULL, 0); } + | ASSIGNOP term + { $$ = $term; } + + +/* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */ +sigscalarelem: + '$' sigvarname sigdefault + { + OP *var = $sigvarname; + OP *defexpr = $sigdefault; + + if (parser->sig_slurpy) + yyerror("Slurpy parameter not last"); + + parser->sig_elems++; + + if (defexpr) { + parser->sig_optelems++; + + if ( defexpr->op_type == OP_NULL + && !(defexpr->op_flags & OPf_KIDS)) + { + /* handle '$=' special case */ + if (var) + yyerror("Optional parameter " + "lacks default expression"); + op_free(defexpr); + } + else { + /* a normal '=default' expression */ + OP *defop = (OP*)alloc_LOGOP(OP_ARGDEFELEM, + defexpr, + LINKLIST(defexpr)); + /* re-purpose op_targ to hold @_ index */ + defop->op_targ = + (PADOFFSET)(parser->sig_elems - 1); + + if (var) { + var->op_flags |= OPf_STACKED; + (void)op_sibling_splice(var, + NULL, 0, defop); + scalar(defop); + } + else + var = newUNOP(OP_NULL, 0, defop); + + LINKLIST(var); + /* NB: normally the first child of a + * logop is executed before the logop, + * and it pushes a boolean result + * ready for the logop. For ARGDEFELEM, + * the op itself does the boolean + * calculation, so set the first op to + * it instead. + */ + var->op_next = defop; + defexpr->op_next = var; + } + } + else { + if (parser->sig_optelems) + yyerror("Mandatory parameter " + "follows optional parameter"); + } + + $$ = var ? newSTATEOP(0, NULL, var) : NULL; + } + ; + + +/* subroutine signature element: e.g. '$x = $default' or '%h' */ +sigelem: sigscalarelem + { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; } + | sigslurpelem + { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; } + ; + +/* list of subroutine signature elements */ +siglist: + siglist[list] ',' + { $$ = $list; } + | siglist[list] ',' sigelem[element] + { + $$ = op_append_list(OP_LINESEQ, $list, $element); } - | expr OROP expr - { $$ = newLOGOP(IVAL($2), 0, $1, $3); - TOKEN_GETMAD($2,$$,'o'); + | sigelem[element] %prec PREC_LOW + { $$ = $element; } + ; + +/* () or (....) */ +siglistornull: /* NULL */ + { $$ = NULL; } + | siglist + { $$ = $siglist; } + +/* optional subroutine signature */ +optsubsignature: /* NULL */ + { $$ = NULL; } + | subsignature + { $$ = $subsignature; } + +/* Subroutine signature */ +subsignature: '(' subsigguts ')' + { $$ = $subsigguts; } + +subsigguts: + { + ENTER; + SAVEIV(parser->sig_elems); + SAVEIV(parser->sig_optelems); + SAVEI8(parser->sig_slurpy); + parser->sig_elems = 0; + parser->sig_optelems = 0; + parser->sig_slurpy = 0; + parser->in_my = KEY_sigvar; + } + siglistornull + { + OP *sigops = $siglistornull; + struct op_argcheck_aux *aux; + OP *check; + + if (!FEATURE_SIGNATURES_IS_ENABLED) + Perl_croak(aTHX_ "Experimental " + "subroutine signatures not enabled"); + + /* We shouldn't get here otherwise */ + Perl_ck_warner_d(aTHX_ + packWARN(WARN_EXPERIMENTAL__SIGNATURES), + "The signatures feature is experimental"); + + aux = (struct op_argcheck_aux*) + PerlMemShared_malloc( + sizeof(struct op_argcheck_aux)); + aux->params = parser->sig_elems; + aux->opt_params = parser->sig_optelems; + aux->slurpy = parser->sig_slurpy; + check = newUNOP_AUX(OP_ARGCHECK, 0, NULL, + (UNOP_AUX_item *)aux); + sigops = op_prepend_elem(OP_LINESEQ, check, sigops); + sigops = op_prepend_elem(OP_LINESEQ, + newSTATEOP(0, NULL, NULL), + sigops); + /* a nextstate at the end handles context + * correctly for an empty sub body */ + sigops = op_append_elem(OP_LINESEQ, + sigops, + newSTATEOP(0, NULL, NULL)); + /* wrap the list of arg ops in a NULL aux op. + This serves two purposes. First, it makes + the arg list a separate subtree from the + body of the sub, and secondly the null op + may in future be upgraded to an OP_SIGNATURE + when implemented. For now leave it as + ex-argcheck */ + $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL); + op_null($$); + + parser->in_my = 0; + /* tell the toker that attrributes can follow + * this sig, but only so that the toker + * can skip through any (illegal) trailing + * attribute text then give a useful error + * message about "attributes before sig", + * rather than falling over ina mess at + * unrecognised syntax. + */ + parser->expect = XATTRBLOCK; + parser->sig_seen = TRUE; + LEAVE; } - | expr DOROP expr - { $$ = newLOGOP(OP_DOR, 0, $1, $3); - TOKEN_GETMAD($2,$$,'o'); + ; + +/* Optional subroutine body (for named subroutine declaration) */ +optsubbody: subbody { $$ = $subbody; } + | ';' { $$ = NULL; } + ; + + +/* Subroutine body (without signature) */ +subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE + { + if (parser->copline > (line_t)$PERLY_BRACE_OPEN) + parser->copline = (line_t)$PERLY_BRACE_OPEN; + $$ = block_end($remember, $stmtseq); } + ; + + +/* optional [ Subroutine body with optional signature ] (for named + * subroutine declaration) */ +optsigsubbody: sigsubbody { $$ = $sigsubbody; } + | ';' { $$ = NULL; } + +/* Subroutine body with optional signature */ +sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE + { + if (parser->copline > (line_t)$PERLY_BRACE_OPEN) + parser->copline = (line_t)$PERLY_BRACE_OPEN; + $$ = block_end($remember, + op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq)); + } + ; + + +/* Ordinary expressions; logical combinations */ +expr : expr[lhs] ANDOP expr[rhs] + { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); } + | expr[lhs] OROP[operator] expr[rhs] + { $$ = newLOGOP($operator, 0, $lhs, $rhs); } + | expr[lhs] DOROP expr[rhs] + { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); } | listexpr %prec PREC_LOW ; /* Expressions are a list of terms joined by commas */ -listexpr: listexpr ',' +listexpr: listexpr[list] ',' + { $$ = $list; } + | listexpr[list] ',' term { -#ifdef MAD - OP* op = newNULLLIST(); - token_getmad($2,op,','); - $$ = op_append_elem(OP_LIST, $1, op); -#else - $$ = $1; -#endif - } - | listexpr ',' term - { - OP* term = $3; - DO_MAD( - term = newUNOP(OP_NULL, 0, term); - token_getmad($2,term,','); - ) - $$ = op_append_elem(OP_LIST, $1, term); + OP* term = $term; + $$ = op_append_elem(OP_LIST, $list, term); } | term %prec PREC_LOW ; /* List operators */ listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */ - { $$ = convert(IVAL($1), OPf_STACKED, - op_prepend_elem(OP_LIST, newGVREF(IVAL($1),$2), $3) ); - TOKEN_GETMAD($1,$$,'o'); + { $$ = op_convert_list($LSTOP, OPf_STACKED, + op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) ); } | FUNC '(' indirob expr ')' /* print ($fh @args */ - { $$ = convert(IVAL($1), OPf_STACKED, - op_prepend_elem(OP_LIST, newGVREF(IVAL($1),$3), $4) ); - TOKEN_GETMAD($1,$$,'o'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($5,$$,')'); + { $$ = op_convert_list($FUNC, OPf_STACKED, + op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) ); } | term ARROW method '(' optexpr ')' /* $foo->bar(list) */ - { $$ = convert(OP_ENTERSUB, OPf_STACKED, + { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, - op_prepend_elem(OP_LIST, scalar($1), $5), - newUNOP(OP_METHOD, 0, $3))); - TOKEN_GETMAD($2,$$,'A'); - TOKEN_GETMAD($4,$$,'('); - TOKEN_GETMAD($6,$$,')'); + op_prepend_elem(OP_LIST, scalar($term), $optexpr), + newMETHOP(OP_METHOD, 0, $method))); } | term ARROW method /* $foo->bar */ - { $$ = convert(OP_ENTERSUB, OPf_STACKED, - op_append_elem(OP_LIST, scalar($1), - newUNOP(OP_METHOD, 0, $3))); - TOKEN_GETMAD($2,$$,'A'); + { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED, + op_append_elem(OP_LIST, scalar($term), + newMETHOP(OP_METHOD, 0, $method))); } | METHOD indirob optlistexpr /* new Class @args */ - { $$ = convert(OP_ENTERSUB, OPf_STACKED, + { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, - op_prepend_elem(OP_LIST, $2, $3), - newUNOP(OP_METHOD, 0, $1))); + op_prepend_elem(OP_LIST, $indirob, $optlistexpr), + newMETHOP(OP_METHOD, 0, $METHOD))); } | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */ - { $$ = convert(OP_ENTERSUB, OPf_STACKED, + { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, - op_prepend_elem(OP_LIST, $2, $4), - newUNOP(OP_METHOD, 0, $1))); - TOKEN_GETMAD($3,$$,'('); - TOKEN_GETMAD($5,$$,')'); + op_prepend_elem(OP_LIST, $indirob, $optexpr), + newMETHOP(OP_METHOD, 0, $FUNCMETH))); } | LSTOP optlistexpr /* print @args */ - { $$ = convert(IVAL($1), 0, $2); - TOKEN_GETMAD($1,$$,'o'); - } + { $$ = op_convert_list($LSTOP, 0, $optlistexpr); } | FUNC '(' optexpr ')' /* print (@args) */ - { $$ = convert(IVAL($1), 0, $3); - TOKEN_GETMAD($1,$$,'o'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($4,$$,')'); - } + { $$ = op_convert_list($FUNC, 0, $optexpr); } + | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */ + { $$ = op_convert_list($FUNC, 0, $optexpr); } | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */ { SvREFCNT_inc_simple_void(PL_compcv); - $$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); } + $$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub] optlistexpr %prec LSTOP /* ... @bar */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, - op_prepend_elem(OP_LIST, $4, $5), $1)); + op_prepend_elem(OP_LIST, $anonattrsub, $optlistexpr), $LSTOPSUB)); } ; @@ -779,600 +958,464 @@ method : METHOD ; /* Some kind of subscripted expression */ -subscripted: star '{' expr ';' '}' /* *main::{something} */ +subscripted: gelem PERLY_BRACE_OPEN expr ';' PERLY_BRACE_CLOSE /* *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_GELEM, 0, $gelem, scalar($expr)); } + | scalar[array] '[' expr ']' /* $array[$element] */ + { $$ = newBINOP(OP_AELEM, 0, oopsAV($array), scalar($expr)); + } + | term[array_reference] 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,$$,']'); + ref(newAVREF($array_reference),OP_RV2AV), + scalar($expr)); } - | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */ + | subscripted[array_reference] '[' 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();} */ + ref(newAVREF($array_reference),OP_RV2AV), + scalar($expr)); + } + | scalar[hash] PERLY_BRACE_OPEN expr ';' PERLY_BRACE_CLOSE /* $foo{bar();} */ + { $$ = newBINOP(OP_HELEM, 0, oopsHV($hash), jmaybe($expr)); + } + | term[hash_reference] ARROW PERLY_BRACE_OPEN expr ';' PERLY_BRACE_CLOSE /* 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;} */ + ref(newHVREF($hash_reference),OP_RV2HV), + jmaybe($expr)); } + | subscripted[hash_reference] PERLY_BRACE_OPEN expr ';' PERLY_BRACE_CLOSE /* $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->() */ + ref(newHVREF($hash_reference),OP_RV2HV), + jmaybe($expr)); } + | term[code_reference] ARROW '(' ')' /* $subref->() */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - newCVREF(0, scalar($1))); - TOKEN_GETMAD($2,$$,'a'); - TOKEN_GETMAD($3,$$,'('); - TOKEN_GETMAD($4,$$,')'); + newCVREF(0, scalar($code_reference))); + if (parser->expect == XBLOCK) + parser->expect = XOPERATOR; } - | term ARROW '(' expr ')' /* $subref->(@args) */ + | term[code_reference] ARROW '(' expr ')' /* $subref->(@args) */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - op_append_elem(OP_LIST, $4, - newCVREF(0, scalar($1)))); - TOKEN_GETMAD($2,$$,'a'); - TOKEN_GETMAD($3,$$,'('); - TOKEN_GETMAD($5,$$,')'); + op_append_elem(OP_LIST, $expr, + newCVREF(0, scalar($code_reference)))); + if (parser->expect == XBLOCK) + parser->expect = XOPERATOR; } - | subscripted '(' expr ')' /* $foo->{bar}->(@args) */ + | subscripted[code_reference] '(' expr ')' /* $foo->{bar}->(@args) */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - op_append_elem(OP_LIST, $3, - newCVREF(0, scalar($1)))); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($4,$$,')'); + op_append_elem(OP_LIST, $expr, + newCVREF(0, scalar($code_reference)))); + if (parser->expect == XBLOCK) + parser->expect = XOPERATOR; } - | subscripted '(' ')' /* $foo->{bar}->() */ + | subscripted[code_reference] '(' ')' /* $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,$$,']'); + newCVREF(0, scalar($code_reference))); + if (parser->expect == XBLOCK) + parser->expect = XOPERATOR; } + | '(' expr[list] ')' '[' expr[slice] ']' /* list slice */ + { $$ = newSLICEOP(0, $slice, $list); } | QWLIST '[' expr ']' /* list literal slice */ - { $$ = newSLICEOP(0, $3, $1); - TOKEN_GETMAD($2,$$,'['); - TOKEN_GETMAD($4,$$,']'); - } + { $$ = newSLICEOP(0, $expr, $QWLIST); } | '(' ')' '[' expr ']' /* empty list slice! */ - { $$ = newSLICEOP(0, $4, (OP*)NULL); - TOKEN_GETMAD($1,$$,'('); - TOKEN_GETMAD($2,$$,')'); - TOKEN_GETMAD($3,$$,'['); - TOKEN_GETMAD($5,$$,']'); - } + { $$ = newSLICEOP(0, $expr, NULL); } ; /* 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 : $$), - '~'); - } +termbinop: term[lhs] ASSIGNOP term[rhs] /* $x = $y, $x += $y */ + { $$ = newASSIGNOP(OPf_STACKED, $lhs, $ASSIGNOP, $rhs); } + | term[lhs] POWOP term[rhs] /* $x ** $y */ + { $$ = newBINOP($POWOP, 0, scalar($lhs), scalar($rhs)); } + | term[lhs] MULOP term[rhs] /* $x * $y, $x x $y */ + { if ($MULOP != OP_REPEAT) + scalar($lhs); + $$ = newBINOP($MULOP, 0, $lhs, scalar($rhs)); + } + | term[lhs] ADDOP term[rhs] /* $x + $y */ + { $$ = newBINOP($ADDOP, 0, scalar($lhs), scalar($rhs)); } + | term[lhs] SHIFTOP term[rhs] /* $x >> $y, $x << $y */ + { $$ = newBINOP($SHIFTOP, 0, scalar($lhs), scalar($rhs)); } + | termrelop %prec PREC_LOW /* $x > $y, etc. */ + { $$ = $termrelop; } + | termeqop %prec PREC_LOW /* $x == $y, $x cmp $y */ + { $$ = $termeqop; } + | term[lhs] BITANDOP term[rhs] /* $x & $y */ + { $$ = newBINOP($BITANDOP, 0, scalar($lhs), scalar($rhs)); } + | term[lhs] BITOROP term[rhs] /* $x | $y */ + { $$ = newBINOP($BITOROP, 0, scalar($lhs), scalar($rhs)); } + | term[lhs] DOTDOT term[rhs] /* $x..$y, $x...$y */ + { $$ = newRANGE($DOTDOT, scalar($lhs), scalar($rhs)); } + | term[lhs] ANDAND term[rhs] /* $x && $y */ + { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); } + | term[lhs] OROR term[rhs] /* $x || $y */ + { $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); } + | term[lhs] DORDOR term[rhs] /* $x // $y */ + { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); } + | term[lhs] MATCHOP term[rhs] /* $x =~ /$y/ */ + { $$ = bind_match($MATCHOP, $lhs, $rhs); } ; +termrelop: relopchain %prec PREC_LOW + { $$ = cmpchain_finish($relopchain); } + | term[lhs] NCRELOP term[rhs] + { $$ = newBINOP($NCRELOP, 0, scalar($lhs), scalar($rhs)); } + | termrelop NCRELOP + { yyerror("syntax error"); YYERROR; } + | termrelop CHRELOP + { yyerror("syntax error"); YYERROR; } + ; + +relopchain: term[lhs] CHRELOP term[rhs] + { $$ = cmpchain_start($CHRELOP, $lhs, $rhs); } + | relopchain[lhs] CHRELOP term[rhs] + { $$ = cmpchain_extend($CHRELOP, $lhs, $rhs); } + ; + +termeqop: eqopchain %prec PREC_LOW + { $$ = cmpchain_finish($eqopchain); } + | term[lhs] NCEQOP term[rhs] + { $$ = newBINOP($NCEQOP, 0, scalar($lhs), scalar($rhs)); } + | termeqop NCEQOP + { yyerror("syntax error"); YYERROR; } + | termeqop CHEQOP + { yyerror("syntax error"); YYERROR; } + ; + +eqopchain: term[lhs] CHEQOP term[rhs] + { $$ = cmpchain_start($CHEQOP, $lhs, $rhs); } + | eqopchain[lhs] CHEQOP term[rhs] + { $$ = cmpchain_extend($CHEQOP, $lhs, $rhs); } + ; + /* Unary operators and terms */ termunop : '-' term %prec UMINUS /* -$x */ - { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); - TOKEN_GETMAD($1,$$,'o'); - } + { $$ = newUNOP(OP_NEGATE, 0, scalar($term)); } | '+' term %prec UMINUS /* +$x */ - { $$ = IF_MAD( - newUNOP(OP_NULL, 0, $2), - $2 - ); - TOKEN_GETMAD($1,$$,'+'); - } + { $$ = $term; } + | '!' term /* !$x */ - { $$ = newUNOP(OP_NOT, 0, scalar($2)); - TOKEN_GETMAD($1,$$,'o'); - } + { $$ = newUNOP(OP_NOT, 0, scalar($term)); } | '~' term /* ~$x */ - { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); - TOKEN_GETMAD($1,$$,'o'); - } + { $$ = newUNOP($1, 0, scalar($term)); } | term POSTINC /* $x++ */ { $$ = newUNOP(OP_POSTINC, 0, - op_lvalue(scalar($1), OP_POSTINC)); - TOKEN_GETMAD($2,$$,'o'); - } + op_lvalue(scalar($term), OP_POSTINC)); } | term POSTDEC /* $x-- */ { $$ = newUNOP(OP_POSTDEC, 0, - op_lvalue(scalar($1), OP_POSTDEC)); - TOKEN_GETMAD($2,$$,'o'); + op_lvalue(scalar($term), OP_POSTDEC));} + | term POSTJOIN /* implicit join after interpolated ->@ */ + { $$ = op_convert_list(OP_JOIN, 0, + op_append_elem( + OP_LIST, + newSVREF(scalar( + newSVOP(OP_CONST,0, + newSVpvs("\"")) + )), + $term + )); } | PREINC term /* ++$x */ { $$ = newUNOP(OP_PREINC, 0, - op_lvalue(scalar($2), OP_PREINC)); - TOKEN_GETMAD($1,$$,'o'); - } + op_lvalue(scalar($term), OP_PREINC)); } | PREDEC term /* --$x */ { $$ = newUNOP(OP_PREDEC, 0, - op_lvalue(scalar($2), OP_PREDEC)); - TOKEN_GETMAD($1,$$,'o'); - } + op_lvalue(scalar($term), OP_PREDEC)); } ; /* Constructors for anonymous data */ anonymous: '[' expr ']' - { $$ = newANONLIST($2); - TOKEN_GETMAD($1,$$,'['); - TOKEN_GETMAD($3,$$,']'); - } + { $$ = newANONLIST($expr); } | '[' ']' - { $$ = 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 '(' + { $$ = newANONLIST(NULL);} + | HASHBRACK expr ';' PERLY_BRACE_CLOSE %prec '(' /* { foo => "Bar" } */ + { $$ = newANONHASH($expr); } + | HASHBRACK ';' PERLY_BRACE_CLOSE %prec '(' /* { } (';' by tokener) */ + { $$ = newANONHASH(NULL); } + | ANONSUB startanonsub proto subattrlist subbody %prec '(' { SvREFCNT_inc_simple_void(PL_compcv); - $$ = newANONATTRSUB($2, $3, $4, $5); - TOKEN_GETMAD($1,$$,'o'); - OP_GETMAD($3,$$,'s'); - OP_GETMAD($4,$$,'a'); - } - + $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); } + | ANON_SIGSUB startanonsub subattrlist sigsubbody %prec '(' + { SvREFCNT_inc_simple_void(PL_compcv); + $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); } ; /* Things called with "do" */ termdo : DO term %prec UNIOP /* do $filename */ - { $$ = dofile($2, IVAL($1)); - TOKEN_GETMAD($1,$$,'o'); - } + { $$ = dofile($term, $DO);} | DO block %prec '(' /* do { code */ - { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2)); - TOKEN_GETMAD($1,$$,'D'); - } - | DO WORD '(' ')' /* do somesub() */ - { $$ = newUNOP(OP_ENTERSUB, - OPf_SPECIAL|OPf_STACKED, - op_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, - op_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, - op_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, - op_prepend_elem(OP_LIST, - $4, - scalar(newCVREF(0,scalar($2))))); dep(); - TOKEN_GETMAD($1,$$,'o'); - TOKEN_GETMAD($3,$$,'('); - TOKEN_GETMAD($5,$$,')'); - } - + { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));} ; -term : termbinop +term[product] : 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, op_lvalue($2,OP_REFGEN)); - TOKEN_GETMAD($1,$$,'o'); - } + | term[condition] '?' term[then] ':' term[else] + { $$ = newCONDOP(0, $condition, $then, $else); } + | REFGEN term[operand] /* \$x, \@y, \%z */ + { $$ = newUNOP(OP_REFGEN, 0, $operand); } + | MY REFGEN term[operand] + { $$ = newUNOP(OP_REFGEN, 0, localize($operand,1)); } | myattrterm %prec UNIOP - { $$ = $1; } - | LOCAL term %prec UNIOP - { $$ = localize($2,IVAL($1)); - TOKEN_GETMAD($1,$$,'k'); - } + { $$ = $myattrterm; } + | LOCAL term[operand] %prec UNIOP + { $$ = localize($operand,0); } | '(' expr ')' - { $$ = sawparens(IF_MAD(newUNOP(OP_NULL,0,$2), $2)); - TOKEN_GETMAD($1,$$,'('); - TOKEN_GETMAD($3,$$,')'); - } + { $$ = sawparens($expr); } | QWLIST - { $$ = IF_MAD(newUNOP(OP_NULL,0,$1), $1); } + { $$ = $QWLIST; } | '(' ')' - { $$ = sawparens(newNULLLIST()); - TOKEN_GETMAD($1,$$,'('); - TOKEN_GETMAD($2,$$,')'); - } + { $$ = sawparens(newNULLLIST()); } | scalar %prec '(' - { $$ = $1; } + { $$ = $scalar; } | star %prec '(' - { $$ = $1; } + { $$ = $star; } | hsh %prec '(' - { $$ = $1; } + { $$ = $hsh; } | ary %prec '(' - { $$ = $1; } + { $$ = $ary; } | arylen %prec '(' /* $#x, $#{ something } */ - { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));} + { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));} | subscripted - { $$ = $1; } - | ary '[' expr ']' /* array slice */ + { $$ = $subscripted; } + | sliceme '[' expr ']' /* array slice */ { $$ = op_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} */ + list($expr), + ref($sliceme, OP_ASLICE))); + if ($$ && $sliceme) + $$->op_private |= + $sliceme->op_private & OPpSLICEWARNING; + } + | kvslice '[' expr ']' /* array key/value slice */ + { $$ = op_prepend_elem(OP_KVASLICE, + newOP(OP_PUSHMARK, 0), + newLISTOP(OP_KVASLICE, 0, + list($expr), + ref(oopsAV($kvslice), OP_KVASLICE))); + if ($$ && $kvslice) + $$->op_private |= + $kvslice->op_private & OPpSLICEWARNING; + } + | sliceme PERLY_BRACE_OPEN expr ';' PERLY_BRACE_CLOSE /* @hash{@keys} */ { $$ = op_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,$$,'}'); + list($expr), + ref(oopsHV($sliceme), OP_HSLICE))); + if ($$ && $sliceme) + $$->op_private |= + $sliceme->op_private & OPpSLICEWARNING; + } + | kvslice PERLY_BRACE_OPEN expr ';' PERLY_BRACE_CLOSE /* %hash{@keys} */ + { $$ = op_prepend_elem(OP_KVHSLICE, + newOP(OP_PUSHMARK, 0), + newLISTOP(OP_KVHSLICE, 0, + list($expr), + ref($kvslice, OP_KVHSLICE))); + if ($$ && $kvslice) + $$->op_private |= + $kvslice->op_private & OPpSLICEWARNING; } | THING %prec '(' - { $$ = $1; } + { $$ = $THING; } | amper /* &foo; */ - { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); } - | amper '(' ')' /* &foo() */ - { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($3,$$,')'); + { $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); } + | amper '(' ')' /* &foo() or foo() */ + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper)); } - | amper '(' expr ')' /* &foo(@args) */ + | amper '(' expr ')' /* &foo(@args) or foo(@args) */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - op_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 optlistexpr /* foo(@args) */ - { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - op_append_elem(OP_LIST, $3, scalar($2))); - TOKEN_GETMAD($1,$$,'o'); + op_append_elem(OP_LIST, $expr, scalar($amper))); } + | NOAMP subname optlistexpr /* foo @args (no parens) */ + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, + op_append_elem(OP_LIST, $optlistexpr, scalar($subname))); + } + | term[operand] ARROW '$' '*' + { $$ = newSVREF($operand); } + | term[operand] ARROW '@' '*' + { $$ = newAVREF($operand); } + | term[operand] ARROW '%' '*' + { $$ = newHVREF($operand); } + | term[operand] ARROW '&' '*' + { $$ = newUNOP(OP_ENTERSUB, 0, + scalar(newCVREF($3,$operand))); } + | term[operand] ARROW '*' '*' %prec '(' + { $$ = newGVREF(0,$operand); } | 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'); - } + { $$ = newOP($LOOPEX, OPf_SPECIAL); + PL_hints |= HINT_BLOCK_SCOPE; } + | LOOPEX term[operand] + { $$ = newLOOPEX($LOOPEX,$operand); } | NOTOP listexpr /* not $foo */ - { $$ = newUNOP(OP_NOT, 0, scalar($2)); - TOKEN_GETMAD($1,$$,'o'); - } + { $$ = newUNOP(OP_NOT, 0, scalar($listexpr)); } | UNIOP /* Unary op, $_ implied */ - { $$ = newOP(IVAL($1), 0); - TOKEN_GETMAD($1,$$,'o'); - } + { $$ = newOP($UNIOP, 0); } | 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'); - } + { $$ = newUNOP($UNIOP, 0, $block); } + | UNIOP term[operand] /* Unary op */ + { $$ = newUNOP($UNIOP, 0, $operand); } | 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'); - } + { $$ = newOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0); } + | REQUIRE term[operand] /* require Foo */ + { $$ = newUNOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0, $operand); } | UNIOPSUB - { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); } - | UNIOPSUB term /* Sub treated as unop */ + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($UNIOPSUB)); } + | UNIOPSUB term[operand] /* Sub treated as unop */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - op_append_elem(OP_LIST, $2, scalar($1))); } + op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); } | FUNC0 /* Nullary operator */ - { $$ = newOP(IVAL($1), 0); - TOKEN_GETMAD($1,$$,'o'); - } + { $$ = newOP($FUNC0, 0); } | FUNC0 '(' ')' - { $$ = newOP(IVAL($1), 0); - TOKEN_GETMAD($1,$$,'o'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($3,$$,')'); - } + { $$ = newOP($FUNC0, 0);} | FUNC0OP /* Same as above, but op created in toke.c */ - { $$ = $1; } + { $$ = $FUNC0OP; } | FUNC0OP '(' ')' - { $$ = $1; - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($3,$$,')'); - } + { $$ = $FUNC0OP; } | FUNC0SUB /* Sub treated as nullop */ - { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - scalar($1)); } + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); } | 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 == OP_NOT) + ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0))) + : newOP($FUNC1, OPf_SPECIAL); } | FUNC1 '(' expr ')' /* not($foo) */ - { $$ = newUNOP(IVAL($1), 0, $3); - TOKEN_GETMAD($1,$$,'o'); - TOKEN_GETMAD($2,$$,'('); - TOKEN_GETMAD($4,$$,')'); - } + { $$ = newUNOP($FUNC1, 0, $expr); } | PMFUNC /* m//, s///, qr//, tr/// */ { - if ( $1->op_type != OP_TRANS - && $1->op_type != OP_TRANSR - && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV)) + if ( $PMFUNC->op_type != OP_TRANS + && $PMFUNC->op_type != OP_TRANSR + && (((PMOP*)$PMFUNC)->op_pmflags & PMf_HAS_CV)) { $$ = start_subparse(FALSE, CVf_ANON); SAVEFREESV(PL_compcv); } else $$ = 0; } - '(' listexpr ')' - { $$ = pmruntime($1, $4, 1, $2); - TOKEN_GETMAD($3,$$,'('); - TOKEN_GETMAD($5,$$,')'); - } - | WORD + SUBLEXSTART listexpr optrepl SUBLEXEND + { $$ = pmruntime($PMFUNC, $listexpr, $optrepl, 1, $2); } + | BAREWORD | listop - | YADAYADA - { - $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0), - newSVOP(OP_CONST, 0, newSVpvs("Unimplemented"))); - TOKEN_GETMAD($1,$$,'X'); - } | PLUGEXPR ; /* "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_attrs($myterm,$myattrlist); } | MY myterm - { $$ = localize($2,IVAL($1)); - TOKEN_GETMAD($1,$$,'d'); - } + { $$ = localize($myterm,1); } + | MY REFGEN myterm myattrlist + { $$ = newUNOP(OP_REFGEN, 0, my_attrs($myterm,$myattrlist)); } ; /* Things that can be "my"'d */ myterm : '(' expr ')' - { $$ = sawparens($2); - TOKEN_GETMAD($1,$$,'('); - TOKEN_GETMAD($3,$$,')'); - } + { $$ = sawparens($expr); } | '(' ')' - { $$ = sawparens(newNULLLIST()); - TOKEN_GETMAD($1,$$,'('); - TOKEN_GETMAD($2,$$,')'); - } + { $$ = sawparens(newNULLLIST()); } + | scalar %prec '(' - { $$ = $1; } + { $$ = $scalar; } | hsh %prec '(' - { $$ = $1; } + { $$ = $hsh; } | ary %prec '(' - { $$ = $1; } + { $$ = $ary; } ; /* Basic list expressions */ optlistexpr: /* NULL */ %prec PREC_LOW - { $$ = (OP*)NULL; } + { $$ = NULL; } | listexpr %prec PREC_LOW - { $$ = $1; } + { $$ = $listexpr; } ; optexpr: /* NULL */ - { $$ = (OP*)NULL; } + { $$ = NULL; } | expr - { $$ = $1; } + { $$ = $expr; } + ; + +optrepl: /* NULL */ + { $$ = NULL; } + | '/' expr + { $$ = $expr; } ; /* A little bit of trickery to make "for my $foo (@bar)" actually be lexical */ my_scalar: scalar - { PL_parser->in_my = 0; $$ = my($1); } + { parser->in_my = 0; $$ = my($scalar); } + ; + +my_var : scalar + | ary + | hsh + ; + +refgen_topic: my_var + | amper + ; + +my_refgen: MY REFGEN + | REFGEN MY ; amper : '&' indirob - { $$ = newCVREF(IVAL($1),$2); - TOKEN_GETMAD($1,$$,'&'); - } + { $$ = newCVREF($1,$indirob); } ; scalar : '$' indirob - { $$ = newSVREF($2); - TOKEN_GETMAD($1,$$,'$'); - } + { $$ = newSVREF($indirob); } ; ary : '@' indirob - { $$ = newAVREF($2); - TOKEN_GETMAD($1,$$,'@'); + { $$ = newAVREF($indirob); + if ($$) $$->op_private |= $1; } ; hsh : '%' indirob - { $$ = newHVREF($2); - TOKEN_GETMAD($1,$$,'%'); + { $$ = newHVREF($indirob); + if ($$) $$->op_private |= $1; } ; arylen : DOLSHARP indirob - { $$ = newAVREF($2); - TOKEN_GETMAD($1,$$,'l'); - } + { $$ = newAVREF($indirob); } + | term ARROW DOLSHARP '*' + { $$ = newAVREF($term); } ; star : '*' indirob - { $$ = newGVREF(0,$2); - TOKEN_GETMAD($1,$$,'*'); - } + { $$ = newGVREF(0,$indirob); } + ; + +sliceme : ary + | term ARROW '@' + { $$ = newAVREF($term); } + ; + +kvslice : hsh + | term ARROW '%' + { $$ = newHVREF($term); } + ; + +gelem : star + | term ARROW '*' + { $$ = newGVREF(0,$term); } ; /* Indirect objects */ -indirob : WORD - { $$ = scalar($1); } +indirob : BAREWORD + { $$ = scalar($BAREWORD); } | scalar %prec PREC_LOW - { $$ = scalar($1); } + { $$ = scalar($scalar); } | block - { $$ = op_scope($1); } + { $$ = op_scope($block); } | PRIVATEREF - { $$ = $1; } + { $$ = $PRIVATEREF; } ;