Semantic Analysis - Compiler
Syntax analyzer will just create parse tree. Semantic Analyzer will check actual meaning of the statement parsed in parse tree. Semantic analysis can compare information in one part of a parse tree to that in another part (e.g., compare reference to variable agrees with its declaration, or that parameters to a function call match the function definition).
Semantic Analysis is used for the following -
- Maintaining the Symbol Table for each block.
- Check Source Program for Semantic Errors.
- Collect Type Information for Code Generation.
- Reporting compile-time errors in the code (except syntactic errors, which are caught by syntactic analysis)
- Generating the object code (e.g., assembler or intermediate code)
Now In the Semantic Analysis Compiler Will Check -
- Data Type of First Operand
- Data Type of Second Operand
- Check Whether + is Binary or Unary.
- Check for Number of Operands Supplied to Operator Depending on Type of Operator (Unary | Binary | Ternary)