[antlr-interest] intro..& questions

Ric Klaren ric.klaren at gmail.com
Thu Jun 9 00:34:56 PDT 2005


On 6/9/05, Robert Hill <rob.hill at blueyonder.co.uk> wrote:
> I've split my grammar out into 3 separate files, lexer,parser and
> treewalker. I export the vocab from the lexer, and import into the parser
> and the treewalker.
> Now, I need to create some imaginary tokens to insert into the tree as place
> holders for certain constructs to make the walking easier,but must I define
> them in the lexers tokens{} block, since they'll never be used by the lexer?

No you can just define them in the tokens section of the parser and
change the import chain to lexer -> parser -> treeparser. Also be
aware of the build order this implies when building your project.

> I've tried adding them to a tokens{} block parser just to see what happens,
> but when walking the tree I get mismatched tokens because they end up with
> different values in the parser and the tree walker.

Probably because you a) did not build in the right order or b) created
a wrong import/exportVocab chain.

so in short:

lexer : exportVocab L
parser: importVocab L, exportVocab P
treeparser: importVocab P

Then always build in the order lexer, parser, treeparser.

> (BTW...I just love being able to single step into the generated code & see
> what its doing. The value of human readable code shouldn't be
> underestimated)*

Couldn't agree more =)

Cheers,

Ric


More information about the antlr-interest mailing list