[antlr-interest] AST tutorial

Thomas Brandon tbrandonau at gmail.com
Wed Aug 2 02:49:38 PDT 2006


On 8/2/06, Herumor <herumor at fastwebnet.it> wrote:
<SNIP>
>   loop_cond
>  : SEMICOLON!
>  { #loop_cond = #([NULL_NODE, "null_cond"]); }
>  | expr SEMICOLON!
>  ;
>
> the meaning of this kind of expressions.
You want AST Action Translation in the ANTLR Tree Construction section
of the documentation - http://www.antlr.org/doc/trees.html#_bb9. That
is an action where various parts are rewritten by ANTLR for AST
constuction, "#loop_cond" refers to the output AST of the rule,
"#(...)" constucts a tree with the first specified node as root and
subsequent nodes as children, "[NULL_NODE, "null_cond"]" constructs a
synthetic node of type NULL_NODE with text "null_cond". So that will
output the tree "(NULL_NODE)" for that alternative.

Tom.

> Davide Pugliese
>


More information about the antlr-interest mailing list