writing a parser for lambda expressions,
data expr = Symbol of string | Lambda of string * expr | App of expr * expr
When writing the .mly
file how can I express the idea that a sequence of expressions
e1 e2 e3 e4
should be parsed as
App ((App (App e1 e2) e3) e4)
Using the rules:
%public expr_expr:
| ID { Symbol ($1) }
| NUMBER { Symbol ($1) }
| LPAREN expr_expr RPAREN { ($2) }
| LAMBDA ID ARROW expr_expr { Lambda ($2, $4) }
| expr_expr expr_expr { Apply ($1, $2) }
gives the structure (e1 , (e2 , (e3 , e4)))
as opposed to (((e1, e2), e3), e4)
. Is there a way of controlling the associativity of a rule as opposed to a token?