The predicate should take two arguments

Assignment Help Basic Computer Science
Reference no: EM13542262

Prolog Program: The predicate should take two arguments: a list corresponding to the program to execute, and a list corresponding to the contents of the resulting stack.
If any error occurs in parsing or executing the program (including stack underflow or unrecognized command words),the predicate should simply fail, in the Prolog sense.
example: main([1,2,4,+,*,9],X).
X=[12,9]
the way it is done is: when a + is encountered, the first two elements of the list are taken out and are added and the result is put back in the list, the list now becomes [3,4,*,9].
Further a * is encountered, hence it should multiply 3 and 4 and 12 should be added to the list, the list now becomes [12,9] since there are only integers remaining in the list [12,9] is the final result.

The predicate should fail if list is empty, or for the following examples,
[12,+]-not enough elements to do the operation,
[+,-], no integers
etc

the following are the operations that are needed to be implemented
+ ( n1 n2 -- sum ) Adds (n1 + n2).
- ( n1 n2 -- diff ) Subtracts (n1 - n2).
* ( n1 n2 -- prod ) Multiplies (n1 * n2).
/ ( n1 n2 -- quot ) Divides (n1 / n2), using integer division (truncates).
/MOD ( n1 n2 -- rem quot ) Divides. Returns the remainder and quotient.
MOD ( n1 n2 -- rem ) Returns the remainder from division.
= ( n1 n2 -- equal ) Compares for equality (n1 == n2). Indicates false with the value zero, and true with the value -1.

Reference no: EM13542262

Questions Cloud

Society is more important than the individual : Society is more important than the individual. Discuss with reference to Marx (1844 Manuscripts) and Durkheim (Suicide).
Implement one of demings points each year : Implement one of Demings points each year, do you believe that this methodology would be effective? Why or why not?
Businesses today are extremely reliant on large amounts : Businesses today are extremely reliant on large amounts of data for making intelligent business decisions. Likewise, the data warehouses are often structured in a manner that optimizes processing large amounts of data.
A large software development company : Suppose you are an internal investigator for a large software development company
The predicate should take two arguments : The predicate should take two arguments: a list corresponding to the program to execute, and a list corresponding to the contents of the resulting stack.
How do your organizations deal with affirmative action : Identify a specific job and discuss the environmental factors could affect the selection process for it - compare the ways that discipline is typically handled in unionized versus union-free firms.
Three strategic considerations : Three strategic considerations when developing a media schedule?
Explain how organizational behavior has influenced : Provide a brief background on the organization and its objectives and explain how organizational behavior has influenced the organization's effectiveness over the last 5 years.
What does the water content of the sludge need to be : First, it is thought that the sludge can be incinerated. If the heat value of dried sludge is 12,804KJ/Kg dry solid and the heat of vaporization of water is 40.656KJ/mol of water, what does the water content of the sludge need to be in order to "brea..

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Draw the block diagram for the hardware

Draw the block diagram for the hardware that implements the following: y + xz: AR ß BR + CR where AR, BR and CR are n-bit registers and x, y, and z are control variables.

  Determine the maximum number

Determine the maximum number Determine the range (maximum - minimum) Displays a histogram that shows the numbers in each five-unit range.

  Review and discuss methods for it manager

Review and discuss methods for IT managers to maintain their skills while gaining new managerial skills

  Write a function in c language with prototype

write a function in C language with prototype.

  Represent processor demand in the time interval

Let the function D[i, j] represent processor demand in the time interval (i, j). Prove the following theorem.

  Why can i only see up to the index of this book

Why can I only see up to the index of this book? I understand it's a large book and you may only want to give the reader access to part of the book, but if it's read only until I get my book in the mail, why can't I see the whole book

  Transform g to an equivalent g'' that has no

Let G be a context free grammar with productions S->ABAC , A->aA|? , B->bB|? , C->d Transform G to an equivalent G' that has no ? productions and no unit productions

  How can these limitations be overcome

What are the data limitations that occur when creating cookies from JavaScript® language? How can these limitations be overcome?

  The board game scrabble

The board game Scrabble works by assigning points to wooden tiles that are marked with printed letters, and are arranged as interlocking words on a Scrabble board.

  Display the converted expression

Spaces between tokens are allowed but not required. The program will convert the expression to postfix (RPN) form and display the converted expression.

  Instruction cycle and finding contents of registers

Go over instruction cycle and find out contents of registers PC, AR, DR, AC, and IR for each of seven memory-reference instructions.

  Describe how these tips are implemented

Describe how these tips are implemented and why these are important.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd