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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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