Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The second project involves writing the syntactic analyzer for the compiler that was begun in the previous project. The grammar of the language is the

The second project involves writing the syntactic analyzer for the compiler that was begun in the previous project. The grammar of the language is the following: program: {function} function: FUNCTION IDENTIFIER [parameters] RETURNS type ; body parameters: parameter {, parameter} parameter: IDENTIFIER : type type: INTEGER | REAL | BOOLEAN body: {variable} BEGIN statement END ; variable: IDENTIFIER : type IS statement statement: expression ; | IF expression THEN statement ELSE statement ENDIF ; CASE expression IS {case} OTHERS ARROW expression ; ENDCASE ; case: WHEN INT_LITERAL ARROW expression ; expression: IDENTIFIER | IDENTIFIER (expression {, expression}) | INT_LITERAL | REAL_LITERAL | BOOLEAN_LITERAL | NOT expression | expression operator expression | (expression) operator: ADDOP | MULOP | EXPOP | RELOP | AND | OR 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 0 or more times and the brackets denote optional. The grammar must be rewritten 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 The syntactic analyzer should be created using bison. It should detect and recover from syntax errors to the extent possible. The semicolon should be used as the primary synchronization token. The compiler should produce a listing of the program with error messages included after the line in which they occur. A count of the number of lexical and syntactic errors and the number of total errors should follow the compilation listing. Your parser should, however, be able to correctly parse any syntactically correct program without any problem. The compiler should produce a listing of the program with both lexical and syntactic error messages included after the line in which they occur. An example of compilation listing output containing syntax errors is shown below: 1 -- Multiple errors 2 3 function main a integer returns real; Syntax Error, Unexpected INTEGER, expecting ':' 4 b: integer is * 2; Syntax Error, Unexpected MULOP 5 c: real is 6.0; 6 begin 7 if a > c then 8 b 3.0; Syntax Error, Unexpected REAL_LITERAL, expecting ';' 9 else 10 b = 4.; 11 endif; 12 ; Syntax Error, Unexpected ';', expecting END Lexical Errors 0 Syntax Errors 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions