Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Programming Language Concepts
Project 2 - Logic Programming in Prolog
prepare a Prolog program to evaluate prefix arithmetic expressions represented as lists. Assume four operators may be used in expressions and they are +, -, *, and /. All these operators are binary, i.e., they are applied in an expression in this format: [operator, operand1, operand2], where "operator" can be +, -, *, or /, and each operand can be either a single number, or another expression. For ex, the following are all legal input:
[+, 1, 2]
[-, 6, [/, 7, 0.5]]
[*, [/, 78, [-, 67, 3.5]], [+, 4, 9.0]]
But the following are not:
[+, 1] ; missing operand
[6, -, 7] ; every expression must start with an operator
[/, +, 4, 5] ; every expression can only have one operator
[*, 6, 7, 8] ; every expression must have exactly two operands
[%, 6, 7] ; unrecognizable operator
[-, 6, A] ; illegal operator
prepare a predicate named "main" to check the validity of the expression and evaluate the expression. The following should be the way to run your program:
? main([+, 1, 2], X)
X = 3
? main([-, 6, A], X)
error
where [+, 1, 2]and [-, 6, A] are input. If the input is legal, your program should output the final result of the expression evaluation, as shown in the above ex. If the input is illegal, the result is undefined, i.e., your program assumes the input is legal.
Submit your program file at Blackboard Vista by the due date (Check the course schedule).  

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M981789

Have any Question?


Related Questions in Computer Engineering

A companys balance sheet often reflects its business model

A company's balance sheet often reflects its business model and a horizontal or vertical analysis can help you identify one model from another. Using information from the text, compare horizontal and vertical analysis an ...

Maureen has preferences for two goods to be consistent with

Maureen has preferences for two goods to be consistent with the utility function. The price of good 1 is $4 each, and the price of good 2 is $12 each. For what incomes will good 1 be normal?

The systems development lifecycle sdlc provides a

The systems development lifecycle (SDLC) provides a standardized process for all phases of any system development. What are the different phases involved in SDLC give a brief note on all its phases in your own words. (no ...

Three mutually exclusive new designs for an aircraft engine

Three mutually exclusive new designs for an aircraft engine are under consideration. The engine has a ten-year life. The first engine incurs a cost of $1.2 million for a net saving of $300,000 per annum as compared to an ...

In thenbspworkspaceproject-lognbspdirectory create file

In the ~/workspace/project-log directory, create file named  changelog.txt  with the following content and format: Changelog Version: 1.0 Redirect the output of the ls command to a file named  file-list.txt  in the ~/wor ...

Can someone please help me with this examthis is consists

can someone please help me with this exam This is consists of four questions. The questions are designed to test your understanding of certain concepts that were studied over the course of the semester. Please answer all ...

Question 1 using the internet each member of your team

Question: 1. Using the Internet, each member of your team should read at least 3 academically reviewed articles on designing. Summarize the articles in 300 words or more. Provide appropriate reference. 2. Combine each su ...

Recall merge sort sorts a vector of elements rewrite merge

Recall Merge Sort sorts a vector of elements. Rewrite Merge Sort to sort a list of elements. You may use your own List or STL list. This must be in C++. Write your own version of merge_sort(), merge(), and copy() functio ...

Why is it important to back up the dhcp database and

Why is it important to back up the DHCP database and Identify key files that make up the DHCP database?

Solution must be recursive you are not allowed to use loops

Solution must be recursive. You are not allowed to use loops, or use the Python "in" operator. PYTHON Write a function called first. It is passed a parameter x, that may or may not be a list; if is x is a list it may con ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As