[antlr-interest] ANTLR 3: Problem with separated lexer / parser

Oliver Zeigermann oliver.zeigermann at gmail.com
Sat Sep 10 14:45:05 PDT 2005


2005/9/10, Terence Parr <parrt at cs.usfca.edu>:
> 
> On Sep 9, 2005, at 9:26 AM, Oliver Zeigermann wrote:
> 
> > When lexer and parser are specified in different files I find no way
> > to tell the parser to use the token vocabulary of the lexer. Doing
> > something like this
> >
> > grammar XMLParser;
> > options {
> >     tokenVocab=XMLLexer;
> > }
> 
> Yep, I made it a one-way street.
> 
> > where the lexer is called XMLLexer sort of seems to work, but ANTLR
> > still complains like this
> >
> > xmlParser.g:10:38: no lexer rule corresponding to token: VALUE
> > xmlParser.g:25:20: no lexer rule corresponding to token: PCDATA
> >
> > which makes me suspicious that maybe it only worked incidentally.
> >
> > Any hints?
> 
> You have previously generated the lexer and so the vocab file
> exists.  Since you called the XMLParser a combined grammar it is
> properly warning you that have not defined lexer rules. :)  Try:
> 
> parser grammar XMLParser;
> options {
>      tokenVocab=XMLLexer;
> }
> 
> and joy shall be yours! (I hope) ;)

Cool, that makes sense and actually worked for me. 

Thanks :)

Oliver


More information about the antlr-interest mailing list