[antlr-interest] Tree construction

Ivan Yu Titov ITitov at beeline.ru
Tue May 13 05:51:28 PDT 2008


      Hello,

      I need to parse input "%a%b%c" into the tree. This tree should be
like this (well-know example):

       +
      /  \
%a     +
           /  \
     %b   %c

      After lexer I have three tokens (%a, %b, %c). How can I apply to it
following construction:

      expr: id ('+'^ id)*;    ?

Below is my grammar:

grammar Expr;

id
      :     Reference
      ;

Reference
      :     '%' Identifier
      ;

fragment
Identifier
      :     Letter (Letter | Digit | '_')*
      ;

fragment
Letter      :     'a'..'z' | 'A'..'Z'
      ;

fragment
Digit :     '0'..'9'
      ;



More information about the antlr-interest mailing list