I have a grammar that includes this rule:
expr:
unaryExpr '(' (stat | expr | constant) ')' #labelUnaryExpr
| binaryExpr '(' (stat | expr | constant) ',' (stat | expr | constant) ')' #labelBinaryExpr
| multipleExpr '(' (stat | expr | constant) (',' (stat | expr | constant))+ ')' #labelMultipleExpr
;
For expr, I can access the value of unaryExpr by calling ctx.unaryStat(). How can I access (stat | expr | constant) similarly? Is there a solution that doesn't require modifying my grammar by adding another rule for the group?
Since you've labelled you alternatives, you can access the
(stat | expr | constant)in its respective listener/visitor method: