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.
-
Name the class to which each of the compounds used in this experiment belongs (eg. alcohol, alkane, ester, etc.)
-
Based on all three estimates and on the valuation figures for the three competitors how much per share do you think that Orange Brite is really worth? Explain your rationale.
-
Alternatives 1, 2, and 3 have lives of 3, 4, and 6 years, respectively. Their net cash flow (NCF) and salvage value (SV) profiles are as follows: Additional explanation is necessary: The NCF profile...
-
Rehab Health Care, LLC, incurred the following service-related activity costs for the month: Total sales ................$42,000 Customer complaint processing ....... 1,200 Employee training...
-
The output of the following code is: var x=5; var y="10"; if (x < y ) { } alert("x < y"); else if (x > y) alert("x > y"); { } else{ alert("x = y"); }
-
Consider a vibrating system of your choice modeled by y" + cy' + ky = (t). (a) Using graphs of the solution, describe the effect of continuously decreasing the damping to 0, keeping k constant. (b)...
-
2. An okra fami anticipates highly seasonal demand for their product, tender pods of okra that can be made into the new drink sensation, the okra colada. Their estimate of the demand profile appears...
-
A fairly priced unlevered firm plans to pay a dividend of $2 next year (t=1) which is expected to grow by 5% pa every year after that. The firm's required return on equity is 12% pa. The firm is...
-
A popcorn company wishes to make recommendations to its customers about the right cooking time and cooking temperature for its microwave popcorn. The company investigated the effect of two times (2...
-
The tableshows the Market Capitalization, Enterprise Value and multiples for a number of firms in the newspaper publishing industry.Another newspaper publishing firm (not shown) had sales of $24...
-
Each business day, on average, a company writes checks totaling $13,400 to pay its suppliers. The usual clearing time for the checks is four days. Meanwhile, the company is receiving payments from...
-
Find f'(x) and f'(c). Function f(x) = (x3 + 2x)(5x4 + 5x-2) Value of c c = 0 f'(x) = f'(c) = C
-
Do you feel your peer's responses spoke "truth to power" sufficiently in their response to the CFO? Since you are not the director of quality at the hospital, is it ever your role to speak "truth to...
-
What are the risks and liability factors in an audit? What are the implications to the auditor? What are the implications to the organization? How can the auditor mitigate these risks and liability...
-
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)?
-
On June 3, 2019, Catherine Shanahan received an unsolicited phone call on her cell phone. When she answered, she heard a prerecorded voice message advertising extended automobile warranties (Service...
-
John Whalen was employed by the City of Binghamton as the director of Parks and Recreation. In his capacity as the director, Whalen was to collect various fees and was entrusted with related funds....
-
On August 14, 2018, Jane Doe asked her boyfriend to call an Uber for her as Does phone had low battery. Does boyfriend was not with her, so she did not know which driver Uber had assigned to pick her...
Study smarter with the SolutionInn App