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

1 answer below »
CMSC 430 Project 2
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:function_header{variable} bodyfunction_header: FUNCTION IDENTIFIER [parameters] RETURNS type ; variable: IDENTIFIER : type IS statement parameters: parameter {, parameter} parameter: IDENTIFIER : type type: INTEGER | REAL | BOOLEAN body: BEGIN statement END ; statement: expression ; | REDUCE operator {statement} ENDREDUCE ; | IF expression THEN statement ELSE statement ENDIF ; | CASE expression IS {case} OTHERS ARROW statement ENDCASE ; operator: ADDOP | MULOP case: WHEN INT_LITERAL ARROW statement expression: ( expression ) | expression binary_operator expression | NOTOP expression | INT_LITERAL | REAL_LITERAL | BOOL_LITERAL | IDENTIFIER binary_operator: ADDOP | MULOP | REMOP | EXPOP | RELOP | ANDOP | OROPIn the above grammar, the red symbols are nonterminals, the blue symbols are terminals and the black punctuation are EBNF metasymbols. The braces denote repetition 0 or more times and the brackets denote optional.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 usedYour 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 shift/reduce or reduce/reduce 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.
Answered 7 days AfterJul 17, 2022

Answer To: CMSC 430 Project 2 The second project involves modifying the syntactic analyzer for the attached...

Aditi answered on Jul 17 2022
71 Votes
Syntactical Analyzer Generator
Approach
When I am given skeleton code, the first thing I do, just like I did with the last project, is mak
e sure I understand everything about the code I have been given. That way, I may alter it easily as though it were my personal code.   Dr. Duane J. Jarc provided a thorough explanation of the code's syntax and purpose. I was able to comprehend not just how the code connects to the readings for the course, and how this project is directly related to the lexical analyzer.
First, I had to swap out part of the lexical analyzer's skeleton work with my own, and then I had to rewrite scanner.l because it wouldn't conflict with parser.y. For instance, the main function is already present in the new skeleton code's parser.y, so I removed it from scanner.l to avoid an issue caused by having two main methods.
Changing the grammar productions was the next major step after expanding the token definitions in parser.y. The first thing I made care to include were checks for syntax errors, which I learned were only required in the root-level productions. Including incorrect productions with the non terminals function header, variable, and statement was all that I required to cover all probable production mistakes.
Another item that needed a lot of thought and preparation was keeping correct priority among the operators. Bison's file syntax first baffled me, but...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here