Why doesn't my header show up in the lexer as well as the parser?
Actions are specific to one grammar. When using a combined parser/lexer grammar, use // applies only to the parser: @header // applies only to the lexer: @lexer::header not just the @header. When using a separate (noncombined) parser, @header applies to the parser ...
Action execution during backtracking
ANTLR must parse ahead to see if something matches. If it fails, then ANTLR tries the next viable alt. Upon failure, it's pretty hard to undo actions in general so ANTLR gates actions out with something like this: if ( backtracking==0 ) Labels ...