Question
Exercise 3. (evaluation of arithmetic expressions with variables) Let us consider an arithmetic expression described by a tree constructed from tuples as follows: 1. An
Exercise 3. (evaluation of arithmetic expressions with variables) Let us consider an arithmetic expression described by a tree constructed from tuples as follows: 1. An integer is described by a tuple int(N), where N is an integer. 2. An addition is described by a tuple add(X Y), where both X and Y are arithmetic expressions. 3. A multiplication is described by a tuple mul(X Y), where both X and Y are arithmetic expressions. 4. A variable is described by a tuple var(A), where A is an atom giving the variable name. An environment is a record with a label env and for each variable name there is a feature which corresponds to an integer value. For example, the record env(a:2 b:4) says that the variable a has value 2, whereas the variable b has value 4 (note that the Oz features should start with a lowercase letter). For example, add(var(a) mul(int(3) var(b))) is an arithmetic expression containing two variables (namely a and b) and its evaluation returns 14. Give a specification and an Oz implementation of a function Eval that takes as arguments an arithmetic expression and an environment, and returns its value. For example, the call {Eval add(var(a) mul(int(3) var(b))) env(a:2 b:4)} should return 14.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started