1. In this assignment, you will develop an interpreter for a small language, called SpartanLang. The...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. In this assignment, you will develop an interpreter for a small language, called SpartanLang. The valid expressions for SpartanLang are given in Figure 1. SpartanLang supports mutable references. The state of these references is maintained in an environment, a mapping of variables to values. With mutable references, other language constructs become more useful, such as sequencing operations (e1; e2). Expressions values e ::= assignment variable dereferencing (i.e. getting a variable's value) sequential expressions binary operations conditional expressions while expressions I := e !x e; e e op e if e then e else e end while e do e end v ::= Values integer values boolean values i b op ::= +|- | * | > | >= | < | <= Bìnary operators Figure 1: Expressions in SpartanLang 2 YOUR ASSIGNMENT Create an interpreter for SpartanLang. You can assume that the parsing has been done for you - your job is to write an interpreter when given an abstract syntax tree (AST). Download interp.rkt from the course website and implement the evaluate function, as well as any additional functions it uses. The file test.rkt provides some additional testing cases (though not necessarily a comprehensive set of tests). The files parser.rkt and sl-run.rkt allow you to run on programs written in text files; test1.sparta is provided as an example. The input to evaluate consists of two arguments, an expression and the environment. The expression will be represented as a struct, which could be: • sp-val, representing some constant (such as 42 or true). 1. In this assignment, you will develop an interpreter for a small language, called SpartanLang. The valid expressions for SpartanLang are given in Figure 1. SpartanLang supports mutable references. The state of these references is maintained in an environment, a mapping of variables to values. With mutable references, other language constructs become more useful, such as sequencing operations (e1; e2). Expressions values e ::= assignment variable dereferencing (i.e. getting a variable's value) sequential expressions binary operations conditional expressions while expressions I := e !x e; e e op e if e then e else e end while e do e end v ::= Values integer values boolean values i b op ::= +|- | * | > | >= | < | <= Bìnary operators Figure 1: Expressions in SpartanLang 2 YOUR ASSIGNMENT Create an interpreter for SpartanLang. You can assume that the parsing has been done for you - your job is to write an interpreter when given an abstract syntax tree (AST). Download interp.rkt from the course website and implement the evaluate function, as well as any additional functions it uses. The file test.rkt provides some additional testing cases (though not necessarily a comprehensive set of tests). The files parser.rkt and sl-run.rkt allow you to run on programs written in text files; test1.sparta is provided as an example. The input to evaluate consists of two arguments, an expression and the environment. The expression will be represented as a struct, which could be: • sp-val, representing some constant (such as 42 or true).
Expert Answer:
Answer rating: 100% (QA)
kindly check the solutions below Working code implemented in C and appropriate comments provided for better understanding Here I am attaching code for all files maincpp parseRuncpp parseRunh valcpp va... View the full answer
Related Book For
Posted Date:
Students also viewed these computer network questions
-
Write a one to two-page commentary (using current APA format) on how selected technological innovations have impacted society in a positive way. PROJECT OVERVIEW In this assignment, you will visually...
-
2017 Subaru Legacy Sedan 4 cyl 4 Door Sedan with 136,300 miles. The customer complaint is that when they put their Right Directional on it has a steady clicking/blinking sound coming from their...
-
Write a small C++ program. Your program should compile correctly and produce the specified output. Please note that the computer program should comply with the commenting and formatting rules as has...
-
Explain how the structure of the balance sheet corresponds to the accounting equation.
-
Consider the differential equation y' = f (t, y), a t b, y(a) = . a. Show that for some , where ti b. Part (a) suggests the difference method wi+2 = 4wi+1 3wi 2hf (ti ,wi), for i = 0, 1, . . . ,...
-
A child with a weight of 120 N swings on a playground swing attached to 2.20 m long chains. What is the gravitational potential energy (in J) of the child-earth system relative to the child's lowest...
-
Quantum Computer Company is considering the purchase of automated machinery that is expected to have a useful life of 4 years and no residual value. The average rate of return on the average...
-
You have just been instructed to develop a schedule for introducing a new product into the marketplace. Below are the elements that must appear in your schedule. Arrange these elements into a work...
-
The goal of this project is to explore the topic of bond valuation. The project requires you to work in Excel with the provided spreadsheet. Be sure to fill in the yellow boxes in the Excel file for...
-
1. You borrow $50,000 for 5 years. This is an amortized load, meaning that payments are the same each month, and the loan is fully paid off with final payment. The quoted interest rate (or APR) is...
-
Problem 4: Can a p = 22, k = 1, Np = 10 gear be used as a pinion without undercutting? Circle the correct answer. Show all calculations. No, there will always be interference Yes, it can be used as a...
-
Plaintiff Daniel Sanders residing in Forest Hills, New York, in Queens County. He is a Correction Officer employed by the New York City Department of Correction ("DOC"). DOC operates the City's jails...
-
Sheridan Company estimates that annual manufacturing overhead costs will be $1,140,000. Estimated annual operating activity bases are direct labor cost $570,000, direct labor hours 57,000, and...
-
Mr Goode and Reticent Bank Limited had entered into a margin lending agreement called a Margin Lending Loan and Security Agreement (LSA). In January 2009, RBL sold to Financial Innovators Bank...
-
The functions & and s are defined as follows. r(x) = -2x+2 s(x)=2x+1 Find the value of r (s (-2)).
-
Discuss the impact of Microsoft Windows on the Software market?
-
Anlisis No. 2 DEVELOPMENT AND BUDGET PLANNING esi school Problema Un grupo de inversionistas se encuentra valorando diferentes opciones de proyectos empresariales para lo cual le presentan la...
-
What is an access control list?
-
Write a program that prints a two-column list of your friends birthdays. In the first column, print the names of your best friends; in the second, print their birthdays.
-
Improve the program of Exercise E6.15 to work correctly when the data set contains negative values. Data from Exercise E6.15 Repeat Exercise E6.15, but make the bars vertical, with the tallest bar...
-
Suppose a double value a is 0.6 and b is 0.3. What is the result of (int)(a - b)? Of (int)(b - a)? What is the result of Double.compare(a, b)? Of Double.compare(b - a)?
-
Match each of the following roles of a cost management system, 1 through 6 , with the most appropriate example, a through \(f\). Cost Management System Role 1. Develop accurate product/ service costs...
-
A cost management system is made up of three primary elements: (1) motivational elements, (2) informational elements, and (3) reporting elements. Classify each of the following items, a through...
-
Stock options and stock grants are often utilized to compensate executives. The general rule is that the fair value of the compensation award is determined at the grant date and expense is recognized...
Study smarter with the SolutionInn App