[antlr-interest] importVocab question

Ric Klaren ric.klaren at gmail.com
Mon Apr 10 03:57:54 PDT 2006


Hi,

On 4/8/06, Scott Amort <jsamort at rogers.com> wrote:
> I have my ANTLR lexer and parser grammars separated into two files.
> Now, my lexer scans identifiers and tests them against the literals
> table.  The problem here is that there is not a literals table yet, as
> they are all defined in the parser.  To solve this, I import my parser
> vocabulary into the lexer (with importVocab), which also necessitates
> running antlr on the parser first.  This seems to work and everything
> runs fine, except one thing.  Within the lexer, I have numerous
> paraphrase="x" statements to make any error output a bit more
> understandable.  These statements do not make it to the parser, as the
> parser is not inputting the vocabulary from the lexer, but it is instead
> operating the other way around. If I do try to input the lexer
> vocabulary, I end up with a circular dependency - the parser must
> generate its vocab first, but in order to do so it needs the lexer
> vocab, but the lexer needs the parser's vocab to work, and so on.  Is
> there a way to fix this?

Define all tokens in the lexer or define all tokens in the parser.
Export/ImportVocab 'chains' are best built linearly: lexer -> parser
-> treerewriter -> treeparser. Also make sure to get the build order
right, it gives very strange behaviour if you don't (double check the
tokenTypes.txt files when in doubt and see if tokens appear twice or
with different numbers assigned to them).

Cheers,

Ric


More information about the antlr-interest mailing list