Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 3: A tiny language [Read Chapter 8] Let E (for expression) be a tiny progra

ID: 3585268 • Letter: P

Question

Part 3: A tiny language [Read Chapter 8] Let E (for expression) be a tiny programming language that supports the declaration of arith- metic expressions involving only addition and multiplication, and equality comparisons on integers. Here is an example program in E: When evaluated, this program should evaluate to the truth value true. In this exercise, we will not write E programs as strings, but as values of a Haskell data type E, that can represent E programs as their abstract syntax trees (ASTs). Given the following data type E, data EIntLit Int -- for Int literal, e.g. , (IntLit 3) BoolLit Bool-- for Bool literal, e.g., (BoolLit False) | Plus E E | Mult E E _ for addition _ for multiplication Equals E E deriving (Eq, Show) The above example program is represented as its AST: program = Equals (Plus (IntLit 1) (IntLit 9)) (Mult (IntLit 5) (Plus (IntLit 1) (IntLit 1)))

Explanation / Answer

Mul (BoolLit True) (IntLit 1)

The above equation will output True , as True when converted in IntLit is equal to 1.

and as 1 * 1 = 1

so the output of above expression will be one.