Syntax Analysis – CompilerPritesh
Analysis Phase : 2nd Phase of Compiler (Syntax Analysis)
During the first Scanning phase i.e Lexical Analysis Phase of the compiler , symbol table is created by the compiler which contain the list of leximes or tokens.
Syntax Analysis :
- It is Second Phase Of Compiler after Lexical Analyzer
- It is also Called as Hierarchical Analysis or Parsing.
- It Groups Tokens of source Program into Grammatical Production
- In Short Syntax Analysis Generates Parse Tree
Parse Tree Generation :
sum = num1 + num2
Now Consider above C Programming statement. In this statement we Syntax Analyzer will create a parse tree from the tokens.
[box]Syntax Analyzer will check only Syntax not the meaning of Statement[/box]
Explanation : Syntax Analysis
- We know , Addition operator plus (‘+’) operates on two Operands
- Syntax analyzer will just check whether plus operator has two operands or not . It does not checks the type of operands.
- Suppose One of the Operand is String and other is Integer then it does not throw error as it only checks whether there are two operands associated with ‘+’ or not .
- So this Phase is also called Hierarchical Analysis as it generates Parse Tree Representation of the Tokens generated by Lexical Analyzer