Question: If T is an arithmetic parse tree, we associate a value with T (which we call value(T)) by the following recursive rule: if T has

If T is an arithmetic parse tree, we associate a value with T (which we call value(T)) by the following recursive rule: if T has a single (leaf) node, value(T) is equal to the numeric value of the node, if T has two subtrees, L and R, and its root node contains the operator +, then value(T) = value(L) + value(R), if T has two subtrees, L and R, and its root node contains the operator , then value(T) = value(L) value(R), if T has one subtree, S, and its root node contains the operator , then value(T) = value(S), if T has one subtree, S, and its root node contains the operator 1/, then value(T) = 1/ value(S).

An arithmetic parse tree for the expression 2 3 + (4 + (5)) (1/6). Write a SCHEME function, named (nvalue T), which, given an arithmetic parse tree, computes the value associated with the tree. You may assume that the operators +, , , and 1/ appear in the tree as the characters #\+, #\*, #\-, and #\/

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!