CMSC 430 Project 2The second project involves modifying the syntactic analyzer for the attached compiler byadding to the existing grammar. The full grammar of the…

CMSC 430 Project 2The second project involves modifying the syntactic analyzer for the attached compiler byadding to the existing grammar. The full grammar of the language is shown below. Thehighlighted portions of the grammar show what you must either modify or add to the existinggrammar.function:function_header variable bodyfunction_header:FUNCTION IDENTIFIER [parameters] RETURNS type ;variable:IDENTIFIER : type IS statementparameters:parameter , parameterparameter:IDENTIFIER : typetype:INTEGER | REAL | BOOLEANbody:BEGIN statement END ;statement:

expression ; |REDUCE operator statement ENDREDUCE ; |IF expression THEN statement ELSE statement ENDIF ; |CASE expression IS case OTHERS ARROW statement ; ENDCASE ;

CookMyProjectoperator:ADDOP | MULOPcase:WHEN INT_LITERAL ARROW statementexpression:( expression ) |

expression binary_operator expression |NOT expression |INT_LITERAL IDENTIFIER| REAL_LITERAL | BOOL_LITERAL |

binary_operator: ADDOP | MULOP | REMOP | EXPOP | RELOP | ANDOP | OROPIn the above grammar, the red symbols are nonterminals, the blue symbols are terminals and theblack punctuation are EBNF metasymbols. The braces denote repetition 0 or more times and thebrackets denote optional.You must rewrite the grammar to eliminate the EBNF brace and bracket metasymbols and toincorporate the significance of parentheses, operator precedence and associativity for alloperators. Among arithmetic operators the exponentiation operator has highest precedencefollowing by the multiplying operators and then the adding operators. All relational operatorshave the same precedence. Among the binary logical operators, and has higher precedence thanor. Of the categories of operators, the unary logical operator has highest precedence, thearithmetic operators have next highest precedence, followed by the relational operators andfinally the binary logical operators. All operators except the exponentiation operator are leftassociative. The directives to specify precedence and associativity, such as %prec and %left,may not be usedYour parser should be able to correctly parse any syntactically correct program without anyproblem.You must modify the syntactic analyzer to detect and recover from additional syntax errors usingthe semicolon as the synchronization token. To accomplish detecting additional errors an errorproduction must be added to the function header and another to the variable declaration.Your bison input file should not produce any shift/reduce or reduce/reduce errors. Eliminatingthem can be difficult so the best strategy is not introduce any. That is best achieved by makingsmall incremental additions to the grammar and ensuring that no addition introduces any sucherrors.An example of compilation listing output containing syntax errors is shown below:

1 — Multiple errors2

3 function main a integer returns real;Syntax Error, Unexpected INTEGER, expecting ‘:’4 b: integer is * 2;Syntax Error, Unexpected MULOP5 c: real is 6.0;6 begin7 if a > c then8 b 3.0;Syntax Error, Unexpected REAL_LITERAL, expecting ‘;’9 else10 b = 4.;11 endif;12 ;Syntax Error, Unexpected ‘;’, expecting ENDLexical Errors 0Syntax Errors 4Semantic Errors 0You are to submit two files. The first is a .zip file that contains all the source code for the project. The .zip fileshould contain the flex input file, which should be a .l file, the bison file, which shouldbe 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 thedocumentation for the project, which should include the following:a. A discussion of how you approached the projectb. A test plan that includes test cases that you have created indicating what aspectsof the program each one is testing and a screen shot of your compiler run on thattest casec. A discussion of lessons learned from the project and any improvements that couldbe madeGrading Rubric

Criteria Meets Does Not MeetFunctionality70 points 0 pointsParses all syntactically correctprograms (25)Does not parse all syntactically correctprograms (0)Productions correctly implementprecedence and associativity (10)Productions do not correctlyimplement precedence andassociativity (0)Grammar contains no shift/reduce orreduce/reduce errors (5)Grammar contains shift/reduce orreduce/reduce errors (0)Detects and recovers from all programswith single syntax errors (20)Does not detect and recover fromerrors in the function header (0)Detects and recovers from a programwith multiple syntax errors (10)Does not detect and recover frommultiple errors (0)Test Cases15 points 0 pointsIncludes test cases that test allgrammar productions (6)Does not include test cases that test allgrammar productions (0)Includes test cases that test errors in allproductions (6)Does not include test cases that testerrors in all productions (0)Includes test case with multiple errors(3)Does not include test case withmultiple errors (0)Documentation15 points 0 pointsDiscussion 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 descriptionincluded in each file (5)Comment blocks with student name,project, date and code description notincluded in each file (0)

Let’s block ads! (Why?)

Do you need any assistance with this question?
Send us your paper details now
We’ll find the best professional writer for you!

 



error: Content is protected !!