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

  Translate the given code into mips64 assembly language

you can use the instructions 'blt' (branch on less than), 'ble' (branch on less or equal), 'bgt' (branch on greater than) and 'bge' (branch on greater or equal) - Translate the given code into MIPS64 assembly language.

  Create program in visual studio-produce summary of ammounts

Create the program in Visual Studio, C#, 3.5 .Net that will produce the summary of amounts due for Pat's Auto Repair Shop. Display splash screen first.

  Recursive method to search a string for a byrd

Write a recursive method that searches a string for a Byrd. A Byrd has the following properties. Its first character is an 'A'. If it is a two character Byrd then its second and last character is an 'H'.

  Estimate probability of default for a credit application

What would you suggest as the target variable and what would you recommend that Joe do to achieve his business goal?

  Provide an analogous response when adding the two positive

What is the range of values that the multiplication of those two numbers (a ? b) will have - Provide an analogous response when adding the two positive n-bit and m-bit numbers (a + b).

  Write code to find largest value found in parking tickets

Without using any additional variables, write some code that results in mostTickets containing the largest value found in parkingTickets.

  Write program that would estimate magnitude

Write a program that would estimate the magnitude (liters/day) and cost of the water saved based on the community's population.

  Write down a program to input widths of both hallways

Write down a program which prompts user to input widths of both hallways. The program then outputs length of longest pipe.

  Design a modularized body mass index program

Design a modularized Body Mass Index (BMI) Program which will calculate the BMI of a team player. The formula to calculate the BMI is as follows:

  Program that will call a function called writedatatofile

Write a program that will call a function called writeDataToFile to prompt a user for their first name, last name and zip code, and print this information to a file called "UserData.txt".

  Write program to perform arithmetic operations on fractions

Write a program that lets the user perform arithmetic operations on fractions. Fractions are of the form a/b, where a and b are integers and b is not equal to 0.

  Prompt for user login to begin using the system

Suggest an application system which is able to perform some arithmetic computations, like commission system, encryption system, timer system, etc, from anyone of the following industry.

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