Previous: TC-B Samples, Up: TC-B [Contents][Index]
The bounds checking extension relies on the use of casts (see TC-B Samples), see See Language Extensions in Tiger Compiler Reference Manual. However, a simplistic implementation of casts introduces ambiguities in the grammar that even a GLR parser cannot resolve dynamically.
Consider the following example, where foo
is an l-value :
_cast(foo, string)
This piece of code can be parsed in two different ways:
exp -> cast-exp -> exp -> lvalue (foo)
exp -> lvalue -> cast-lvalue -> lvalue (foo)
As the cast must preserve the l-value nature of foo
, it must
itself produce an l-value. Hence we want the latter interpretation.
This is a true ambiguity, not a local ambiguity that GLR can resolve
simply by “waiting for enough look-ahead”.
To help it take the right decision, you can favor the right path by
assigning dynamic priorities to relevant rules, using Bison’s
%dprec
keyword. See Bison’s manual (see Flex & Bison) for
more information on this feature.