[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
1.5.3 GLR Semantic Actions
By definition, a deferred semantic action is not performed at the same time as the associated reduction. This raises caveats for several Bison features you might use in a semantic action in a GLR parser.
In any semantic action, you can examine yychar
to determine the type of
the lookahead token present at the time of the associated reduction.
After checking that yychar
is not set to YYEMPTY
or YYEOF
,
you can then examine yylval
and yylloc
to determine the
lookahead token's semantic value and location, if any.
In a nondeferred semantic action, you can also modify any of these variables to
influence syntax analysis.
See section Lookahead Tokens.
In a deferred semantic action, it's too late to influence syntax analysis.
In this case, yychar
, yylval
, and yylloc
are set to
shallow copies of the values they had at the time of the associated reduction.
For this reason alone, modifying them is dangerous.
Moreover, the result of modifying them is undefined and subject to change with
future versions of Bison.
For example, if a semantic action might be deferred, you should never write it
to invoke yyclearin
(see section Special Features for Use in Actions) or to attempt to free
memory referenced by yylval
.
Another Bison feature requiring special consideration is YYERROR
(see section Special Features for Use in Actions), which you can invoke in a semantic action to
initiate error recovery.
During deterministic GLR operation, the effect of YYERROR
is
the same as its effect in an LALR(1) parser.
In a deferred semantic action, its effect is undefined.
Also, see Default Action for Locations, which
describes a special usage of YYLLOC_DEFAULT
in GLR parsers.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |