Semantic Analysis and Symbol Table
Budget: $10 – $30 USD
PAC-MAN language.
a) Declaration Checking: For this part, you need to process the declaration.
• A variable cannot be used if it is not previously declared.
• No two variables can share a name within their declared scope (The scope of a variable is from the point where it is declared until the end). it is legal to have same variable name in different scope
b) Type System: PAC-MAN specification also describes rules for statements and ex- pressions type checking.
• The left and right side of an assignment statement must have the same type.
• Arithmetic operators (+,-,*,/) operate on operands of type integer or double only. The result should be of same type of the two operands, if one operand is integer and the other is double the result should be of type double.
• Relational operator, the two operand must have the same type and the result is boolean (true or false.
• Logic operator (&&,||,!) only operates on boolean expression and the result is boolean (true or false.
• The expression/condition in (if and while) statements must be of type boolean. c) Error Handling
During parsing, if one of the above rules (a declaration or a type rule) is violated, print an error message that explains in details the violation (along with associated line number) and continue processing the input. Your compiler should detect and show all semantic errors that occur before the first syntax error. In case of syntax error, your compiler should show a message with the line number of the first encountered syntax error then exit the system
a) Declaration Checking: For this part, you need to process the declaration.
• A variable cannot be used if it is not previously declared.
• No two variables can share a name within their declared scope (The scope of a variable is from the point where it is declared until the end). it is legal to have same variable name in different scope
b) Type System: PAC-MAN specification also describes rules for statements and ex- pressions type checking.
• The left and right side of an assignment statement must have the same type.
• Arithmetic operators (+,-,*,/) operate on operands of type integer or double only. The result should be of same type of the two operands, if one operand is integer and the other is double the result should be of type double.
• Relational operator, the two operand must have the same type and the result is boolean (true or false.
• Logic operator (&&,||,!) only operates on boolean expression and the result is boolean (true or false.
• The expression/condition in (if and while) statements must be of type boolean. c) Error Handling
During parsing, if one of the above rules (a declaration or a type rule) is violated, print an error message that explains in details the violation (along with associated line number) and continue processing the input. Your compiler should detect and show all semantic errors that occur before the first syntax error. In case of syntax error, your compiler should show a message with the line number of the first encountered syntax error then exit the system