Your grammar works in ANTLR v3 without any parameters.
The parameter k restricts ANTLR to the classical LL (k) analysis. Returning means - if the analyzer cannot predict which rule to use, it simply tries, retreats and tries again. The backtracking option that you should use when ANTLR cannot build the open source DFA for this grammar. ANTLR v3 can easily create DFAs from regular expressions, but has its difficulties with recursive rules. For example, this grammar works:
start: recursive_rule ';' | recursive_rule ':' ; recursive_rule : (ID)* '%' ;
This grammar below is the same, but expressed through recursion. ANTLR cannot build a DFA for it (I really don't know why), so you need to switch back:
start options {backtrack=true;} : recursive_rule ';' | recursive_rule ':' ; recursive_rule : ID recursive_rule |'%' ;
The k parameter is used to improve analyzer performance. I do not know any other reason for restricting LL (*) to LL (k).
source share