SlideShare a Scribd company logo
1 of 10
Compiler Construction
By Noor Wali Khan
UOCH
Semantic Analyzer
• It is the third phase of compiler.
• This phase of compiler is connected with meanings: its job is to check
whether operations applied the source program are meaningful or
not.
• It is also called type checking.
• It checks the meaningfulness of the statement in the source program.
• It performs type checking i.e. int a; float b; c= a+b;
•Semantic analysis is the task of ensuring
that the declarations and statements of a
program are semantically correct, i.e, that
their meaning is clear and consistent with
the way in which control structures and data
types are supposed to be used.
OR
Semantic Analyzer
• It checks whether the operations applied to the
operands of compatible types, if yes, then the
operations is semantically correct.
• If no it performs any of the following:
• Generate the error messages
• Automatic or implicit type conversion.
Int-to-float
60
Position = initial + rate * 60;
Where Is Semantic Analysis Performed in a
Compiler?
•Semantic analysis is not a separate module
within a compiler.
• It is usually a collection of procedures
called at appropriate times by the parser as
the grammar requires it.
Semantic analysis
• Semantic analysis judges whether the syntax structure constructed in
the source program derives any meaning or not.
For example:
int a = “value”;
• should not issue an error in lexical and syntax analysis phase, as it is
lexically and structurally correct, but it should generate a semantic
error as the type of the assignment differs.
• These rules are set by the grammar of the language and evaluated in
semantic analysis.
Semantic analysis
•The following tasks should be performed in
semantic analysis:
•Scope resolution
•Type checking
•Array-bound checking
What Does Semantic Analysis Produce?
• Part of semantic analysis is producing some sort of
representation of the program, either object code or an
intermediate representation of the program.
• One-pass compilers will generate object code without using
an intermediate representation; code generation is part of
the semantic actions performed during parsing.
• Other compilers will produce an intermediate representation
during semantic analysis.
Semantic Errors
• We have mentioned some of the semantics errors that
the semantic analyzer is expected to recognize:
• Type mismatch
• Undeclared variable
• Reserved identifier misuse.
• Multiple declaration of variable in a scope.
• Accessing an out of scope variable.
• Actual and formal parameter mismatch

More Related Content

What's hot

Scope - Static and Dynamic
Scope - Static and DynamicScope - Static and Dynamic
Scope - Static and DynamicSneh Pahilwani
 
Unit testing
Unit testingUnit testing
Unit testingmedsherb
 
Semantic scaffolds for pseudocode to-code generation (2020)
Semantic scaffolds for pseudocode to-code generation (2020)Semantic scaffolds for pseudocode to-code generation (2020)
Semantic scaffolds for pseudocode to-code generation (2020)Minhazul Arefin
 
Testing Philosphies
Testing PhilosphiesTesting Philosphies
Testing PhilosphiesRob Kaufman
 
Control Flow Testing
Control Flow TestingControl Flow Testing
Control Flow TestingHirra Sultan
 
TMPA-2015: Towards a Usable Defect Prediction Tool: Crossbreeding Machine Lea...
TMPA-2015: Towards a Usable Defect Prediction Tool: Crossbreeding Machine Lea...TMPA-2015: Towards a Usable Defect Prediction Tool: Crossbreeding Machine Lea...
TMPA-2015: Towards a Usable Defect Prediction Tool: Crossbreeding Machine Lea...Iosif Itkin
 
Function points analysis
Function points analysisFunction points analysis
Function points analysisYunis Lone
 
Fundamentals of Software Engineering
Fundamentals of Software Engineering Fundamentals of Software Engineering
Fundamentals of Software Engineering Madhar Khan Pathan
 
Unit 3 Control Flow Testing
Unit 3   Control Flow TestingUnit 3   Control Flow Testing
Unit 3 Control Flow Testingravikhimani
 
Fundamentals of Software Engineering
Fundamentals of Software Engineering Fundamentals of Software Engineering
Fundamentals of Software Engineering Madhar Khan Pathan
 
States, state graphs and transition testing
States, state graphs and transition testingStates, state graphs and transition testing
States, state graphs and transition testinggeethawilliam
 
20100522 software verification_sharygina_lecture02
20100522 software verification_sharygina_lecture0220100522 software verification_sharygina_lecture02
20100522 software verification_sharygina_lecture02Computer Science Club
 

What's hot (20)

Scope - Static and Dynamic
Scope - Static and DynamicScope - Static and Dynamic
Scope - Static and Dynamic
 
Unit testing
Unit testingUnit testing
Unit testing
 
Semantic scaffolds for pseudocode to-code generation (2020)
Semantic scaffolds for pseudocode to-code generation (2020)Semantic scaffolds for pseudocode to-code generation (2020)
Semantic scaffolds for pseudocode to-code generation (2020)
 
Testing Philosphies
Testing PhilosphiesTesting Philosphies
Testing Philosphies
 
Control Flow Testing
Control Flow TestingControl Flow Testing
Control Flow Testing
 
TMPA-2015: Towards a Usable Defect Prediction Tool: Crossbreeding Machine Lea...
TMPA-2015: Towards a Usable Defect Prediction Tool: Crossbreeding Machine Lea...TMPA-2015: Towards a Usable Defect Prediction Tool: Crossbreeding Machine Lea...
TMPA-2015: Towards a Usable Defect Prediction Tool: Crossbreeding Machine Lea...
 
