Ambiguous call expression in ANTLR4 grammar
I have a simple grammar (for demonstration) grammar Test; program : expression* EOF ; expression : Identifier | expression '(' expression? ')' | '(' expression ')' ; Identifier : [a-zA-Z_] [a-zA-Z_0-9?]* ; WS : [ \r\t\n]+ -> channel(HIDDEN) ; Obviously the second and third alternatives in the expression rule are ambiguous. I want to resolve this ambiguity by permitting the second alternative only if an expression is immediately followed by a '(' . So the following bar(foo) should match the second alternative while bar (foo) should match the 1st and 3rd alternatives (even if the token between