[antlr-interest] non-LL(*) decision problem

Juan Fernando Herrera J. juanfhj at gmail.com
Fri Dec 3 02:23:23 PST 2010


I'm trying to implement ON condition GOTO and ON condition GOSUB rules. My
code looks like

statement [boolean defer]
options {backtrack=true;}
    |   'ON' onGotoCondition=expr[defer] 'GOTO' onGotoArg=INT
{onGotoArgs.add($onGotoArg.text);} ( ',' onGotoArg=INT
{onGotoArgs.add($onGotoArg.text);} )* NL {if (!defer)
interp.onGoto($onGotoCondition.start, onGotoArgs);}

    |   'ON' onGosubCondition=expr[defer] 'GOSUB' onGosubArg=INT
{onGosubArgs.add($onGosubArg.text);} ( ',' onGosubArg=INT
{dimArgs.add($onGosubArg.text);} )* NL {if (!defer)
interp.onGosub($onGosubCondition.start, onGosubArgs);}

This requires backtrack=true. However, the generated parser has an error:

    public final void synpred14_InterpreterGrammar02_fragment() throws
RecognitionException {
...
onGotoCondition=expr(defer);

The error is that the defer variable is not defined; I expected

public final void synpred14_InterpreterGrammar02_fragment(boolean defer)
throws RecognitionException {

The problem is solved by left-factoring, but the code becomes quite
unreadable. How could I write a syntactic predicate? I don't quite
understand the concept.

Thanks


More information about the antlr-interest mailing list