I'm trying to write a Haskell-style language parser in ANTLR4, but I'm having some issues with function application. It parses as right associative rather than left associative
expression :
unit #UnitExpression
| IntegerLiteral #IntExpression
| FloatLiteral #FloatExpression
| CharLiteral #CharExpression
| StringLiteral #StringExpression
| LSquareParen (expression (Comma expression)*)? RSquareParen #ListExpression
| LParen expression RParen #ParenExpression
| LParen (expression (Comma expression)+) RParen #TupleExpression
| expression operatorIdentifier expression #OperatorApplicationExpression
| expression (expression)+ #FunctionApplicationExpression
| variableIdentifier # VariableExpression
;
This is the relevant part of the grammar , the issue is that when I write something like f a b it parses as f (a b) rather than (f a) b
The actual example I was using was f "a" "b", which seemed even more confusing since String literals have higher precedence than function application.
I also tried rewriting to expression+ expression which didn't work because it's mutually left recursive apparently
How can I make this work?
