logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Cooper EllisManagement
(5/5)

690 Answers

Hire Me
expert
StatAnalytica ExpertManagement
(5/5)

691 Answers

Hire Me
expert
Michele PerezPhilosophy
(4/5)

863 Answers

Hire Me
expert
Oscar BoltsGeneral article writing
(5/5)

597 Answers

Hire Me
Others
(5/5)

aim of this practical work is to familiarize you with the Prolog language while learning stack-based languages.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

1 Overview

The aim of this practical work is to familiarize you with the Prolog language while learning stack-based languages. As with the previous labs, the steps are as follows: 1. Improve your knowledge of Prolog.

2. Read and understand this data.

3. Read, find, and understand the code provided. 4. Complete the code provided.

5. Write a report. It should describe your experience during the points previous: problems encountered, surprises, choices you had to make, options that you have knowingly rejected, etc. The report should not exceed 5 pages.

2 The Cat language (just a made-up name given to the project not a real language) You are going to write a Prolog program that implements the static semantics (i.e. type inference) and dynamic semantics (i.e. an interpreter) of a little flip language. Push-on languages are languages that have the particularity to use a value stack instead of local variables. E.g. Postscript is a push-on language.

The basic principle is very simple: the code consists of a sequence of operations that modify the stack. E.g. dup takes the item at the top of the stack and adds a copy on top. add takes both elements at the top of the stack, adds them up and replaces them with the result. The operation push V adds the value V to the top of th1e stack; many stack languages drop the push keyword to leave only V to add V to the top of the battery. Thus a code such as [12 75 dup add add] amounts to add 162 to the top of the stack

The Cat language that you need to implement knows the following Val values: 

Num A number.(integer) true The true boolean. false The false boolean. nil The empty list.

X^Xs List made up of element X and list Xs.

[Ops...] Anonymous function made up of Ops operations.

The Ops operations are as follows (I use ToS (Top of Stack) to refer at the top of the stack):

dup

swap pop

get(N )

set(N )

Duplicates the ToS.

Change both to ToS elements. Remove the element from ToS.

Gets the Nth item on the stack and add a copy to the ToS.

get(0) == dup

Take the item from the ToS and then replace the N-th item with this value. [set(0)] == [swap pop]

Val Adds the valueVal to ToS.

add Replace the two elements in ToS by their sum.

if

cons emptyp car

cdr apply papply

Replaces the three elements at ToS by the second or the third depending on whether the first is true or false.

Replace the two elements X and Xs in ToS with the list X ˆX s. Replaces the list in ToS by the boolean which indicates if it is empty. Replaces the ToS list with its head.

Replaces the ToS list with its tail. Calls the function that is in ToS.

Partial application : takes the function F and the value V to the ToS and replaces them with a new function (a closure) which, when called, executes F after adding V to the ToS.

Op : Type Explicit type annotation. Behaves like Op.

So [13 [add] papply] constructs a function which increments the ToS by 13.

The function [] which does not contain any operation corresponds to the function identity.

So [7 [] papply] constructs a function which adds the number 7 to the top of stack and [6 7 [] papply papply] constructs a function that adds 6 and 7 to the stack.

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme