Question: Write a prolog predicate to evaluate an expression tree. For example the representation in prolog for (1+5) * 2 would be [xmul,[xadd,[xint,1],[xint,5]],[xint,2]]. Implement the predicate
Write a prolog predicate to evaluate an expression tree. For example the representation in prolog for (1+5) * 2 would be [xmul,[xadd,[xint,1],[xint,5]],[xint,2]]. Implement the predicate evaluate(X,Y) which means the result of evaluating tree X is Y. Examples of test cases that should evaluate to true : evaluate([xadd,[xint,4],[xint,5]], 9) and evaluate([xint,1], 1).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
