[antlr-interest] Bug in ANTLR 3.1.1?
Robert Vaessen
robert at rvaessen.com
Mon Nov 10 13:04:26 PST 2008
Thx Gavin.
I've already tried adding the $ to the variable name. BTW: I am still
waiting for complete understanding on this one - some times it matters
and some times it doesn't.
And isn't it interesting that the invocation of objectPath doesn't have
the same problem?
____________________
Robert Jozef Vaessen
robert at rvaessen.com
(704) 996-1080
Gavin Lambert wrote:
> At 05:57 9/11/2008, Robert Vaessen wrote:
>> In the grammar (see the attached grammar file) the start rule calls
>> the booleanExpression rule passing it a string argument. In the
>> generated class the start() method invokes a "delegated" rule which
>> in turn invokes a "fragment" which in turn invokes the
>> booleanExpression() method (see line 867 in the attached java file)
>> passing it the string argument which was never passed in by the
>> start() method???
>
> It's because you've set backtrack=true, so ANTLR has inserted a
> predicate to perform the lookahead. Predicates and rule arguments
> don't really play nicely together, especially if they get hoisted.
>
>> start[String inCdlClassName, String inCdlVariableName] returns
>> [String code]
>> @init {
>> linkDefinitions();
>> pushDefiniton(inCdlClassName);
>> mCdlVariableName = inCdlVariableName;
>> CodeBuilder builder = new CodeBuilder();
>> }
>> @after {
>> $code = builder.toString();
>> unlinkDefinitions();
>> }
>> : booleanExpression[inCdlVariableName] {
>> builder.append($booleanExpression.code); }
>> | objectPath[builder]
>> ;
>
> The first thing to try is to use $inCdlVariableName here, so that
> ANTLR knows you're referring to the parameter. (You should always do
> this when referring to a symbol defined in the grammar rather than the
> code.)
>
> If that doesn't help, then you will probably need to use scopes
> instead of rule parameters. Or you could just use mCdlVariableName,
> since you're saving it anyway.
>
>
>
More information about the antlr-interest
mailing list