In a rule expr : expr '<' expr | ...;
the ANTLR parser will accept expressions like 1 < 2 < 3
(and construct left-associative trees corrsponding to brackets (1 < 2) < 3
.
You can tell ANTLR to treat operators as right associative, e.g.
expr : expr '<'<assoc=right> expr | ...;
to yield parse trees 1 < (2 < 3)
.
However, in many languages, relational operators are non-associative, i.e., an expression 1 < 2 < 3
is forbidden.
This can be specified in YACC and its derivates.
Can it also be specified in ANTLR?
E.g., as expr : expr '<'<assoc=no> expr | ...;
I was unable to find something in the ANTLR4-book so far.