Manual
Manual
Manual
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 5: The Bison Parser Algorithm 79<br />
%token BOGUS<br />
...<br />
%%<br />
...<br />
return_spec:<br />
type<br />
| name ’:’ type<br />
/* This rule is never used. */<br />
| ID BOGUS<br />
;<br />
This corrects the problem because it introduces the possibility of an additional active<br />
rule in the context after the ID at the beginning of return_spec. This rule is not active<br />
in the corresponding context in a param_spec, so the two contexts receive distinct parser<br />
states. As long as the token BOGUS is never generated by yylex, the added rule cannot alter<br />
the way actual input is parsed.<br />
In this particular example, there is another way to solve the problem: rewrite the rule<br />
for return_spec to use ID directly instead of via name. This also causes the two confusing<br />
contexts to have different sets of active rules, because the one for return_spec activates<br />
the altered rule for return_spec rather than the one for name.<br />
param_spec:<br />
type<br />
| name_list ’:’ type<br />
;<br />
return_spec:<br />
type<br />
| ID ’:’ type<br />
;<br />
For a more detailed exposition of LALR(1) parsers and parser generators, please see:<br />
Frank DeRemer and Thomas Pennello, Efficient Computation of LALR(1) Look-Ahead Sets,<br />
ACM Transactions on Programming Languages and Systems, Vol. 4, No. 4 (October 1982),<br />
pp. 615–649 http://doi.acm.org/10.1145/69622.357187.<br />
5.8 Generalized LR (GLR) Parsing<br />
Bison produces deterministic parsers that choose uniquely when to reduce and which reduction<br />
to apply based on a summary of the preceding input and on one extra token of<br />
look-ahead. As a result, normal Bison handles a proper subset of the family of context-free<br />
languages. Ambiguous grammars, since they have strings with more than one possible sequence<br />
of reductions cannot have deterministic parsers in this sense. The same is true of<br />
languages that require more than one symbol of look-ahead, since the parser lacks the information<br />
necessary to make a decision at the point it must be made in a shift-reduce parser.<br />
Finally, as previously mentioned (see Section 5.7 [Mystery Conflicts], page 77), there are<br />
languages where Bison’s particular choice of how to summarize the input seen so far loses<br />
necessary information.<br />
When you use the ‘%glr-parser’ declaration in your grammar file, Bison generates<br />
a parser that uses a different algorithm, called Generalized LR (or GLR). A Bison GLR