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

Christian Schladetsch christian.schladetsch at gmail.com
Tue May 26 22:35:08 PDT 2009


Apologies, I am using ANTLR 3.1 with C runtime.

On Wed, May 27, 2009 at 5:33 PM, Christian Schladetsch <
christian.schladetsch at gmail.com> wrote:

> 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/6885c755/attachment.html 


More information about the antlr-interest mailing list