Question: I d like to view: The second project involves modifying the syntactic analyzer for the attached compiler by adding to the existing grammar. The full
Id like to view:
The second project involves modifying the syntactic analyzer for the attached compiler by adding to the existing grammar. The full grammar of the language is shown below. The highlighted portions of the grammar show what you must either modify or add to the existing grammar.
function:
functionheader variable body
functionheader:
FUNCTION IDENTIFIER parameters RETURNS type ;
variable:
IDENTIFIER : type IS statement
:
type:
INTEGER REAL BOOLEAN
body:
BEGIN statement END ;
statement:
expression ;
REDUCE operator statement ENDREDUCE ;
operator:
ADDOP MULOP
case:
WHEN INTLITERAL ARROW statement
expression:
expression
expression binaryoperator expression
parameters
parameter parameter
parameter:
IDENTIFIER : type
IF expression THEN statement ELSE statement ENDIF ;
CASE expression IS case OTHERS ARROW statement ENDCASE ;
NOTOP expression
BOOLLITERAL
binaryoperator: ADDOP MULOP REMOP EXPOP RELOP ANDOP OROP
In the above grammar, the red symbols are nonterminals, the blue symbols are terminals and the black punctuation are EBNF metasymbols. The braces denote repetition or more times and the brackets denote optional.
INTLITERAL
IDENTIFIER
REALLITERAL
You must rewrite the grammar to eliminate the EBNF brace and bracket metasymbols and to incorporate the significance of parentheses, operator precedence and associativity for all operators. Among arithmetic operators the exponentiation operator has highest precedence following by the multiplying operators and then the adding operators. All relational operators have the same precedence. Among the binary logical operators, and has higher precedence than or Of the categories of operators, the unary logical operator has highest precedence, the arithmetic operators have next highest precedence, followed by the relational operators and finally the binary logical operators. All operators except the exponentiation operator are left associative. The directives to specify precedence and associativity, such as prec and left, may not be used
Your parser should be able to correctly parse any syntactically correct program without any problem.
You must modify the syntactic analyzer to detect and recover from additional syntax errors using the semicolon as the synchronization token. To accomplish detecting additional errors an error production must be added to the function header, another to the variable declaration and a final one to the when clause of the case statement.
Your bison input file should not produce any shiftreduce or reducereduce errors. Eliminating them can be difficult so the best strategy is not introduce any. That is best achieved by making small incremental additions to the grammar and ensuring that no addition introduces any such errors.
An example of compilation listing output containing syntax errors is shown below:
Multiple errors
function main a integer returns real;
Syntax Error, Unexpected INTEGER, expecting : b: integer is ;
Syntax Error, Unexpected MULOP
c: real is ;
begin
if a c then
b ;
Syntax Error, Unexpected REALLITERAL, expecting ;
Lexical Errors
Syntax Errors
Semantic Errors
You are to submit two files.
else
b ;
endif;
Syntax Error, Unexpected ; expecting END
;
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 be a y file, all cc and h files and a makefile that builds the project.
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 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
A discussion of lessons learned from the project and any improvements that could
be made
Provided Skeleton Code:
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 ;
static void displayErrors;
void firstLine
lineNumber ;
printf
d lineNumber;
void nextLine
displayErrors;
lineNumber;
printfd lineNumber;
int lastLine
printfr;
displayErrors;
printf
;
return totalErrors;
void appendErrorErrorCategories errorCategory, string message
string messages "Lexical Error, Invalid Character
"Semantic Error, "Semantic Error, Duplicate Identifier:
"Semantic Error, Undeclared ;
error messages
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
