Question: Construct an unambiguous grammar with the below information: Simplified Haskell Types, as described by the ambiguous grammar: T -> var (type variable) T -> con
Construct an unambiguous grammar with the below information:
Simplified Haskell Types, as described by the ambiguous grammar:
T -> var (type variable) T -> con (type constant) T -> T => T (function type) T -> T T (application) T -> ( T ) (parenthesized types)
The words on the right, in parentheses, are just descriptions of what each production describes; they are not part of the grammar. The terminal symbol => is used here in place of the -> symbol that is normally used in Haskell types so that there is no confusion with the -> symbol that we are using to describe our context free grammar.
To resolve the ambiguities in the grammar above, you should use the same conventions as Haskell, which is to treat the arrow operator as grouping to the right with lower precedence than application, the latter grouping to the left. For example, the type:
Either a b -> C -> D
would be interpreted as if it had been written:
((Either a) b) -> (C -> D)
(We assume here that Either, C, and D are lexemes for the con token, and that a and b are lexemes for the var token.)
Examples of strings that should be produced by the unambiguous context free grammar: "var" "con var var" "var var var" "var ( var var )" "var -> var -> var -> var" "(var -> var) -> con"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
