[antlr-interest] setting k Value Versus Predicates

Gokulakannan Somasundaram gokul007 at gmail.com
Wed Feb 10 15:07:49 PST 2010


Hi,
     I observed the code generated for antlr parser and understood this.
a) If i have set k = n, ANTLR keeps trying to resolve the grammar by reading
further tokens(max n tokens), if there is an ambiguity
b) Once it has read n tokens, then it tries the syntactic or(and) semantic
predicates and chooses the first alternative that satisfies the predicate.
This is implemented with if- condition, whereas the resolving of n-tokens,
happen through switch-case.

Now if i have a grammar(say with k=2) and the only way i can convert it into
k=1 is by using predicates, i think i am better off staying with a higher
value of k. In any case converting my grammar would produce x ambiguity
warnings in y rules. We can be sure that (x >= y). So even in the best case
of x=y ( i.e. each rule produces one ambiguity while converting to lower k
and each one can be resolved by one if-condition), i am just replacing
switch..case by if..condition.

So i feel it is better off to stay with a higher value of k, than to resolve
by predicates. Can i safely make this assumption?

Thanks,
Gokul.


More information about the antlr-interest mailing list