ASA CMSC 430 Modifying the Attached Interpreter Project The third project involves modifying the attached interpreter so that it interprets programs for the complete language.
You may convert all values to double values, although you can maintain their individual types if you wish. 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 a: integer, b: integer returns integer;
Don't use plagiarized sources. Get Your Custom Essay on
ASA CMSC 430 Modifying the Attached Interpreter Project The third project involves modifying the attached interpreter so that it interprets programs for th
For $10/Page 0nly
One would execute the program as follows: $ ./compile < test.txt 2 4
In this case, the parameter a would be initialized to 2 and the parameter b to 4. An example of a program execution is shown below:
$ ./compile < test.txt 2 4
1 function main a: integer, b: integer returns integer;
2 c: integer is
3 if a > b then
4 a rem b;
5 else
6 a ** 2;
7 endif;
8 begin
9 case a is
10 when 1 => c;
11 when 2 => (a + b / 2 – 4) * 3;
12 others => 4;
13 endcase;
14 end;
Compiled Successfully
Result = 0
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 reduction statement. You are to add the necessary code to include all of the following:
All additional arithmetic operators
All additional relational and logical operators
Both if and case statements
Functions with multiple variables
Functions with parameters
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.
Skeleton Files:
listing.cc
// Compiler Theory and Design
// Dr. Duane J. Jarc
// This file contains the bodies of the functions that produces the compilation
// listing
#include
#include
using namespace std;
#include “listing.h”
static int lineNumber;
static string error = “”;
static int totalErrors = 0;
static void displayErrors();
void firstLine()
{
lineNumber = 1;
printf(“n%4d “,lineNumber);
}
void nextLine()
{
displayErrors();
lineNumber++;
printf(“%4d “,lineNumber);
}
int lastLine()
{
printf(“r”);
displayErrors();
printf(” n”);
return totalErrors;
}
void appendError(ErrorCategories errorCategory, string message)
{
string messages[] = { “Lexical Error, Invalid Character “, “”,
“Semantic Error, “, “Semantic Error, Duplicate Identifier: “,
“Semantic Error, Undeclared ” };
error = messages[errorCategory] + message;
totalErrors++;
}
void displayErrors()
{
if (error != “”)
printf(“%sn”, error.c_str());
error = “”;
}
listing.h
// Compiler Theory and Design
// Duane J. Jarc
// This file contains the function prototypes for the functions that produce the // compilation listing
enum ErrorCategories {LEXICAL, SYNTAX, GENERAL_SEMANTIC, DUPLICATE_IDENTIFIER,
UNDECLARED};
void firstLine();
void nextLine();
int lastLine();
void appendError(ErrorCategories errorCategory, string message);
parser.y
/* Compiler Theory and Design
Duane J. Jarc */
%{
#include
#include
#include
#include