Semantic Analysis in Compiler Design Last Updated : 22 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Semantic Analysis is the third phase of Compiler. Semantic Analysis makes sure that declarations and statements of program are semantically correct. It is a collection of procedures which is called by parser as and when required by grammar. Both syntax tree of previous phase and symbol table are used to check the consistency of the given code. Type checking is an important part of semantic analysis where compiler makes sure that each operator has matching operands. Semantic Analyzer: It uses syntax tree and symbol table to check whether the given program is semantically consistent with language definition. It gathers type information and stores it in either syntax tree or symbol table. This type information is subsequently used by compiler during intermediate-code generation. Semantic Errors: Errors recognized by semantic analyzer are as follows: Type mismatch Undeclared variables Reserved identifier misuse Functions of Semantic Analysis: Type Checking - Ensures that data types are used in a way consistent with their definition. Label Checking - A program should contain labels references. Flow Control Check - Keeps a check that control structures are used in a proper manner.(example: no break statement outside a loop) Example: float x = 10.1; float y = x*30; In the above example integer 30 will be typecasted to float 30.0 before multiplication, by semantic analyzer. Static and Dynamic Semantics: Static Semantics - It is named so because of the fact that these are checked at compile time. The static semantics and meaning of program during execution, are indirectly related. Dynamic Semantic Analysis - It defines the meaning of different units of program like expressions and statements. These are checked at runtime unlike static semantics. Comment More infoAdvertise with us Next Article Liveliness Analysis in Compiler Design P palaksinghal9903 Follow Improve Article Tags : Compiler Design GATE CS Similar Reads Liveliness Analysis in Compiler Design Liveliness Analysis consists of a specified technique that is implemented to optimize register space allocation, for a given piece of code and facilitate the procedure for dead-code elimination. As any machine has a limited number of registers to hold a variable or data which is being used or manipu 9 min read Introduction to Syntax Analysis in Compiler Design Syntax Analysis (also known as parsing) is the step after Lexical Analysis. The Lexical analysis breaks source code into tokens.Tokens are inputs for Syntax Analysis.The goal of Syntax Analysis is to interpret the meaning of these tokens. It checks whether the tokens produced by the lexical analyzer 7 min read What is LEX in Compiler Design? Whenever a developer wants to make any software application they write the code in a high-level language. That code is not understood by the machine so it is converted into low-level machine-understandable code by the compiler. Lex is an important part of this compiler and is responsible for the cla 3 min read Synthesis Phase in Compiler Design Pre-requisites: Phases of a Compiler The synthesis phase, also known as the code generation or code optimization phase, is the final step of a compiler. It takes the intermediate code generated by the front end of the compiler and converts it into machine code or assembly code, which can be executed 4 min read What is USE, IN, and OUT in Compiler Design? Compiler design plays a crucial role in translating high-level programming languages into machine-readable code. During the compilation process, various terminologies are utilized to facilitate the conversion. This article aims to provide an overview of three essential concepts in compiler design: U 3 min read Parse Tree in Compiler Design In compiler design, the Parse Tree depicts the syntactic structure of a string in accordance with a given grammar. It was created during the parsing phase of compilation, wherein syntax of the input source code is analyzed. A parse tree is a useful way of showing how a string or program would be der 4 min read Like