[antlr-interest] (no subject)

Gavin Lambert antlr at mirality.co.nz
Fri Sep 18 02:46:01 PDT 2009


At 19:28 18/09/2009, David Marín Carreño wrote:
 >OK. I've tried this code, but both ANTLR 3.1.2 
and 3.1.3 generate a
 >faulty tree parser, as they don't declare a 
"expression" variable
 >in the corresponding specialStateTransition function.
 >
 >I think this is a bug. How can I report it?

That sort of problem is fairly well known.  It's 
unfortunate, but at present ANTLR isn't quite 
clever enough to work out that you're using a 
local variable in the predicate and that it'd 
need to pass it along.

 >First of all, I have defined a new private member for the Tree
 >Parser class.
[...]
 >conditionalifthenelse:
 >   ^(IFELSE expression {lastCondExp = ($expression.value!=0);}
 >     		( { lastCondExp }? => ^(THEN statements) ^(ELSE .*) |
 >                                      ^(THEN 
.*) ^(ELSE statements)
 >));

You can also use scopes to do this.  But in 
either case you need to be careful; sometimes the 
predicates can be hoisted to a point before the 
assignment is made.  (It should be ok in this 
context, though; hoisting usually only happens to 
resolve ambiguity.)



More information about the antlr-interest mailing list