[antlr-interest] Retrieving Line and Column information in AST

Christian Schladetsch christian.schladetsch at gmail.com
Tue May 26 22:33:53 PDT 2009


Hello,

I would like to add file+line+column information to code generatedfrom an
AST tree.

IE:

// in lexer
statement:
    :    'for' '(' start=expression? ';' cond=expression? ';'
next=expression? ')' body=statement
        -> ^('for' $cond $next $body $start )
    ...
    ;

// in tree
statement
    :    ^('for' cond=continuation step=continuation body=continuation
expression)    { AppendOp(Operation::ForLoop); }
    ...
    ;

My question is, how can I access file, line and column information for
tokens used by the tree parser? in the example above, how can I access the
location of the 'for' token used in the tree grammar to pass to the
AppendOp() function?

Similarly, I'd like to add debug (file+line+column) info for all generated
objects.

Thanks in advance,
Christian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090527/2c9add5e/attachment.html 


More information about the antlr-interest mailing list