[antlr-interest] non-LL(*) decision problem
Jim Idle
jimi at temporal-wave.com
Fri Dec 3 12:10:54 PST 2010
Left factor:
: ON expr ( GOTO INT | GOSUB INT)
;
Avoid backtrack where possible.
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Juan Fernando Herrera J.
> Sent: Friday, December 03, 2010 2:23 AM
> To: ANTLR Interest
> Subject: [antlr-interest] non-LL(*) decision problem
>
> 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
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
More information about the antlr-interest
mailing list