Phases of compiler
A Compiler is a language processor that:
- translates a program from source language to target language,
- reports errors if any,
- generates executable machine code.
Lexical Analyzer
- Lexical analysis is also called linear analysis or scanning
- It processes character from left to right & group the character stream into significant unit called lexemes
- These lexemes are mapped into token
- It also does the additional job of removing extra whitespace, comments added by the user, etc. from the program
Syntax Analyzer
- The syntax analysis phase takes word/tokens from the lexical analyzer and checks the syntactic correctness of the input program
- Syntax analysis identifies and notifies the syntactic errors in the program once the program has been broken into the tokens
- It often referred as hierarchical analysis or simply parsing
- The hierarchical structure of the source program can be represented by a parse tree
Semantic Analyzer
- Once the program is syntactically correct means grammatically correct the next task is to check semantic correctness
- This phase performs the checks on the meaning of the statement and makes the necessary modification in the parse tree representation
- The word semantic refer to meaning & the semantic analyzer checks the meaning of the program
- This phase checks the source program for semantic error and gathers “type information” about the program element