[antlr-interest] nondeterminism

Adrian Sandor aditsu at yahoo.com
Sat Jun 28 03:00:09 PDT 2003


Wow.. writing good grammars for antlr is very tricky and makes me 
scratch my head a lot.
I managed to isolate and reduce a nondeterminism problem to the 
following grammar:

//---snip
class p extends Parser;
a: (X Y)?;
b: a X;
//---snip

it says:
test1.g:2:4: warning:nondeterminism between alts 1 and 2 of block upon
test1.g:2:4:     k==1:X

I suppose it is unhappy that it doesn't know whether an X is a b or 
starts an a
but the grammar is equivalent to:

//---snip
class p extends Parser;
a: (X Y)?;
b: X (Y X)?;
//---snip

which has no problem.
I wonder why antlr can't figure this out, but anyway I guess I have 
to learn to write grammars the way antlr likes.
What do you guys think about these things? Are there any clear do's 
and don'ts for writing antlr deterministic grammars? Can the 
nondeterminisms be classified and solved in the general case?

Adrian


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list