SlideShare a Scribd company logo
Compiler Construction
By Noor wali Khan
UOCH
Syntax Analyzer
• Syntax analysis is a second phase of the compiler design
process that comes after lexical analysis.
• It analyses the syntactical structure of the given input.
• The syntax analyzer also checks whether a given program
fulfills the rules implied by a context-free grammar.
• We have seen that a lexical analyzer can identify tokens
with the help of regular expressions and pattern rules.
Syntax Analyzer
• But a lexical analyzer cannot check the syntax of a given sentence due
to the limitations of the regular expressions.
• Regular expressions cannot check balancing tokens, such as
parenthesis.
• Therefore, this phase uses context-free grammar (CFG), which is
recognized by push-down automata.
• CFG, on the other hand, is a superset of Regular Grammar, as
depicted below:
Regular
Grammar
CFG
• It implies that every Regular Grammar is also context-free, but there
exists some problems, which are beyond the scope of Regular
Grammar.
• CFG is a helpful tool in describing the syntax of programming
languages.
Syntax Analyzer
•A syntax analyzer or parser takes the input from
a lexical analyzer in the form of token streams.
•The parser analyzes the source code (token
stream) against the production rules to detect
any errors in the code. The output of this phase
is a parse tree.
Syntax Analyzer
Parse Tree
• It is a generalized type of tree which shows pictorially
that how grammar rules are applied on the sequence
of character.
• Parse tree is the output of the syntax analyzer and is
used for designing/defining syntax structure.
• The parse tree describes the syntactic structure of the
input.
Syntax Tree
• Compressed form of parse tree which contains operators as internal
node and operands of the operator to be the children of its internal
node.
=
Id +
Id
*
Id
num
Compiler lecture 06

More Related Content

PPTX
Monolithic and Procedural Programming
PPT
What To Expect With C
PPTX
Programming in python - Week 2
PDF
Keywords in python
PPTX
Introduction to formal methods
DOCX
Chapter 9 & chapter 10 solutions
PPTX
Type checking in compiler design
Monolithic and Procedural Programming
What To Expect With C
Programming in python - Week 2
Keywords in python
Introduction to formal methods
Chapter 9 & chapter 10 solutions
Type checking in compiler design

What's hot (7)

PPTX
PDF
Functional Programming in Ruby
PPTX
9. control statement
PDF
Introduction to Scala Implicits, Pimp my library and Typeclasses
PDF
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
PPTX
White box testing
PPTX
White Box Testing
Functional Programming in Ruby
9. control statement
Introduction to Scala Implicits, Pimp my library and Typeclasses
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
White box testing
White Box Testing
Ad

Similar to Compiler lecture 06 (20)

PPT
Compier Design_Unit I_SRM.ppt
PPT
Compier Design_Unit I.ppt
PPT
Compier Design_Unit I.ppt
PPTX
Principles of Compiler Design - Introduction
PDF
An Introduction to the Compiler Designss
PPTX
Compiler lecture 04
PPTX
Compiler lecture 04
PPTX
1 compiler outline
PPTX
introduction to semantic analysis .pptx
PPTX
Compiler_Presentation important one. .pptx
PPTX
module 2 introduction to syntax analysis
PPTX
1._Introduction_.pptx
PPTX
Compiler Design Introduction With Design
PPTX
COMPILER CONSTRUCTION KU 1.pptx
PPTX
System software module 4 presentation file
PPTX
Compiler lecture 07
PPTX
"Lexical Analysis for GATE and CS Exams"
PPT
Compiler Design in Computer Applications
PPTX
The Phases of a Compiler
PDF
compiler.pdfljdvgepitju4io3elkhldhyreyio4uw
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I.ppt
Compier Design_Unit I.ppt
Principles of Compiler Design - Introduction
An Introduction to the Compiler Designss
Compiler lecture 04
Compiler lecture 04
1 compiler outline
introduction to semantic analysis .pptx
Compiler_Presentation important one. .pptx
module 2 introduction to syntax analysis
1._Introduction_.pptx
Compiler Design Introduction With Design
COMPILER CONSTRUCTION KU 1.pptx
System software module 4 presentation file
Compiler lecture 07
"Lexical Analysis for GATE and CS Exams"
Compiler Design in Computer Applications
The Phases of a Compiler
compiler.pdfljdvgepitju4io3elkhldhyreyio4uw
Ad

More from University of Chitral (12)

PPTX
Compiler lecture 05
PPTX
Oop lecture 06
PPTX
Oop lecture 05
PPTX
OOP lecture 04
PPTX
Compiler lecture 05
PPTX
Compiler lecture 03
PPTX
Compiler lecture 01
PPTX
Compiler lecture 02
PPTX
O op lecture 04
PPTX
Oop lecture 03
PPTX
Oop lecture 02
PPTX
Oop lecture 01
Compiler lecture 05
Oop lecture 06
Oop lecture 05
OOP lecture 04
Compiler lecture 05
Compiler lecture 03
Compiler lecture 01
Compiler lecture 02
O op lecture 04
Oop lecture 03
Oop lecture 02
Oop lecture 01

Recently uploaded (20)

PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Computing-Curriculum for Schools in Ghana
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Lesson notes of climatology university.
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Sports Quiz easy sports quiz sports quiz
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
01-Introduction-to-Information-Management.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Complications of Minimal Access Surgery at WLH
human mycosis Human fungal infections are called human mycosis..pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Computing-Curriculum for Schools in Ghana
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pharma ospi slides which help in ospi learning
STATICS OF THE RIGID BODIES Hibbelers.pdf
Lesson notes of climatology university.
Insiders guide to clinical Medicine.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Sports Quiz easy sports quiz sports quiz
TR - Agricultural Crops Production NC III.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025

Compiler lecture 06

  • 2. Syntax Analyzer • Syntax analysis is a second phase of the compiler design process that comes after lexical analysis. • It analyses the syntactical structure of the given input. • The syntax analyzer also checks whether a given program fulfills the rules implied by a context-free grammar. • We have seen that a lexical analyzer can identify tokens with the help of regular expressions and pattern rules.
  • 3. Syntax Analyzer • But a lexical analyzer cannot check the syntax of a given sentence due to the limitations of the regular expressions. • Regular expressions cannot check balancing tokens, such as parenthesis. • Therefore, this phase uses context-free grammar (CFG), which is recognized by push-down automata. • CFG, on the other hand, is a superset of Regular Grammar, as depicted below: Regular Grammar CFG
  • 4. • It implies that every Regular Grammar is also context-free, but there exists some problems, which are beyond the scope of Regular Grammar. • CFG is a helpful tool in describing the syntax of programming languages.
  • 5. Syntax Analyzer •A syntax analyzer or parser takes the input from a lexical analyzer in the form of token streams. •The parser analyzes the source code (token stream) against the production rules to detect any errors in the code. The output of this phase is a parse tree.
  • 7. Parse Tree • It is a generalized type of tree which shows pictorially that how grammar rules are applied on the sequence of character. • Parse tree is the output of the syntax analyzer and is used for designing/defining syntax structure. • The parse tree describes the syntactic structure of the input.
  • 8. Syntax Tree • Compressed form of parse tree which contains operators as internal node and operands of the operator to be the children of its internal node. = Id + Id * Id num