Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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