[antlr-interest] the # symbol in target language blocks

Ana Nelson nelson.ana at gmail.com
Mon Jun 23 09:04:35 PDT 2008


Hi,

I have been trying to parse ANTLRv3.g using somethiing other than
ANTLR (I know, I know, but I have my reasons).

Things were going very smoothly until I started hitting the "#" symbol
within target language blocks for actions, for example "#notSet" in
this excerpt:

notSet
@init {
    int line = LT(1).getLine();
    int col = LT(1).getColumn();
    GrammarAST subrule=null;
}
    :    n='~'^
        (    notTerminal
        |   block
        )
        {#notSet.setLine(line); #notSet.setColumn(col);}
    ;


So after some digging I think this is referring to AST action
translation in ANTLR v2:

http://www.antlr2.org/doc/trees.html#_bb9

"In parsers and tree parsers with buildAST set to true, ANTLR will
translate portions of user actions in order to make it easier to build
ASTs within actions. In particular, the following constructs starting
with '#' will be translated: "

So, is this use of # within a target language block just a holdover
from version 2 because ANTLR still uses version 2 internally?


More information about the antlr-interest mailing list