27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
11
Choice:2 Depth:1 Group:2 (LP)
The second choice at depth 1 starts at line 5 and immediately finds the LP (item 1).
1 #token LP expr4/2 line 5 paren.g
Choice:1 Depth:2 Group:3 (LP Id)
We are back with choice 1, but the depth is now 2, so it tries to match the Id in
lookahead set 2. We start at line 4 (item 1) and flow into expr5 (items 1 and 2). In
expr5 at line 7 we match the LP (item 3). Still within expr5 we flow into expr1 (item
4). From expr 1 we flow into expr 2 (items 6 and 7). This continues until we reach
item 14 which contains an ID from expr5.
1 to expr5 expr4/1 line 4 paren.g
2 expr5 expr5/1 line 7 paren.g
3 #token LP expr5/3 line 9 paren.g
4 to expr1 expr5/3 line 9 paren.g
5 expr1 expr1/1 line 1 paren.g
6 to expr2 expr1/1 line 1 paren.g
7 expr2 expr2/1 line 2 paren.g
8 to expr3 expr2/1 line 2 paren.g
9 expr3 expr3/1 line 3 paren.g
10 to expr4 expr3/1 line 3 paren.g
11 expr4 expr4/1 line 4 paren.g
12 to expr5 expr4/1 line 4 paren.g
13 expr5 expr5/1 line 7 paren.g
14 #token Id expr5/1 line 7 paren.g
Choice:2 Depth:2 Group:4 (LP Id)
The second choice at depth 2. This is a trivial match to LP followed by Id.
1 #token LP expr4/2 line 5 paren.g
2 #token Id expr4/2 line 5 paren.g
This demonstrates how the ambiguity aid reports a chain of rule references.
#56.
Example with ambiguity due to limitations of linear approximation
The example illustrates an ambiguity which is due solely to the limitations of linear lookahead:
rab : a /* 1 */
| b /* 2 */
; /* 3 */
a : J X /* 4 */
; /* 5 */
b : J P /* 6 */
| K X /* 7 */
; /* 8 */
When analyzed with -k 2 there is no ambiguity, but with -k 1 and -ck 2
ANTLR
reports:
look.g(1) : warning: alts 1 and 2 of the rule itself
ambiguous upon { J }, { X }
To someone unfamiliar with linear lookahead, the problem is not obvious. Given the lookahead J followed by X
surely the choice is obvious ? How does ambiguity aid help ?
We run
the ANTLR
ambiguity aid with depth 2 because the ambiguity involves two tokens of lookahead:
antlr look.g -aa rab -aad 2
The output is: