Why doesn't my header show up in the lexer as well as the parser?

Skip to end of metadata
Go to start of metadata

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).

  1. Sep 09, 2011

    To be sure and not to rely on mysterious defaults, you can also use @lexer::header and @parser::header

  2. Sep 20, 2011

    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.

  3. Sep 21, 2011

    @header is a shorthand for @parser::header, right?

  4. Sep 23, 2011

    @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.

  5. Sep 22, 2011

    So @header in a lexer doesn't assume @lexer::header? you sure?

  6. Sep 23, 2011

    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.