[antlr-interest] Re: nondeterminism question
Bill Canfield
canfield at computer.org
Thu Sep 1 12:51:05 PDT 2005
Hi Klaas:
I haven't looked at your grammar in detail, but be aware that ANTLR uses
"linear approximate" lookahead. In a nutshell, you might have an
unambiguous grammar that looks ambiguous to ANTLR because it took a
shortcut in calculating the rule. Higher values of k tend to produce
more of these false ambiguities.
Here's a note on it in the ANTLR docs:
http://www.antlr.org/doc/options.html#_bb4
When I've had a situation like this, I just factor the rule until I get
ANTLR to behave :-).
Bill
Klaas Hofstra wrote:
> When you say 'grouped expression', do you mean 'LPAREN expression RPAREN' ?
>
> Because bitSliceExpression can only follow a 'primaryExpression' or 'LPAREN
> expression RPAREN!' I thought it could be distinguised from a grouped
> expression. Am I missing something?
>
> I changed k to 3. This resulted in the following warning at the same line as
> before:
>
> warning:nondeterminism between alts 1 and 2 of block upon
> k==1:LPAREN
> k==2:ID,LPAREN,INT,REAL,PLUS,MINUS,"not","cast"
> k==3:ID,LT,GT,LPAREN,LBRACKET,INT,REAL,"signed","unsigned","float",
> "integer","enum",DOTDOT,"and","or","nand","nor","xor","xnor",
> EQUALS,NOT_EQUALS,GTE,LTE,"sll","srl","sla","sra","rol","ror",
> PLUS,MINUS,TIMES,DIV,"mod","not","cast"
>
> Looking at the above warning, I guess there is a problem with the expressions
> in 'range' but I don't get why.
>
> Anyone?
>
More information about the antlr-interest
mailing list