Assuming your tree is just a 1-dimensional list of nodes, here you can create a hierarchy of parents / sisters:
In ANTLR, there are two operators for creating an AST:
! excludes the node (token) from the (sub)tree;
^ makes a node the root of a (sub)tree.
If no operator is specified, nodes / tokens are added as children of the current root. This probably happened to you: everything you see is a one-dimensional list of nodes / tokens.
Example:
grammar Exp;
options {output=AST;}
addition
: Integer '+'^ Integer ';'!
;
Integer
: '0'
| '1'..'9' '0'..'9'*
;
The rule additionwill create the following tree for the expression 6+9;:
+
/ \
/ \
6 9
As you can see: +- this is the root (after it it has ^), numbers are tokens (they do not have an operator), and half points are excluded (after it there is !).
. 7 " " ANTLR. .
, , . , , . : ANTLR.
!