Semantic Analysis in Compiler Design Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 28 Likes 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. Create Quiz Comment P palaksinghal9903 Follow 28 Improve P palaksinghal9903 Follow 28 Improve Article Tags : Compiler Design GATE CS Explore Compiler Design BasicsIntroduction of Compiler Design5 min readCompiler Construction Tools2 min readPhases of a Compiler8 min readSymbol Table in Compiler3 min readError Handling in Compiler Design3 min readLanguage Processors: Assembler, Compiler and Interpreter5 min readGenerations of Programming Languages3 min readLexical AnalysisIntroduction of Lexical Analysis3 min readFlex (Fast Lexical Analyzer Generator)5 min readIntroduction of Finite Automata3 min readClassification of Context Free Grammars4 min readAmbiguous Grammar7 min readSyntax Analysis & ParsersIntroduction to Syntax Analysis in Compiler Design5 min readFIRST and FOLLOW in Compiler Design6 min readParsing - Introduction to Parsers6 min readConstruction of LL(1) Parsing Table6 min readSyntax Directed Translation & Intermediate Code GenerationSyntax Directed Translation in Compiler Design7 min readS - Attributed and L - Attributed SDTs in Syntax Directed Translation3 min readParse Tree and Syntax Tree4 min readIntermediate Code Generation in Compiler Design5 min readIssues in the design of a code generator5 min readThree address code in Compiler6 min readData flow analysis in Compiler6 min readCode Optimization & Runtime EnvironmentsCode Optimization in Compiler Design8 min readIntroduction of Object Code in Compiler Design6 min readStatic and Dynamic Scoping4 min readRuntime Environments in Compiler Design9 min readLinker8 min readLoader in C/C++3 min readPractice QuestionsLast Minute Notes - Compiler Design12 min readCompiler Design - GATE CSE Previous Year Questions2 min read Like