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

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!