summaryrefslogtreecommitdiff
path: root/perly.y
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-08-21 12:47:58 -0700
committerFather Chrysostomos <sprout@cpan.org>2014-08-24 19:02:56 -0700
commit2d0e3c969830d8462aa2c3cb9255ecf35a4905b5 (patch)
tree9818df187ea686a036d3764ab27321e6f5cce418 /perly.y
parent01e751b2b71ea7b314a35dd6012f98ea469069f6 (diff)
downloadperl-2d0e3c969830d8462aa2c3cb9255ecf35a4905b5.tar.gz
Set PL_expect less often when parsing semicolons
As it worked before, the parser (perly.y) would set PL_expect to XSTATE after encountering a statement-terminating semicolon. Two functions in op.c--package and utilize--had to set the value to XSTATE as a result. Also, in the case of a closing brace, the lexer emits an implicit semicolon followed by '}' (emitted via force_next). force_next records the value of PL_expect and restores it when emitting the token. So in this case the value of PL_expect was flipping back and forth between two values. Instead of having the parser set it to XSTATE, we can have the lexer set it to XSTATE by default when emitting an explicit semicolon. (It was setting it to XTERM.) The parser can set it to XTERM in the only place that matters; viz., the header of a for-loop. This simplifies things conceptually, and makes the code a whole line shorter. (The diff stat shows more savings in line count, but that is because the version of bison I used to regenerate the tables produces smaller headers than what was already committed.)
Diffstat (limited to 'perly.y')
-rw-r--r--perly.y14
1 files changed, 7 insertions, 7 deletions
diff --git a/perly.y b/perly.y
index de90b2adca..e3df8319dc 100644
--- a/perly.y
+++ b/perly.y
@@ -348,12 +348,16 @@ barestmt: PLUGSTMT
$4, $7, $8, $6));
PL_parser->copline = (line_t)$1;
}
- | FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')'
+ | FOR '(' remember mnexpr ';'
+ { parser->expect = XTERM; }
+ texpr ';'
+ { parser->expect = XTERM; }
+ mintro mnexpr ')'
mblock
{
OP *initop = $4;
OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
- scalar($6), $11, $9, $8);
+ scalar($7), $13, $11, $10);
if (initop) {
forop = op_prepend_elem(OP_LINESEQ, initop,
op_append_elem(OP_LINESEQ,
@@ -403,12 +407,10 @@ barestmt: PLUGSTMT
}
| sideff ';'
{
- PL_parser->expect = XSTATE;
$$ = $1;
}
| ';'
{
- PL_parser->expect = XSTATE;
$$ = (OP*)NULL;
PL_parser->copline = NOLINE;
}
@@ -599,9 +601,7 @@ realsubbody: remember subsignature '{' stmtseq '}'
/* Optional subroutine body, for named subroutine declaration */
optsubbody: realsubbody { $$ = $1; }
- | ';' { $$ = (OP*)NULL;
- PL_parser->expect = XSTATE;
- }
+ | ';' { $$ = (OP*)NULL; }
;
/* Ordinary expressions; logical combinations */