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 arithmeticexpressions written in the language given by the following context-free grammar: E

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!