X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/5adeeefb95fca6c5e6fabf5929c025d5b432d4b0..1707eb284b1f9646240f4f4ca393f6fa309b51fc:/perly.y diff --git a/perly.y b/perly.y index 929a5a3..18ed6e8 100644 --- a/perly.y +++ b/perly.y @@ -45,12 +45,22 @@ %token GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ GRAMSUBSIGNATURE -%token '-' '+' '@' '%' '&' '=' '.' +%token PERLY_AMPERSAND %token PERLY_BRACE_OPEN %token PERLY_BRACE_CLOSE %token PERLY_BRACKET_OPEN %token PERLY_BRACKET_CLOSE +%token PERLY_COMMA +%token PERLY_DOLLAR +%token PERLY_DOT +%token PERLY_EQUAL_SIGN +%token PERLY_MINUS +%token PERLY_PERCENT_SIGN +%token PERLY_PLUS %token PERLY_SEMICOLON +%token PERLY_SLASH +%token PERLY_SNAIL +%token PERLY_STAR %token BAREWORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST %token FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB @@ -59,6 +69,7 @@ %token FORMAT SUB SIGSUB ANONSUB ANON_SIGSUB PACKAGE USE %token WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR %token GIVEN WHEN DEFAULT +%token TRY CATCH %token LOOPEX DOTDOT YADAYADA %token FUNC0 FUNC1 FUNC UNIOP LSTOP %token MULOP ADDOP @@ -66,6 +77,7 @@ %token LOCAL MY REQUIRE %token COLONATTR FORMLBRACK FORMRBRACK %token SUBLEXSTART SUBLEXEND +%token DEFER %type grammar remember mremember %type startsub startanonsub startformsub @@ -92,13 +104,13 @@ %nonassoc PREC_LOW %nonassoc LOOPEX -%left OROP DOROP +%left OROP %left ANDOP %right NOTOP %nonassoc LSTOP LSTOPSUB -%left ',' +%left PERLY_COMMA %right ASSIGNOP -%right '?' ':' +%right PERLY_QUESTION_MARK PERLY_COLON %nonassoc DOTDOT %left OROR DORDOR %left ANDAND @@ -112,12 +124,12 @@ %left ADDOP %left MULOP %left MATCHOP -%right '!' '~' UMINUS REFGEN +%right PERLY_EXCLAMATION_MARK PERLY_TILDE UMINUS REFGEN %right POWOP %nonassoc PREINC PREDEC POSTINC POSTDEC POSTJOIN %left ARROW -%nonassoc ')' -%left '(' +%nonassoc PERLY_PAREN_CLOSE +%left PERLY_PAREN_OPEN %left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN %% /* RULES */ @@ -214,14 +226,14 @@ block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE ; /* format body */ -formblock: '=' remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON '.' - { if (parser->copline > (line_t)$1) - parser->copline = (line_t)$1; +formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT + { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN) + parser->copline = (line_t)$PERLY_EQUAL_SIGN; $$ = block_end($remember, $formstmtseq); } ; -remember: /* NULL */ /* start a full lexical scope */ +remember: %empty /* start a full lexical scope */ { $$ = block_start(TRUE); parser->parsed_sub = 0; } ; @@ -233,13 +245,13 @@ mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE } ; -mremember: /* NULL */ /* start a partial lexical scope */ +mremember: %empty /* start a partial lexical scope */ { $$ = block_start(FALSE); parser->parsed_sub = 0; } ; /* A sequence of statements in the program */ -stmtseq : /* NULL */ +stmtseq : %empty { $$ = NULL; } | stmtseq[list] fullstmt { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt); @@ -250,7 +262,7 @@ stmtseq : /* NULL */ ; /* A sequence of format lines */ -formstmtseq: /* NULL */ +formstmtseq: %empty { $$ = NULL; } | formstmtseq[list] formline { $$ = op_append_list(OP_LINESEQ, $list, $formline); @@ -354,46 +366,46 @@ barestmt: PLUGSTMT parser->parsed_sub = 1; $$ = NULL; } - | IF '(' remember mexpr ')' mblock else + | IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else { $$ = block_end($remember, newCONDOP(0, $mexpr, op_scope($mblock), $else)); parser->copline = (line_t)$IF; } - | UNLESS '(' remember mexpr ')' mblock else + | UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else { $$ = block_end($remember, newCONDOP(0, $mexpr, $else, op_scope($mblock))); parser->copline = (line_t)$UNLESS; } - | GIVEN '(' remember mexpr ')' mblock + | GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock { $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0)); parser->copline = (line_t)$GIVEN; } - | WHEN '(' remember mexpr ')' mblock + | WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); } | DEFAULT block { $$ = newWHENOP(0, op_scope($block)); } - | WHILE '(' remember texpr ')' mintro mblock cont + | WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont { $$ = block_end($remember, newWHILEOP(0, 1, NULL, $texpr, $mblock, $cont, $mintro)); parser->copline = (line_t)$WHILE; } - | UNTIL '(' remember iexpr ')' mintro mblock cont + | UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont { $$ = block_end($remember, newWHILEOP(0, 1, NULL, $iexpr, $mblock, $cont, $mintro)); parser->copline = (line_t)$UNTIL; } - | FOR '(' remember mnexpr[init_mnexpr] PERLY_SEMICOLON + | FOR PERLY_PAREN_OPEN remember mnexpr[init_mnexpr] PERLY_SEMICOLON { parser->expect = XTERM; } texpr PERLY_SEMICOLON { parser->expect = XTERM; } - mintro mnexpr[iterate_mnexpr] ')' + mintro mnexpr[iterate_mnexpr] PERLY_PAREN_CLOSE mblock { OP *initop = $init_mnexpr; @@ -409,12 +421,12 @@ barestmt: PLUGSTMT $$ = block_end($remember, forop); parser->copline = (line_t)$FOR; } - | FOR MY remember my_scalar '(' mexpr ')' mblock cont + | FOR MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont { $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont)); parser->copline = (line_t)$FOR; } - | FOR scalar '(' remember mexpr ')' mblock cont + | FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont { $$ = block_end($remember, newFOROP(0, op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont)); @@ -422,7 +434,7 @@ barestmt: PLUGSTMT } | FOR my_refgen remember my_var { parser->in_my = 0; $$ = my($my_var); }[variable] - '(' mexpr ')' mblock cont + PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont { $$ = block_end( $remember, @@ -435,7 +447,7 @@ barestmt: PLUGSTMT ); parser->copline = (line_t)$FOR; } - | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont + | FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont { $$ = block_end($remember, newFOROP( 0, op_lvalue(newUNOP(OP_REFGEN, 0, @@ -443,12 +455,22 @@ barestmt: PLUGSTMT OP_ENTERLOOP), $mexpr, $mblock, $cont)); parser->copline = (line_t)$FOR; } - | FOR '(' remember mexpr ')' mblock cont + | FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont { $$ = block_end($remember, newFOROP(0, NULL, $mexpr, $mblock, $cont)); parser->copline = (line_t)$FOR; } + | TRY mblock[try] CATCH PERLY_PAREN_OPEN + { parser->in_my = 1; } + remember scalar + { parser->in_my = 0; intro_my(); } + PERLY_PAREN_CLOSE mblock[catch] + { + $$ = newTRYCATCHOP(0, + $try, $scalar, block_end($remember, op_scope($catch))); + parser->copline = (line_t)$TRY; + } | block cont { /* a block is a loop that happens once */ @@ -474,6 +496,10 @@ barestmt: PLUGSTMT { $$ = $sideff; } + | DEFER mblock + { + $$ = newDEFEROP(0, op_scope($2)); + } | YADAYADA PERLY_SEMICOLON { $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0), @@ -504,7 +530,7 @@ formline: THING formarg } ; -formarg : /* NULL */ +formarg : %empty { $$ = NULL; } | FORMLBRACK stmtseq FORMRBRACK { $$ = op_unscope($stmtseq); } @@ -534,14 +560,14 @@ sideff : error ; /* else and elsif blocks */ -else : /* NULL */ +else : %empty { $$ = NULL; } | ELSE mblock { ($mblock)->op_flags |= OPf_PARENS; $$ = op_scope($mblock); } - | ELSIF '(' mexpr ')' mblock else[else.recurse] + | ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else[else.recurse] { parser->copline = (line_t)$ELSIF; $$ = newCONDOP(0, newSTATEOP(OPf_SPECIAL,NULL,$mexpr), @@ -551,26 +577,26 @@ else : /* NULL */ ; /* Continue blocks */ -cont : /* NULL */ +cont : %empty { $$ = NULL; } | CONTINUE block { $$ = op_scope($block); } ; /* determine whether there are any new my declarations */ -mintro : /* NULL */ +mintro : %empty { $$ = (PL_min_intro_pending && PL_max_intro_pending >= PL_min_intro_pending); intro_my(); } /* Normal expression */ -nexpr : /* NULL */ +nexpr : %empty { $$ = NULL; } | sideff ; /* Boolean expression */ -texpr : /* NULL means true */ +texpr : %empty /* NULL means true */ { YYSTYPE tmplval; (void)scan_num("1", &tmplval); $$ = tmplval.opval; } @@ -592,21 +618,21 @@ mnexpr : nexpr ; formname: BAREWORD { $$ = $BAREWORD; } - | /* NULL */ { $$ = NULL; } + | %empty { $$ = NULL; } ; -startsub: /* NULL */ /* start a regular subroutine scope */ +startsub: %empty /* start a regular subroutine scope */ { $$ = start_subparse(FALSE, 0); SAVEFREESV(PL_compcv); } ; -startanonsub: /* NULL */ /* start an anonymous subroutine scope */ +startanonsub: %empty /* start an anonymous subroutine scope */ { $$ = start_subparse(FALSE, CVf_ANON); SAVEFREESV(PL_compcv); } ; -startformsub: /* NULL */ /* start a format subroutine scope */ +startformsub: %empty /* start a format subroutine scope */ { $$ = start_subparse(TRUE, 0); SAVEFREESV(PL_compcv); } ; @@ -617,13 +643,13 @@ subname : BAREWORD ; /* Subroutine prototype */ -proto : /* NULL */ +proto : %empty { $$ = NULL; } | THING ; /* Optional list of subroutine attributes */ -subattrlist: /* NULL */ +subattrlist: %empty { $$ = NULL; } | COLONATTR THING { $$ = $THING; } @@ -645,16 +671,16 @@ myattrlist: COLONATTR THING */ /* the '' or 'foo' part of a '$' or '@foo' etc signature variable */ -sigvarname: /* NULL */ +sigvarname: %empty { parser->in_my = 0; $$ = NULL; } | PRIVATEREF { parser->in_my = 0; $$ = $PRIVATEREF; } ; sigslurpsigil: - '@' + PERLY_SNAIL { $$ = '@'; } - | '%' + | PERLY_PERCENT_SIGN { $$ = '%'; } /* @, %, @foo, %foo */ @@ -677,7 +703,7 @@ sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */ ; /* default part of sub signature scalar element: i.e. '= default_expr' */ -sigdefault: /* NULL */ +sigdefault: %empty { $$ = NULL; } | ASSIGNOP { $$ = newOP(OP_NULL, 0); } @@ -687,7 +713,7 @@ sigdefault: /* NULL */ /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */ sigscalarelem: - '$' sigvarname sigdefault + PERLY_DOLLAR sigvarname sigdefault { OP *var = $sigvarname; OP *defexpr = $sigdefault; @@ -760,9 +786,9 @@ sigelem: sigscalarelem /* list of subroutine signature elements */ siglist: - siglist[list] ',' + siglist[list] PERLY_COMMA { $$ = $list; } - | siglist[list] ',' sigelem[element] + | siglist[list] PERLY_COMMA sigelem[element] { $$ = op_append_list(OP_LINESEQ, $list, $element); } @@ -771,19 +797,19 @@ siglist: ; /* () or (....) */ -siglistornull: /* NULL */ +siglistornull: %empty { $$ = NULL; } | siglist { $$ = $siglist; } /* optional subroutine signature */ -optsubsignature: /* NULL */ +optsubsignature: %empty { $$ = NULL; } | subsignature { $$ = $subsignature; } /* Subroutine signature */ -subsignature: '(' subsigguts ')' +subsignature: PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE { $$ = $subsigguts; } subsigguts: @@ -891,15 +917,13 @@ 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[list] ',' +listexpr: listexpr[list] PERLY_COMMA { $$ = $list; } - | listexpr[list] ',' term + | listexpr[list] PERLY_COMMA term { OP* term = $term; $$ = op_append_elem(OP_LIST, $list, term); @@ -912,11 +936,11 @@ listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */ { $$ = op_convert_list($LSTOP, OPf_STACKED, op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) ); } - | FUNC '(' indirob expr ')' /* print ($fh @args */ + | FUNC PERLY_PAREN_OPEN indirob expr PERLY_PAREN_CLOSE /* print ($fh @args */ { $$ = op_convert_list($FUNC, OPf_STACKED, op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) ); } - | term ARROW method '(' optexpr ')' /* $foo->bar(list) */ + | term ARROW method PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* $foo->bar(list) */ { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, op_prepend_elem(OP_LIST, scalar($term), $optexpr), @@ -933,7 +957,7 @@ listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */ op_prepend_elem(OP_LIST, $indirob, $optlistexpr), newMETHOP(OP_METHOD, 0, $METHOD))); } - | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */ + | FUNCMETH indirob PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* method $object (@args) */ { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, op_prepend_elem(OP_LIST, $indirob, $optexpr), @@ -941,7 +965,7 @@ listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */ } | LSTOP optlistexpr /* print @args */ { $$ = op_convert_list($LSTOP, 0, $optlistexpr); } - | FUNC '(' optexpr ')' /* print (@args) */ + | FUNC PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* print (@args) */ { $$ = op_convert_list($FUNC, 0, $optexpr); } | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */ { $$ = op_convert_list($FUNC, 0, $optexpr); } @@ -989,13 +1013,13 @@ subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE { $$ = newBINOP(OP_HELEM, 0, ref(newHVREF($hash_reference),OP_RV2HV), jmaybe($expr)); } - | term[code_reference] ARROW '(' ')' /* $subref->() */ + | term[code_reference] ARROW PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $subref->() */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, newCVREF(0, scalar($code_reference))); if (parser->expect == XBLOCK) parser->expect = XOPERATOR; } - | term[code_reference] ARROW '(' expr ')' /* $subref->(@args) */ + | term[code_reference] ARROW PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $subref->(@args) */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, $expr, newCVREF(0, scalar($code_reference)))); @@ -1003,24 +1027,24 @@ subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE parser->expect = XOPERATOR; } - | subscripted[code_reference] '(' expr ')' /* $foo->{bar}->(@args) */ + | subscripted[code_reference] PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $foo->{bar}->(@args) */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, $expr, newCVREF(0, scalar($code_reference)))); if (parser->expect == XBLOCK) parser->expect = XOPERATOR; } - | subscripted[code_reference] '(' ')' /* $foo->{bar}->() */ + | subscripted[code_reference] PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $foo->{bar}->() */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, newCVREF(0, scalar($code_reference))); if (parser->expect == XBLOCK) parser->expect = XOPERATOR; } - | '(' expr[list] ')' PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE /* list slice */ + | PERLY_PAREN_OPEN expr[list] PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE /* list slice */ { $$ = newSLICEOP(0, $slice, $list); } | QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* list literal slice */ { $$ = newSLICEOP(0, $expr, $QWLIST); } - | '(' ')' PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* empty list slice! */ + | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* empty list slice! */ { $$ = newSLICEOP(0, $expr, NULL); } ; @@ -1091,15 +1115,15 @@ eqopchain: term[lhs] CHEQOP term[rhs] ; /* Unary operators and terms */ -termunop : '-' term %prec UMINUS /* -$x */ +termunop : PERLY_MINUS term %prec UMINUS /* -$x */ { $$ = newUNOP(OP_NEGATE, 0, scalar($term)); } - | '+' term %prec UMINUS /* +$x */ + | PERLY_PLUS term %prec UMINUS /* +$x */ { $$ = $term; } - | '!' term /* !$x */ + | PERLY_EXCLAMATION_MARK term /* !$x */ { $$ = newUNOP(OP_NOT, 0, scalar($term)); } - | '~' term /* ~$x */ - { $$ = newUNOP($1, 0, scalar($term)); } + | PERLY_TILDE term /* ~$x */ + { $$ = newUNOP($PERLY_TILDE, 0, scalar($term)); } | term POSTINC /* $x++ */ { $$ = newUNOP(OP_POSTINC, 0, op_lvalue(scalar($term), OP_POSTINC)); } @@ -1131,14 +1155,14 @@ anonymous: PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE { $$ = newANONLIST($expr); } | PERLY_BRACKET_OPEN PERLY_BRACKET_CLOSE { $$ = newANONLIST(NULL);} - | HASHBRACK expr PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec '(' /* { foo => "Bar" } */ + | HASHBRACK expr PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { foo => "Bar" } */ { $$ = newANONHASH($expr); } - | HASHBRACK PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec '(' /* { } (PERLY_SEMICOLON by tokener) */ + | HASHBRACK PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { } (PERLY_SEMICOLON by tokener) */ { $$ = newANONHASH(NULL); } - | ANONSUB startanonsub proto subattrlist subbody %prec '(' + | ANONSUB startanonsub proto subattrlist subbody %prec PERLY_PAREN_OPEN { SvREFCNT_inc_simple_void(PL_compcv); $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); } - | ANON_SIGSUB startanonsub subattrlist sigsubbody %prec '(' + | ANON_SIGSUB startanonsub subattrlist sigsubbody %prec PERLY_PAREN_OPEN { SvREFCNT_inc_simple_void(PL_compcv); $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); } ; @@ -1146,7 +1170,7 @@ anonymous: PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* Things called with "do" */ termdo : DO term %prec UNIOP /* do $filename */ { $$ = dofile($term, $DO);} - | DO block %prec '(' /* do { code */ + | DO block %prec PERLY_PAREN_OPEN /* do { code */ { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));} ; @@ -1154,7 +1178,7 @@ term[product] : termbinop | termunop | anonymous | termdo - | term[condition] '?' term[then] ':' term[else] + | term[condition] PERLY_QUESTION_MARK term[then] PERLY_COLON term[else] { $$ = newCONDOP(0, $condition, $then, $else); } | REFGEN term[operand] /* \$x, \@y, \%z */ { $$ = newUNOP(OP_REFGEN, 0, $operand); } @@ -1164,21 +1188,21 @@ term[product] : termbinop { $$ = $myattrterm; } | LOCAL term[operand] %prec UNIOP { $$ = localize($operand,0); } - | '(' expr ')' + | PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE { $$ = sawparens($expr); } | QWLIST { $$ = $QWLIST; } - | '(' ')' + | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE { $$ = sawparens(newNULLLIST()); } - | scalar %prec '(' + | scalar %prec PERLY_PAREN_OPEN { $$ = $scalar; } - | star %prec '(' + | star %prec PERLY_PAREN_OPEN { $$ = $star; } - | hsh %prec '(' + | hsh %prec PERLY_PAREN_OPEN { $$ = $hsh; } - | ary %prec '(' + | ary %prec PERLY_PAREN_OPEN { $$ = $ary; } - | arylen %prec '(' /* $#x, $#{ something } */ + | arylen %prec PERLY_PAREN_OPEN /* $#x, $#{ something } */ { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));} | subscripted { $$ = $subscripted; } @@ -1222,14 +1246,14 @@ term[product] : termbinop $$->op_private |= $kvslice->op_private & OPpSLICEWARNING; } - | THING %prec '(' + | THING %prec PERLY_PAREN_OPEN { $$ = $THING; } | amper /* &foo; */ { $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); } - | amper '(' ')' /* &foo() or foo() */ + | amper PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* &foo() or foo() */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper)); } - | amper '(' expr ')' /* &foo(@args) or foo(@args) */ + | amper PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* &foo(@args) or foo(@args) */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, $expr, scalar($amper))); @@ -1238,16 +1262,16 @@ term[product] : termbinop { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, $optlistexpr, scalar($subname))); } - | term[operand] ARROW '$' '*' + | term[operand] ARROW PERLY_DOLLAR PERLY_STAR { $$ = newSVREF($operand); } - | term[operand] ARROW '@' '*' + | term[operand] ARROW PERLY_SNAIL PERLY_STAR { $$ = newAVREF($operand); } - | term[operand] ARROW '%' '*' + | term[operand] ARROW PERLY_PERCENT_SIGN PERLY_STAR { $$ = newHVREF($operand); } - | term[operand] ARROW '&' '*' + | term[operand] ARROW PERLY_AMPERSAND PERLY_STAR { $$ = newUNOP(OP_ENTERSUB, 0, - scalar(newCVREF($3,$operand))); } - | term[operand] ARROW '*' '*' %prec '(' + scalar(newCVREF($PERLY_AMPERSAND,$operand))); } + | term[operand] ARROW PERLY_STAR PERLY_STAR %prec PERLY_PAREN_OPEN { $$ = newGVREF(0,$operand); } | LOOPEX /* loop exiting command (goto, last, dump, etc) */ { $$ = newOP($LOOPEX, OPf_SPECIAL); @@ -1273,19 +1297,19 @@ term[product] : termbinop op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); } | FUNC0 /* Nullary operator */ { $$ = newOP($FUNC0, 0); } - | FUNC0 '(' ')' + | FUNC0 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE { $$ = newOP($FUNC0, 0);} | FUNC0OP /* Same as above, but op created in toke.c */ { $$ = $FUNC0OP; } - | FUNC0OP '(' ')' + | FUNC0OP PERLY_PAREN_OPEN PERLY_PAREN_CLOSE { $$ = $FUNC0OP; } | FUNC0SUB /* Sub treated as nullop */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); } - | FUNC1 '(' ')' /* not () */ + | FUNC1 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* not () */ { $$ = ($FUNC1 == OP_NOT) ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0))) : newOP($FUNC1, OPf_SPECIAL); } - | FUNC1 '(' expr ')' /* not($foo) */ + | FUNC1 PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* not($foo) */ { $$ = newUNOP($FUNC1, 0, $expr); } | PMFUNC /* m//, s///, qr//, tr/// */ { @@ -1315,35 +1339,35 @@ myattrterm: MY myterm myattrlist ; /* Things that can be "my"'d */ -myterm : '(' expr ')' +myterm : PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE { $$ = sawparens($expr); } - | '(' ')' + | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE { $$ = sawparens(newNULLLIST()); } - | scalar %prec '(' + | scalar %prec PERLY_PAREN_OPEN { $$ = $scalar; } - | hsh %prec '(' + | hsh %prec PERLY_PAREN_OPEN { $$ = $hsh; } - | ary %prec '(' + | ary %prec PERLY_PAREN_OPEN { $$ = $ary; } ; /* Basic list expressions */ -optlistexpr: /* NULL */ %prec PREC_LOW +optlistexpr: %empty %prec PREC_LOW { $$ = NULL; } | listexpr %prec PREC_LOW { $$ = $listexpr; } ; -optexpr: /* NULL */ +optexpr: %empty { $$ = NULL; } | expr { $$ = $expr; } ; -optrepl: /* NULL */ +optrepl: %empty { $$ = NULL; } - | '/' expr + | PERLY_SLASH expr { $$ = $expr; } ; @@ -1366,48 +1390,48 @@ my_refgen: MY REFGEN | REFGEN MY ; -amper : '&' indirob - { $$ = newCVREF($1,$indirob); } +amper : PERLY_AMPERSAND indirob + { $$ = newCVREF($PERLY_AMPERSAND,$indirob); } ; -scalar : '$' indirob +scalar : PERLY_DOLLAR indirob { $$ = newSVREF($indirob); } ; -ary : '@' indirob +ary : PERLY_SNAIL indirob { $$ = newAVREF($indirob); - if ($$) $$->op_private |= $1; + if ($$) $$->op_private |= $PERLY_SNAIL; } ; -hsh : '%' indirob +hsh : PERLY_PERCENT_SIGN indirob { $$ = newHVREF($indirob); - if ($$) $$->op_private |= $1; + if ($$) $$->op_private |= $PERLY_PERCENT_SIGN; } ; arylen : DOLSHARP indirob { $$ = newAVREF($indirob); } - | term ARROW DOLSHARP '*' + | term ARROW DOLSHARP PERLY_STAR { $$ = newAVREF($term); } ; -star : '*' indirob +star : PERLY_STAR indirob { $$ = newGVREF(0,$indirob); } ; sliceme : ary - | term ARROW '@' + | term ARROW PERLY_SNAIL { $$ = newAVREF($term); } ; kvslice : hsh - | term ARROW '%' + | term ARROW PERLY_PERCENT_SIGN { $$ = newHVREF($term); } ; gelem : star - | term ARROW '*' + | term ARROW PERLY_STAR { $$ = newGVREF(0,$term); } ;