Question: Problem 4 (3 points) Write an F# program to evaluate arithmetic expressions written in the language given by the following context-free grammar: E n I


Problem 4 (3 points) Write an F# program to evaluate arithmetic expressions written in the language given by the following context-free grammar: E n I -E I E E I E E I E E I E E I (E) In the above, n is an integer literal, -E is the negation of E, the next four terms are the sum, difference, product, and quotient of expressions, and (E) is used to control the order of evaluation of expressions, as in the expression 3*(5-1). (1) Use F# type definition (discriminated union type) to define an abstract syntax tree grammar based on the above concrete grammar by completing the following partial solution: type Exp Num of int l Prod of Exp Exp I (hint: add one constructor in the discriminated union type for each rule. No constructor is needed for the parentheses rule). The example given above would simply be represented by
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
