[antlr-interest] Composite grammar issues

Gavin Lambert antlr at mirality.co.nz
Mon Apr 20 12:36:34 PDT 2009


At 07:00 21/04/2009, Kumar Rangarajan wrote:
 >> @parser::header {
 >>  package foo;
 >> }
 >> @lexer::header {
 >>  package foo;
 >> }
 >
 >Sorry, missed replying for this reply. Thanks, Gavin for your
 >suggestion. But I tried this, but this does seem to work as
 >Antlr does seem to allow both @parser::header and @lexer::header 

 >sections in the composite grammar. By default it seems to treat
 >the grammar as a parser grammar and adding '@lexer' triggers an 
error.

Looks like you forgot a couple of "not"s... :)

What is the first line of your grammar file?  It should be just 
"grammar Foo;", not "parser grammar Foo;", if you want to include 
lexer rules within it.  (If you have a separate lexer grammar 
anyway, then it's not an issue -- just define the package in both 
the lexer and the parser separately.)



More information about the antlr-interest mailing list