Syntax Analysis – Compiler

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 :

  1. It is Second Phase Of Compiler after Lexical Analyzer
  2. It is also Called as Hierarchical Analysis or Parsing.
  3. It Groups Tokens of source Program into Grammatical Production
  4. 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.
Parse Tree - Syntax Analysis in Compiler Design
[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