[antlr-interest] Need help in understanding DFA prediction

shmuel siegel antlr at shmuelhome.mine.nu
Mon Nov 10 00:42:32 PST 2008


Sven Prevrhal wrote:
>
> Sam,
>
> It does –
>
> fragment LETTER : 'a'..'z' | 'A'..'Z';
>
> Perhaps the ‘fragment’ is a problem?
>
> Sven
>
> *From:* Sam Harwell [mailto:sharwell at pixelminegames.com]
> *Sent:* Sunday, November 09, 2008 10:52 PM
> *To:* sven.prevrhal at ucsf.edu; antlr-interest at antlr.org
> *Subject:* RE: [antlr-interest] Need help in understanding DFA prediction
>
> What’s the definition for LETTER? If, for example, you have this:
>
> LETTER : 'a'..'z' ;
>
> Then Cake matches CATEGORYSTART because the capital letter C at the 
> beginning rules out all options but that. Does your LETTER rule allow 
> capital letters?
>
> Sam
>
> *From:* antlr-interest-bounces at antlr.org 
> [mailto:antlr-interest-bounces at antlr.org] *On Behalf Of *Sven Prevrhal
> *Sent:* Monday, November 10, 2008 12:08 AM
> *To:* antlr-interest at antlr.org
> *Subject:* [antlr-interest] Need help in understanding DFA prediction
>
> Hello and thanks Gurus:
>
> I have a Lexer rule
>
> CATEGORYSTART
>
> : SPACE* 'Categories:';
>
> and the call to DFA.Predict which originates from Lexer.mTokens() 
> predicts it for input like “Cake”, and then of course the call to 
> mCATEGORYSTART() in the switch statement inside mTokens()after the 
> DFA.Predict call returns issues an error.
>
> Sooo, how do I get DFA.Predict to predict the WORD rule for “Cake” 
> instead of CATEGORYSTART?
>
> Here’s my WORD rule:
>
> WORD : LETTER+;
>
> Thank you and cheers,
>
> Sven
>
> ------------------------------------------------------------------------
In antlrworks 1.2, I get your problem in the interpreter which can't
handle java predicates. But it works in the debugger. I didn't try a
real program. Here is my grammar.

grammar problem;

token
: (WORD | CATEGORYSTART) EOF {System.out.println("done");};

WORD : LETTER+;

CATEGORYSTART: ' '* 'Categories:';

fragment LETTER: 'a'..'z' | 'A'..'Z';







More information about the antlr-interest mailing list