Actions are specific to one grammar. When using a combined parser/lexer grammar, use
not just the @header.
When using a separate (non-combined) parser, @header applies to the parser. Likewise, when using a separate (non-combined) lexer, @header applies to the lexer (it is not necessary to use @lexer::header in this case).
Labels:
6 Comments
Hide/Show CommentsSep 09, 2011
Daniel Stoinski
To be sure and not to rely on mysterious defaults, you can also use @lexer::header and @parser::header
Sep 20, 2011
George S. Cowan
I remember thumbing through the Reference and digging in the website to see how to get a header for the lexer. Leaving the parser header general (falsely) and its parallel lexer header specific violates some general law of sensible naming.
ANTLR 4 would be a good opportunity to make the change to the user interface to get rid of this small, time-wasting barrier to successful use of ANTLR.
Sep 21, 2011
Terence Parr
@header is a shorthand for @parser::header, right?
Sep 23, 2011
George S. Cowan
@header is a shorthand for @parser::header, but not for @lexer::header, in the same way that car would be a shorthand for Ford Fusion, but not for Toyota Prius.
Hey, Ter, you're the boss, it's a small thing that I think would help new users – you may have other priorities or disagree entirely.
Sep 22, 2011
Terence Parr
So @header in a lexer doesn't assume @lexer::header? you sure?
Sep 23, 2011
George S. Cowan
There is a situation in which @header does not stand for @lexer::header, namely the situation in which most beginners are working, a combined parser/lexer grammar, or maybe making small changes to the java 1.6 grammar from you and Yang Jiang.
Let's not spend any more time on this conversation. Feel free to delete my comments. – George
Wait, one last thing I want to say: Building a large system to be used by lots of people in a complicated domain like language definition and compiler generation requires great effort and juggling lots of tradeoffs, both technical and human. You have managed to do it. Go my son, do more.