[antlr-interest] Re: Expected token apparently not expected?!

Ric Klaren klaren at cs.utwente.nl
Thu Sep 9 13:57:05 PDT 2004


Hi,

On Thu, Sep 09, 2004 at 06:47:03PM -0000, David Bullock wrote:
> --- In antlr-interest at yahoogroups.com, "David Bullock" <db at d...> wrote:
> > Having now deleted the .txt files as part of my build, I have
> > unearthed a problem - lexer.g imports literals exported from parser.g,
> > and parser.g of course imports lexer.g.  What is the 'right' strategy
> > for compiling these?
>
> Just for clarity, I have something like:
>
> ... in p.g
>
> class P extends Parser;
> options {
>   exportVocab = P;
>   importVocab = L;
> }
> rule
>    : "keyword" DASH "modifier"
>    ;
>
>
> ... in l.g
>
> class L extends Lexer;
> options {
>   exportVocab = L;
>   importVocab = P;
> }
>
> DASH
>    : '-'
>    ;
>
> ... and I am attempting to use antlr.Tool to compile them, and it
> whinges at me if I give >1 grammar file to compile.

Always use import/export vocab in a clear chain. E.g. have definitions move
up:

Lexer -> Parser -> treeparser

e.g:

In l.g do exportVocab = L;
In p.g do importVocab = L; and exportVocab = P;

In subsequent tree parsers importVocab = P. If you do treetransforms that
add new AST nodes you have to add more import/exportVocab's.

Once you have such a chain set up make sure you always built parsers in the
right order e.g. first the lexer then the parser then the treeparser.

antlr.Tool only accepts one grammar to parse. So you have to run it
separately for different .g files.

Note that when you have lexer/parser in one file then the semantics of
exportVocab/importVocab are slightly different. All the lexers/parsers in
one file share the same vocabulary so usually you don't have to use
import/exportVocab.

See also:

http://www.jguru.com/faq/view.jsp?EID=531842

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
-----+++++*****************************************************+++++++++-------
     Human beings, who are almost unique in having the ability to learn
   from the experience of others, are also remarkable for their apparent
         disinclination to do so. --- Douglas Adams, Last Chance to See



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list