[antlr-interest] intro..& questions

Hill, Robert rhill03 at eds.com
Thu Jun 9 00:58:52 PDT 2005


Ahh, I see now, I never thought about exporting a *different* vocab from
the parser to the tree walker! D'Oh!
My build order is already set out as you describe, it just seemed
logical that way.
Anyway that was exactly the answer I was looking for , Thanks Ric!

Cheers,
/2ob


Rob Hill
EDS UKNMSC			+44 (0) 114 291 1928
Innovation Centre		+44 (0) 114 291 2000
217 Portobello		+44 (0) 791 732 1227
Sheffield			rhill03 at eds.com
S1 4DP



-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Ric Klaren
Sent: 09 June 2005 08:35
To: Robert Hill
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] intro..& questions

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