Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CMSC 4 3 0 Project 3 The third project involves modifying the attached interpreter so that it interprets programs for the complete language. When the
CMSC Project
The third project involves modifying the attached interpreter so that it interprets programs for the
complete language.
When the program is run on the command line, the parameters to the function should be supplied
as command line arguments. For example, for the following function header of a program in the
file text.txt:
function main x: integer, y: integer returns character;
One would execute the program as follows:
$ compile test.txt
In this case, the parameter x would be initialized to and the parameter y to An example
of a program execution is shown below:
$ compile test.txt
Determines the quadrant of a point on the xy plane
function main x: integer, y: integer returns character;
begin
if x then
if y then
;
elsif y then
;
else
Y;
endif;
elsif x then
if y then
;
elsif y then
;
else
Y;
endif;
else
if y then
X;
else
O;
endif;
endif;
end;
Compiled Successfully
Result
After the compilation listing is output, the value of the expression which comprises the body of
the function should be displayed as shown above.
The existing code evaluates some of the arithmetic, relational and logical operators together with
the case statement and decimal integer and real literals only. You are to add the necessary code
to include all of the following:
Hexadecimal integer and character literals that include escape characters
All additional arithmetic operators
All additional relational and logical operators
Both if and fold statements
Functions with multiple variables
Functions with parameters
The fold statement repeatedly applies the specified operation to the list of values, producing one
final value. A left fold associates the operator left to right and a right fold right to left. For
example, the following left fold:
fold left endfold;
would be evaluated as but using a right fold:
fold right endfold;
It would be evaluated as For operations that are associative, the result would be
the same whether it is as folded to the left or right.
This project requires modification to the bison input file, so that it defines the additional the
necessary computations for the above added features. You will need to add functions to the
library of evaluation functions already provided in values.cc You must also make some
modifications to the functions already provided.
Here is the recommended approach for project
Study the skeleton project provided, build it and run it so that you understand how semantic
actions are used to perform the evaluation needed to interpret programs in our language.
You should incorporate the new features that are in the skeleton into your version of project
and be sure that it builds and runs just as the skeleton did. Then confirm that test cases
testtxt testtxt that were provided as test cases for the skeleton code produce the
correct output. Note that changes are required to both parser.y and scanner.l You are likely
to get type clash warnings from bison initially. These will be resolved once the entire project is
completed.
Make additions as defined by the specification incrementally. Start with adding the code to
evaluate real literals and the hexadecimal integer literals. These changes involve modifications to
scanner.l There is a predefined C function atof that will convert a string containing a real
literal to a double. But you will need to write a function that converts a string containing a
hexadecimal integer to an int. Once you have made these modifications use testtxt test
them. Shown below is the output that should result when using that test case as input:
$ compile testtxt
Function with Arithmetic Expression using Real Literals
and Hexadecimal Integer Literals
function main returns real;
begin
eEE #aF;
end;
Compiled Successfully
Result
Next, add the code to scanner.l to evaluate character literals that includes both ordinary
character literals and the escape characters. As with the hexadecimal integer literals, you will
need to write a function to perform this conversion. Once you have made this modification use
testtxt test it Shown below is the output that should result when using that test case as
input:
Function with Character Literal Escape Characters
function main returns character;
lines: integer is ;
begin
when lines
: f;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started