Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

CMSC 430 Project 3 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...

1 answer below »
CMSC 430 Project 3
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;
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;
XXXXXXXXXXc: integer is
XXXXXXXXXXif a > b then
XXXXXXXXXXa rem b;
XXXXXXXXXXelse
XXXXXXXXXXa ** 2;
XXXXXXXXXXendif;
8 begin
XXXXXXXXXXcase a is
XXXXXXXXXXwhen 1 => c;
XXXXXXXXXXwhen 2 => (a + b / 2 - 4) * 3;
XXXXXXXXXXothers => 4;
XXXXXXXXXXendcase;
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
li
ary of evaluation functions already provided in values.cc. You must also make some
modifications to the functions already provided.
You are to submit two files.
1. The first is a .zip file that contains all the source code for the project. The .zip file
should contain the flex input file, which should be a .l file, the bison file, which should
e a .y file, all .cc and .h files and a makefile that builds the project.
2. The second is a Word document (PDF or RTF is also acceptable) that contains the
documentation for the project, which should include the following:
a. A discussion of how you approached the project
. A test plan that includes test cases that you have created indicating what aspects
of the program each one is testing and a screen shot of your compiler run on that
test case
c. A discussion of lessons learned from the project and any improvements that could
e made
Grading Ru
ic
Criteria Meets Does Not Meet
Functionality
70 points 0 points
Subtraction operator evaluated
co
ectly (5)
Subtraction operator not evaluated
co
ectly (0)
Division operator evaluated co
ectly
(5)
Division operator not evaluated
co
ectly (0)
Remainder operator evaluated
co
ectly (5)
Remainder operator not evaluated
co
ectly (0)
Exponentiation operator evaluated
co
ectly (5)
Exponentiation operator not evaluated
co
ectly (0)
Additional relational operators
evaluated co
ectly (5)
Additional relational operators not
evaluated co
ectly (0)
Additional logical operators evaluated
co
ectly (5)
Additional logical operators not
evaluated co
ectly (0)
if conditional expressions evaluated
co
ectly (10)
if conditional expressions not
evaluated co
ectly (0)
case conditional expressions evaluated
co
ectly (10)
case conditional expressions not
evaluated co
ectly (0)
Functions with multiple variables
evaluated co
ectly (10)
Functions with multiple variables not
evaluated co
ectly (0)
Functions with parameters evaluated
co
ectly (10)
Functions with parameters not
evaluated co
ectly (0)
Test Cases
15 points 0 points
Includes test cases that test all
arithmetic operators (3)
Does not include test cases that test all
arithmetic operators (0)
Includes test cases that test all
elational operators (3)
Does not include test cases that test all
elational operators (0)
Includes test cases that test all logical
operators (3)
Does not include test cases that test all
logical operators (0)
Includes test cases that test both
conditional expressions (3)
Does not include test cases that test
oth conditional expressions (0)
Includes test cases with variables and
parameters (3)
Does not include test cases with
variables and parameters (0)
Documentation
15 points 0 points
Discussion of approach included (5) Discussion of approach not included (0)
Lessons learned included (5) Lessons learned not included (0)
Comment blocks with student name,
project, date and code description
included in each file (5)
Comment blocks with student name,
project, date and code description not
included in each file (0)
Answered Same Day Apr 23, 2021

Solution

Pritam answered on Apr 26 2021
157 Votes
execution_screenshot.png
listing.cc
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 e
or = "";
static int totalE
ors = 0;
static void displayE
ors();
void firstLine()
{
    lineNumber = 1;
    printf("\n%4d  ",lineNumber);
}
void nextLine()
{
    displayE
ors();
    lineNumber++;
    printf("%4d  ",lineNumber);
}
int lastLine()
{
    printf("\r");
    displayE
ors();
    printf("     \n");
    return totalE
ors;
}
    
void appendE
or(E
orCategories e
orCategory, string message)
{
    string messages[] = { "Lexical E
or, Invalid Character ", "",
        "Semantic E
or, ", "Semantic E
or, Duplicate Identifier: ",
        "Semantic E
or, Undeclared " };
    e
or = messages[e
orCategory] + message;
    totalE
ors++;
}
void displayE
ors()
{
    if (e
or != "")
        printf("%s\n", e
or.c_str());
    e
or = "";
}
listing.h
Compiler Theory and Design
Duane J. Jarc
This file contains the function prototypes for the functions that produce the
compilation listing
enum E
orCategories {LEXICAL, SYNTAX, GENERAL_SEMANTIC, DUPLICATE_IDENTIFIER,
    UNDECLARED};
void firstLine();
void nextLine();
int lastLine();
void appendE
or(E
orCategories e
orCategory, string message);
makefile
compile: scanner.o parser.o listing.o values.o
    g++ -o compile scanner.o parser.o listing.o values.o
    
scanner.o: scanner.c values.h listing.h tokens.h
    g++ -c scanner.c
scanner.c: scanner.l    
    flex scanner.l
    mv lex.yy.c scanner.c
parser.o: parser.c values.h listing.h symbols.h
    g++ -c parser.c
parser.c tokens.h: parser.y
    bison -d -v parser.y
    mv parser.tab.c parser.c
    mv parser.tab.h tokens.h
listing.o: listing.cc listing.h
    g++ -c listing.cc
values.o: values.cc values.h
    g++ -c values.cc
parser.y
* Compiler Theory and Design
Duane J. Jarc *
%{
#include #include #include #include using namespace std;
#include "values.h"
#include "listing.h"
#include "symbols.h"
int yylex();
void yye
or(const char* message);
Symbols symbols;
int result;
%}
%e
or-ve
ose
%union
{
    CharPtr iden;
    Operators oper;
    int value;
}
%token IDENTIFIER
%token INT_LITERAL
%token ADDOP MULOP RELOP
%token ANDOP
%token BEGIN_ BOOLEAN END ENDREDUCE FUNCTION INTEGER IS REDUCE RETURNS
%type body statement_ statement reductions expression relation term
    factor primary
%type operato
%%
function:    
    function_header optional_variable body {result = $3;} ;
    
function_header:    
    FUNCTION IDENTIFIER RETURNS type ';' ;
optional_variable:
    variable |
    ;
variable:    
    IDENTIFIER ':' type IS statement_ {symbols.insert($1, $5);} ;
type:
    INTEGER |
    BOOLEAN...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here