[antlr-interest] Tree walking
Jeff Dahl
jddahl at micron.com
Fri Jul 8 15:20:43 PDT 2005
Jeff Dahl wrote:
> Why does SAMPLE.TREE.G not walk the entire tree? Instead of
>
> ROOT
> |-- A
> | `-- B
> | |-- C
> | | |-- attribute1
> | | | `-- value 1
> | | |-- attribute2
> | | | `-- value 2
> | | `-- attribute3
> | | `-- value 3
> | `-- D
> | `-- attribute4
> | `-- value 4
> |-- E
> | `-- attribute5
> | `-- value 5
> `-- F
> `-- attribute6
> `-- value 6
>
> SAMPLE.TREE.G outputs
>
> ROOT
> |-- A
> | `-- B
> | |-- C
> | `-- D
> |-- E
> `-- F
I figured out while SAMPLE.TREE.G was not walking the entire tree-- I
had SAMPLE.TREE.G defined in a different file and did not use the
exportVocab/importVocab options. As such, a new ...TokenTypes.java file
was created that did not correspond to the TokenTypes.java SAMPLE.G
created. For example, the TokenTypes created by SAMPLE.G were:
int EOF = 1;
int NULL_TREE_LOOKAHEAD = 3;
int ROOT = 4;
int O_SECTION = 5;
int C_SECTION = 6;
int KEYWORD = 7;
int VALUE = 8;
int SECTION = 9;
int CHARS = 10;
int WS = 11;
int NEWLINE = 12;
while the TokenTypes created by SAMPLE.TREE.G were:
int EOF = 1;
int NULL_TREE_LOOKAHEAD = 3;
int ROOT = 4;
int O_SECTION = 5;
int KEYWORD = 6;
int VALUE = 7;
Clearly, when the tree walker was looking for a KEYWORD(6) and the token
came up as a KEYWORD(7) the tree parser would fail.
The solution is to use the exportVocab/importVocab
<http://www.antlr.org/doc/options.html#importVocab> options.
More information about the antlr-interest
mailing list