diff options
author | Zefram <zefram@fysh.org> | 2010-08-21 18:54:04 +0100 |
---|---|---|
committer | Rafael Garcia-Suarez <rgs@consttype.org> | 2010-09-06 23:25:34 +0200 |
commit | 28ac2b49dea6847c95a32afde577935fec51650f (patch) | |
tree | 2af2b2eb45e3584e390fddcc564587e2c2286f4a /perly.y | |
parent | 544cdeac5a054fa1c1b543769d0076fa6c3faf68 (diff) | |
download | perl-28ac2b49dea6847c95a32afde577935fec51650f.tar.gz |
function interface to parse Perl statement
yyparse() becomes reentrant. The yacc stack and related resources
are allocated in yyparse(), rather than in lex_start(), and they are
localised to yyparse(), preserving their values from any outer parser.
yyparse() now takes a parameter which determines which production it
will parse at the top level. New API function parse_fullstmt() uses this
facility to parse just a single statement. The top-level single-statement
production that is used for this then messes with the parser's head so
that the parsing stops without seeing EOF, and any lookahead token seen
after the statement is pushed back to the lexer.
Diffstat (limited to 'perly.y')
-rw-r--r-- | perly.y | 33 |
1 files changed, 28 insertions, 5 deletions
@@ -49,7 +49,7 @@ /* FIXME for MAD - is the new mintro on while and until important? */ -%start prog +%start grammar %union { I32 ival; /* __DEFAULT__ (marker for regen_perly.pl; @@ -69,6 +69,8 @@ #endif } +%token <ival> GRAMPROG GRAMFULLSTMT + %token <i_tkval> '{' '}' '[' ']' '-' '+' '$' '@' '%' '*' '&' ';' %token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF @@ -85,13 +87,12 @@ %token <i_tkval> LOCAL MY MYSUB REQUIRE %token <i_tkval> COLONATTR -%type <ival> prog progstart remember mremember +%type <ival> grammar prog progstart remember mremember %type <ival> startsub startanonsub startformsub /* FIXME for MAD - are these two ival? */ %type <ival> mydefsv mintro -%type <opval> decl format subrout mysubrout package use peg - +%type <opval> fullstmt decl format subrout mysubrout package use peg %type <opval> block package_block mblock lineseq line loop cond else %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff %type <opval> argexpr nexpr texpr iexpr mexpr mnexpr miexpr @@ -137,6 +138,18 @@ %% /* RULES */ +/* Top-level choice of what kind of thing yyparse was called to parse */ +grammar : GRAMPROG prog + { $$ = $2; } + | GRAMFULLSTMT fullstmt + { + PL_eval_root = $2; + $$ = 0; + yyunlex(); + parser->yychar = YYEOF; + } + ; + /* The whole program */ prog : progstart /*CONTINUED*/ lineseq @@ -200,7 +213,17 @@ lineseq : /* NULL */ } ; -/* A "line" in the program */ +/* A statement, or "line", in the program */ +fullstmt: decl + { $$ = $1; } + | line + { + PL_pad_reset_pending = TRUE; + $$ = $1; + } + ; + +/* A non-declaration statement */ line : label cond { $$ = newSTATEOP(0, PVAL($1), $2); TOKEN_GETMAD($1,((LISTOP*)$$)->op_first,'L'); } |