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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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