What happens is that your expressions / expressions support single parentheses, but not multiple parentheses (as you concluded). I have no specific ANTLR experience, but I worked with Javacc, which shares a lot of similar concepts (I wrote a grammar for Prolog ... I don't ask).
To handle nested parentheses, you usually have something similar to:
ParenthesisExpression: '(' (ParenthesisExpression | Expression) ')';
This would mean that the expression is either wrapped in parentheses or just a raw expression. As for how AST handles this, ParenthesisExpression is an βexpressionβ, so it can be represented as a subclass or implementation (if the expression is an interface / abstract class).
source share