Sta unit 2(abimanyu)
Sta unit 2(abimanyu)Sta unit 2(abimanyu)
Sta unit 2(abimanyu)
 
St 1.6
St 1.6St 1.6
St 1.6
 
Function points analysis
Function points analysisFunction points analysis
Function points analysis
 
Fundamentals of Software Engineering
Fundamentals of Software Engineering Fundamentals of Software Engineering
Fundamentals of Software Engineering
 
Unit 3 Control Flow Testing
Unit 3   Control Flow TestingUnit 3   Control Flow Testing
Unit 3 Control Flow Testing
 
Function Point Analysis
Function Point AnalysisFunction Point Analysis
Function Point Analysis
 
Black box and white box testing
Black box and white box testingBlack box and white box testing
Black box and white box testing
 
Introduction to programming languages part 2
Introduction to programming languages   part 2Introduction to programming languages   part 2
Introduction to programming languages part 2
 
Black box testing
Black box testingBlack box testing
Black box testing
 
Fundamentals of Software Engineering
Fundamentals of Software Engineering Fundamentals of Software Engineering
Fundamentals of Software Engineering
 
States, state graphs and transition testing
States, state graphs and transition testingStates, state graphs and transition testing
States, state graphs and transition testing
 
Black Box Testing
Black Box TestingBlack Box Testing
Black Box Testing
 
20100522 software verification_sharygina_lecture02
20100522 software verification_sharygina_lecture0220100522 software verification_sharygina_lecture02
20100522 software verification_sharygina_lecture02
 
Testing
TestingTesting
Testing
 

Similar to Compiler Construction Semantic Analyzer

Principles of Compiler Design - Introduction
Principles of Compiler Design - IntroductionPrinciples of Compiler Design - Introduction
Principles of Compiler Design - Introductionsheelarajasekar205
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler DesignMarimuthu M
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation filejithujithin657
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.pptsivaganesh293
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.pptsivaganesh293
 
Comiler construction Notes
Comiler construction NotesComiler construction Notes
Comiler construction NotesNadeem Khan
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionSarmad Ali
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptApoorv Diwan
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialgadisaAdamu
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement_jenica
 
White box testing
White box testingWhite box testing
White box testingAbdul Basit
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilersvijaya603274
 

Similar to Compiler Construction Semantic Analyzer (20)

Principles of Compiler Design - Introduction
Principles of Compiler Design - IntroductionPrinciples of Compiler Design - Introduction
Principles of Compiler Design - Introduction
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler Design
 
Compiler lecture 04
Compiler lecture 04Compiler lecture 04
Compiler lecture 04
 
Compiler lecture 04
Compiler lecture 04Compiler lecture 04
Compiler lecture 04
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation file
 
1 compiler outline
1 compiler outline1 compiler outline
1 compiler outline
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Phases of Compiler.pdf
Phases of Compiler.pdfPhases of Compiler.pdf
Phases of Compiler.pdf
 
Comiler construction Notes
Comiler construction NotesComiler construction Notes
Comiler construction Notes
 
Compilers
CompilersCompilers
Compilers
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality Tools
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course Material
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement
 
White box testing
White box testingWhite box testing
White box testing
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
Compiler lecture 06
Compiler lecture 06Compiler lecture 06
Compiler lecture 06
 

More from University of Chitral (12)

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

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Compiler Construction Semantic Analyzer

  • 2. Semantic Analyzer • It is the third phase of compiler. • This phase of compiler is connected with meanings: its job is to check whether operations applied the source program are meaningful or not. • It is also called type checking. • It checks the meaningfulness of the statement in the source program. • It performs type checking i.e. int a; float b; c= a+b;
  • 3. •Semantic analysis is the task of ensuring that the declarations and statements of a program are semantically correct, i.e, that their meaning is clear and consistent with the way in which control structures and data types are supposed to be used. OR
  • 4. Semantic Analyzer • It checks whether the operations applied to the operands of compatible types, if yes, then the operations is semantically correct. • If no it performs any of the following: • Generate the error messages • Automatic or implicit type conversion.
  • 6. Where Is Semantic Analysis Performed in a Compiler? •Semantic analysis is not a separate module within a compiler. • It is usually a collection of procedures called at appropriate times by the parser as the grammar requires it.
  • 7. Semantic analysis • Semantic analysis judges whether the syntax structure constructed in the source program derives any meaning or not. For example: int a = “value”; • should not issue an error in lexical and syntax analysis phase, as it is lexically and structurally correct, but it should generate a semantic error as the type of the assignment differs. • These rules are set by the grammar of the language and evaluated in semantic analysis.
  • 8. Semantic analysis •The following tasks should be performed in semantic analysis: •Scope resolution •Type checking •Array-bound checking
  • 9. What Does Semantic Analysis Produce? • Part of semantic analysis is producing some sort of representation of the program, either object code or an intermediate representation of the program. • One-pass compilers will generate object code without using an intermediate representation; code generation is part of the semantic actions performed during parsing. • Other compilers will produce an intermediate representation during semantic analysis.
  • 10. Semantic Errors • We have mentioned some of the semantics errors that the semantic analyzer is expected to recognize: • Type mismatch • Undeclared variable • Reserved identifier misuse. • Multiple declaration of variable in a scope. • Accessing an out of scope variable. • Actual and formal parameter mismatch