
Hello. I am learning how to use Happy (a LALR(1) parser generator) and I have a question on a grammar based on an example from the manual. The input file to Happy is attached to this message. The grammar is: Exp -> let var = Exp in Exp Exp -> Exp + Exp Exp -> Exp - Exp Exp -> Exp * Exp Exp -> Exp / Exp Exp -> ( Exp ) This grammar is ambiguous, but the conflicts that will appear in the parser table can be resolved with precedence and associativity declarations for the operators that surround expressions: %right in %left + - %left * / giving right associativity to the in token, and left associativity to the arithmetic operators, and giving lower precedence to in, followed by + and -, and then by * and /. I see that if the token in is not given a precedence declaration, the grammar still is ambiguous, as can be seen in the example of parsing the expression: let v = e1 in e2 + e3 which could be parsed as (let v = e1 in e2) + e3 or let v = e1 in (e2 + e3) Giving the token in a lower precedence makes the parser choose the last option. My question is about the associativity of the token in? Does it make any difference giving it left associativity, right associativity, or making it non associative? Regards. José Romildo