Implement the evaluator for the language

Assignment Help Programming Languages
Reference no: EM13843609

Submit this Haskell file with the questions completed.

**What you can use.** In this assignment, you can use anything from the lectures, the given Haskell file (including what's imported) and anything in the Prelude. Nothing more though. The first two import lines at the beginning of the file can be ignored. They're just for the parser. The next two are useful but you don't need to use them.

**Debugging.** You might find the debugger useful. It's imported above. It's quite easy to use the basic tracing facility. See the Haskell Hierarchical Libraries documentation for info on how to use it:

https://downloads.haskell.org/~ghc/latest/docs/html/libraries/

The assignment is to implement the evaluator for the language L discussed in class. You should review the notes from that class. There is also a complete description of the language in this file.

## Description of L

Expressions (abstract and concrete syntax):

%x.e -- lambda abstraction, like \x->e in Haskell
e e' -- application
x,y,z -- variables
succ, pred, ifzero, 0, 1, 2....

Values:

0, 1, 2, 3,...
%x.e
succ, pred, ifzero
ifzero e
ifzero e e

Evaluation: e ==> v means e evaluates to value v. The rules below specify how to evaluate.

For an algorithmic view, you can read the rules bottom-up. E.g. the second rule can be read as saying that to evaluate an application expression e e', first evaluate e, and if you get a value of the form %x.b, continue by evaluating b[e'/x], and if that results in a value v, return that as the result of evaluating e e'.

There's a more algorithmic presentation of evaluation in the lectures notes. There are a few small differences, so please use the definition below as the specification for your evaluator.

-- QUESTION 1:
--
-- subst x e e': substitute e for all "free" occurrences of (Var x) in
-- e'. "Free" means that the variable it is not declared by a
-- surrounding %. For example, in the expression
--
-- x (%x. x (%y.xz)) (%y.x)

-- there are 5 occurrences of x. The first is "free". The second is
-- the parameter for the % expression and is never substituted for.
-- The third and fourth occurrences refer to the parameter of the
-- enclosing % expression. The fifth is free. Therefore if we
-- substitute 0 for x we get 0 (%x. x (%y.xz)) (%y.0)
subst :: Id -> Exp -> Exp -> Exp
subst = stub "subst"

-- QUESTION 2:
--
-- isClosed e is true if and only if there are no free variables in e
-- (see the discussion in the comment for subst).
-- Examples: (%x. %y. x y) is closed; (%x. y %y. x y) is not since the
-- first occurrence of y is free.
isClosed :: Exp -> Bool
isClosed = stub "isClosed"

-- QUESTION 3:
--
-- eval e = v where e ==> v. If there is no v such that e==>v, the
-- result is undefined. Assume that e is closed.
eval :: Exp -> Exp

eval = stub "eval"

run :: Exp -> String
run e =
if isClosed e
then pp $ eval e
else error "run: expression must be closed"

stub :: String -> a
stub s = error ("Not implemented: " ++ s)


Attachment:- assignment.zip

Reference no: EM13843609

Questions Cloud

Determining inventory at lower of cost or market : Determining Inventory at Lower of Cost or Market
Summarise the governance problems and suggest solutions : Summarise the Governance problems and suggest solutions. Using Borne and Walker's article as a guide (see embedded object below), identify two stakeholders.
Swot analysis of a large technology company : Look at your organization (or one similar to it) and perform a SWOT analysis. For any reason you cannot use your organization, do a SWOT analysis of a large technology company such as Google, Microsoft, Oracle, Cisco and Apple. C
Does imprecision pose a problem : Does this imprecision pose a problem for anyone wanting to achieve Aristotle's notion of living a virtuous and happy life?
Implement the evaluator for the language : Implement the evaluator for the language L discussed in class. You should review the notes from that class. There is also a complete description of the language in this file.
Create a project schedule for process of hiring new employee : You need to create a project schedule for the process of hiring a new employee for your department. OPEN a new blank project schedule. Set the project start date to be October 19, 2015.
Calculate the cash flow effect of nickolas restructuring : Calculate the cash flow effect of Nickolas restructuring during fiscal 2014 - What affect did this have on The Bean's consolidated income statement for the current year?
Know about feeding pamela? : know about feeding Pamela?
How does wind increase transpiration? : How does wind increase transpiration?

Reviews

Write a Review

Programming Languages Questions & Answers

  Modeling a game using turing machine

Modeling a Game Using Turing Machine, Select a game that can be modeled by a simple Turing machine. It should take a series of inputs (such as a set of moves by a player) and use the tape and table to compute the outcome of whether the player won o..

  Write statement that calls add to compute sum of sales

Add is a method that accepts two int arguments and returns their sum. Write a statement that calls add to compute the sum of euroSales and asiaSales and that stores this value in eurasiaSales .

  Write a single line for body of constructor to create object

Create the constructor Orb(int xSpeed, int ySpeed). Write a single line for the body of the constructor,which creates a new Velocity object.

  Program has function named presentvalue for calculations

Write a program that has a function named presentValue that performs this calculation. The function should accept the future value, annual interest rate, and number of years as arguments.

  Write method that accepts as parameter reference

Write a method maxVal that accepts as parameter the reference to the head node of a linked list of integers. The method should return the largest value in the list.

  Create new program which prompts user for numbers

Create a new program whihc prompts a user for numbers and determines total revenue using following formula: Total Revenue = Price * Quantity.

  Progarm to calculate unit price for products sold

Manager of Super Supermarket would like to be able to calculate unit price for products sold there. To do this, program must input name and price of the item and its weight in pounds and ounces.

  Display policy data after revisions have made

The day is not correct for the month (that is, between 1 and 31 for January, 1 and 29 for February, and so on), then set the month, day, and year to 0. Display the policy data after any revisions have been made.

  Write menu driven program that make coffee shop operational

Jason has opened a coffee shop at the beach and sells coffee in three sizes: small (9oz) medium (12oz) and large (15oz). Small cost is $1.75 medium costs $1.90 and large costs $2.00. Write a menu driven program that will make the coffee shop opera..

  Arguments for and against allowing mixed-mode arithmetic exp

1). State your own arguments for and against allowing mixed-mode arithmetic expressions.

  Create application to generate a series of random numbers

Create the application to generate a series of 100 random numbers in the range of 1 through 1000. Save the series of numbers in a file.

  London underground fire at the kings cross underground

london underground fire at the kings cross underground station on 18 november 1987 a wooden escalator caught fire

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