SlideShare a Scribd company logo
Semantics
Semantic Analysis
• Semantics of a language provide meaning to its
constructs like tokens and syntax structure.
• Semantic analysis judge whether the syntax structure
constructed in the source program provide any meaning
or not.
• For example -
Int a=“book”; is syntactically correct but
generates a semantic error.
• Solution –
CFG + Semantic Rules = Syntax directed
definition.
Semantic Analysis
• output of syntax analysis which is a parse tree is the input of semantic
analysis which is also a parse tree with some additional attributes
called annotated parse tree.
• Some semantic rules are associated with the production rules in
semantic analysis, like:
• Production Semantic Rule
E->E1+T E.code =E1.code||T.code||'+'
Semantic Analysis
◦In which certain checks are performed to ensure that the
components of a program fit together meaningfully.
◦The semantic analysis phase checks the source
program for semantic errors and gathers type
information for the subsequent code- generation phase.
Ways to associate semantic rules
◦There are two ways to represent the semantic rules associated
with grammar symbols
◦ Syntax-Directed Definitions (SDD)
◦ Syntax-Directed Translation Schemes (SDT)
Syntax-Directed Definitions
◦ A syntax-directed definition (SDD) is a context-free grammar
together with attributes and rules.
◦ Attributes are associated with grammar symbols and rules are
associated with productions.
◦ PRODUCTION SEMANTIC RULE
E → E1 + T E.code = E1.code || T.code || ‘+’
Attribute Grammar
◦ Attribute grammar is a context-free grammar where some additional
information (attributes) are appended to one or more of its non-
terminals in order to provide context-sensitive information.
◦ Attribute grammar is a medium to provide semantics to the context-
free grammar and it can help specify the syntax and semantics of a
programming language.
◦ Example
E → E + T { E.value = E.value + T.value }
synthesized attributes
◦ Synthesized attribute get values from the attribute values of their
child nodes.
◦ Example
S → ABC
◦ If S is taking values from its child nodes (A,B,C), then it is said to be
a synthesized attribute, as the values of ABC are synthesized to S.
Inherited attributes
◦ Inherited attributes can take values from parent and/or siblings
Example
S → ABC
◦ A can get values from S, B and C.
◦ B can take values from S, A, and C.
◦ C can take values from S, A, and B.
SDD for expression grammar with synthesized attributes
Annotated Parse Tree for 3*5+4n
SDD for expression grammar with inherited attributes
Annotated Parse Tree for 3*5
S-attributed SDT
◦ If an SDT uses only synthesized attributes it is called S-attributed
SDT.
◦ These attributes are evaluated using S-attributed SDTs that have their
semantic actions written after the production (right hand side).
Example: S → ABC
◦ S can take values from A, B, and C only.
L-attributed SDT
◦ This form of SDT uses both synthesized and inherited attributes with restriction
of not taking values from right siblings.
◦ In L-attributed SDTs, a non-terminal can get values from its parent, child, and
sibling nodes. As in the following production
Example: S → ABC
◦ S can take values from A, B, and C.
◦ A can take values from S only.
◦ B can take values from S and A.
◦ C can get values from S, A, and B.
No non-terminal can get values from the sibling to its right.
SYNTAX -Directed TRANSLATION (SDT)
Background:
◦ Parser uses a CFG (Context-free-Grammer) to validate the
string and produce output for next phase of the compiler.
Output could be either a parse tree or abstract syntax tree
◦ Now to interleave semantic analysis with syntax analysis phase
of the compiler, we use Syntax Directed Translation.
SYNTAX -Directed TRANSLATION (SDT)
Definition:
Syntax Directed Translation are augmented rules to the grammar that
facilitate semantic analysis.
Grammar + semantic rules = SDT
Example:
E -> E+T | T
T -> T*F | F
F -> Id
Grammar RULES
E -> E+T { E.val = E.val + T.val }
E -> T { E.val = T.val }
T -> T*F { T.val = T.val * F.val }
T -> F { T.val = F.val }
F -> ID { F.val = ID.lexval }
Application of SDT
◦ Executing arithmetic expression
◦ Conversion from infix to postfix
◦ Conversion from infix to prefix
◦ Conversion from binary to decimal
◦ Counting number of reductions
◦ Creating syntax tree
◦ Generating the intermediate code
◦ Type checking
◦ Storing type info into symbol table
Example:
Grammar :
E -> E+T | T.
T -> T*F | F
F -> digit
input string:
3*5+4
Annotated parse tree
Syntax directed translation schemes
◦ The syntax directed translation scheme is used to evaluate the order
of semantic rules.
◦ In translation scheme, the semantic rules are embedded within the
right side of the productions.
◦ The position at which an action is to be executed is shown by
enclosed between braces.
Errors
Program submitted to a compiler often have errors of
various kinds
So, good compiler should be able to detect as many
errors as possible in various ways and also recover from
them.
Even in the presence of errors ,the compiler should scan
the program and try to compile all of it.
CLASSIFICATION OF COMPILE TIME
ERRORS
•lexical errors
•Syntactic errors
•Semantic errors
Type Mismatch
Int a = 10;
String b=“Hello World”;
Double sum=a+b;
Undeclared or multiple declare variable
Int a , b;
int b;
a = 10;
b = 10;
Sum = a+b;
Actual and formal Parameter mismatch
Fun (int a)
{
STATEMENTS;
}
String value = “ Hello World ” ;
Fun (value);
Reserved identifier mismatch
int void = 10 ;
Manage type casting
When a binary arithmetic operator is applied to an integer and
real. In this case, the compiler may need to be converting the
integer to a real. As shown in figure given below
Float position, initial, Rate;
Initial = 10.5 ;
Rate = 10.5 ;
Position = initial + Rate * 60 ;
int a=10 ;
float b=15.5 ;
float c= a+int(b) ;
References
www.tutorialspoint.com
www.geeksforgeeks.org
Any Question?
Ad

More Related Content

What's hot (20)

Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01
Iffat Anjum
 
COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
Vetukurivenkatashiva
 
Parsing
ParsingParsing
Parsing
khush_boo31
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
Akshaya Arunan
 
Semantic analysis
Semantic analysisSemantic analysis
Semantic analysis
Lahore Garrison University
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Akshaya Arunan
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.ppt
NderituGichuki1
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
Mir Majid
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
COMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed TranslationCOMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed Translation
Jyothishmathi Institute of Technology and Science Karimnagar
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
Radhakrishnan Chinnusamy
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
Nlp ambiguity presentation
Nlp ambiguity presentationNlp ambiguity presentation
Nlp ambiguity presentation
Gurram Poorna Prudhvi
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
Prankit Mishra
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
Akhil Kaushik
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
nadarmispapaulraj
 
Code Generation
Code GenerationCode Generation
Code Generation
PrabuPappuR
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR
Zahid Parvez
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
R Islam
 

Similar to Semantics analysis (20)

Module 3 - Semantic Analysis(Compiler Design).pptx
Module 3 - Semantic Analysis(Compiler Design).pptxModule 3 - Semantic Analysis(Compiler Design).pptx
Module 3 - Semantic Analysis(Compiler Design).pptx
muralidharanm2022
 
compiler design course focus of chapter 3 and 4 part
compiler design course focus of chapter 3 and 4 partcompiler design course focus of chapter 3 and 4 part
compiler design course focus of chapter 3 and 4 part
abel185080
 
unit 3 modules intermediate code generation
unit 3 modules intermediate code generationunit 3 modules intermediate code generation
unit 3 modules intermediate code generation
ElakkiaU
 
Chapter _4_Semantic Analysis .pptx
Chapter _4_Semantic Analysis .pptxChapter _4_Semantic Analysis .pptx
Chapter _4_Semantic Analysis .pptx
ArebuMaruf
 
Ch6_Semantic_Analysis_ppt_fgjdkidskjfdd.ppt
Ch6_Semantic_Analysis_ppt_fgjdkidskjfdd.pptCh6_Semantic_Analysis_ppt_fgjdkidskjfdd.ppt
Ch6_Semantic_Analysis_ppt_fgjdkidskjfdd.ppt
FutureTechnologies3
 
Chapter -4.pptx
Chapter -4.pptxChapter -4.pptx
Chapter -4.pptx
woldu2
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Bhavin Darji
 
Parsing
ParsingParsing
Parsing
jayashri kolekar
 
syntax-directed-translation.ppt syntax-directed-translation.ppt
syntax-directed-translation.ppt syntax-directed-translation.pptsyntax-directed-translation.ppt syntax-directed-translation.ppt
syntax-directed-translation.ppt syntax-directed-translation.ppt
dejusertse
 
Unit iv-syntax-directed-translation
Unit iv-syntax-directed-translationUnit iv-syntax-directed-translation
Unit iv-syntax-directed-translation
Ajith kumar M P
 
Compiler Design UNIT III PPT (SDD, SDT).pdf
Compiler Design UNIT III PPT (SDD, SDT).pdfCompiler Design UNIT III PPT (SDD, SDT).pdf
Compiler Design UNIT III PPT (SDD, SDT).pdf
Shiva350357
 
Semantic Analysis.pptx
Semantic Analysis.pptxSemantic Analysis.pptx
Semantic Analysis.pptx
ZarfaMasood
 
atc 3rd module compiler and automata.ppt
atc 3rd module compiler and automata.pptatc 3rd module compiler and automata.ppt
atc 3rd module compiler and automata.ppt
ranjan317165
 
3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf
TANZINTANZINA
 
L attribute in compiler design
L  attribute in compiler designL  attribute in compiler design
L attribute in compiler design
khush_boo31
 
Syntaxdirected
SyntaxdirectedSyntaxdirected
Syntaxdirected
Royalzig Luxury Furniture
 
Syntaxdirected
SyntaxdirectedSyntaxdirected
Syntaxdirected
Royalzig Luxury Furniture
 
Syntaxdirected (1)
Syntaxdirected (1)Syntaxdirected (1)
Syntaxdirected (1)
Royalzig Luxury Furniture
 
Compiler design selective dissemination of information syntax direct translat...
Compiler design selective dissemination of information syntax direct translat...Compiler design selective dissemination of information syntax direct translat...
Compiler design selective dissemination of information syntax direct translat...
ganeshjaggineni1927
 
Introduction to C
Introduction to CIntroduction to C
Introduction to C
Janani Satheshkumar
 
Module 3 - Semantic Analysis(Compiler Design).pptx
Module 3 - Semantic Analysis(Compiler Design).pptxModule 3 - Semantic Analysis(Compiler Design).pptx
Module 3 - Semantic Analysis(Compiler Design).pptx
muralidharanm2022
 
compiler design course focus of chapter 3 and 4 part
compiler design course focus of chapter 3 and 4 partcompiler design course focus of chapter 3 and 4 part
compiler design course focus of chapter 3 and 4 part
abel185080
 
unit 3 modules intermediate code generation
unit 3 modules intermediate code generationunit 3 modules intermediate code generation
unit 3 modules intermediate code generation
ElakkiaU
 
Chapter _4_Semantic Analysis .pptx
Chapter _4_Semantic Analysis .pptxChapter _4_Semantic Analysis .pptx
Chapter _4_Semantic Analysis .pptx
ArebuMaruf
 
Ch6_Semantic_Analysis_ppt_fgjdkidskjfdd.ppt
Ch6_Semantic_Analysis_ppt_fgjdkidskjfdd.pptCh6_Semantic_Analysis_ppt_fgjdkidskjfdd.ppt
Ch6_Semantic_Analysis_ppt_fgjdkidskjfdd.ppt
FutureTechnologies3
 
Chapter -4.pptx
Chapter -4.pptxChapter -4.pptx
Chapter -4.pptx
woldu2
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Bhavin Darji
 
syntax-directed-translation.ppt syntax-directed-translation.ppt
syntax-directed-translation.ppt syntax-directed-translation.pptsyntax-directed-translation.ppt syntax-directed-translation.ppt
syntax-directed-translation.ppt syntax-directed-translation.ppt
dejusertse
 
Unit iv-syntax-directed-translation
Unit iv-syntax-directed-translationUnit iv-syntax-directed-translation
Unit iv-syntax-directed-translation
Ajith kumar M P
 
Compiler Design UNIT III PPT (SDD, SDT).pdf
Compiler Design UNIT III PPT (SDD, SDT).pdfCompiler Design UNIT III PPT (SDD, SDT).pdf
Compiler Design UNIT III PPT (SDD, SDT).pdf
Shiva350357
 
Semantic Analysis.pptx
Semantic Analysis.pptxSemantic Analysis.pptx
Semantic Analysis.pptx
ZarfaMasood
 
atc 3rd module compiler and automata.ppt
atc 3rd module compiler and automata.pptatc 3rd module compiler and automata.ppt
atc 3rd module compiler and automata.ppt
ranjan317165
 
3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf
TANZINTANZINA
 
L attribute in compiler design
L  attribute in compiler designL  attribute in compiler design
L attribute in compiler design
khush_boo31
 
Compiler design selective dissemination of information syntax direct translat...
Compiler design selective dissemination of information syntax direct translat...Compiler design selective dissemination of information syntax direct translat...
Compiler design selective dissemination of information syntax direct translat...
ganeshjaggineni1927
 
Ad

Recently uploaded (20)

Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Ad

Semantics analysis

  • 2. Semantic Analysis • Semantics of a language provide meaning to its constructs like tokens and syntax structure. • Semantic analysis judge whether the syntax structure constructed in the source program provide any meaning or not. • For example - Int a=“book”; is syntactically correct but generates a semantic error. • Solution – CFG + Semantic Rules = Syntax directed definition.
  • 3. Semantic Analysis • output of syntax analysis which is a parse tree is the input of semantic analysis which is also a parse tree with some additional attributes called annotated parse tree. • Some semantic rules are associated with the production rules in semantic analysis, like: • Production Semantic Rule E->E1+T E.code =E1.code||T.code||'+'
  • 4. Semantic Analysis ◦In which certain checks are performed to ensure that the components of a program fit together meaningfully. ◦The semantic analysis phase checks the source program for semantic errors and gathers type information for the subsequent code- generation phase.
  • 5. Ways to associate semantic rules ◦There are two ways to represent the semantic rules associated with grammar symbols ◦ Syntax-Directed Definitions (SDD) ◦ Syntax-Directed Translation Schemes (SDT)
  • 6. Syntax-Directed Definitions ◦ A syntax-directed definition (SDD) is a context-free grammar together with attributes and rules. ◦ Attributes are associated with grammar symbols and rules are associated with productions. ◦ PRODUCTION SEMANTIC RULE E → E1 + T E.code = E1.code || T.code || ‘+’
  • 7. Attribute Grammar ◦ Attribute grammar is a context-free grammar where some additional information (attributes) are appended to one or more of its non- terminals in order to provide context-sensitive information. ◦ Attribute grammar is a medium to provide semantics to the context- free grammar and it can help specify the syntax and semantics of a programming language. ◦ Example E → E + T { E.value = E.value + T.value }
  • 8. synthesized attributes ◦ Synthesized attribute get values from the attribute values of their child nodes. ◦ Example S → ABC ◦ If S is taking values from its child nodes (A,B,C), then it is said to be a synthesized attribute, as the values of ABC are synthesized to S.
  • 9. Inherited attributes ◦ Inherited attributes can take values from parent and/or siblings Example S → ABC ◦ A can get values from S, B and C. ◦ B can take values from S, A, and C. ◦ C can take values from S, A, and B.
  • 10. SDD for expression grammar with synthesized attributes Annotated Parse Tree for 3*5+4n
  • 11. SDD for expression grammar with inherited attributes Annotated Parse Tree for 3*5
  • 12. S-attributed SDT ◦ If an SDT uses only synthesized attributes it is called S-attributed SDT. ◦ These attributes are evaluated using S-attributed SDTs that have their semantic actions written after the production (right hand side). Example: S → ABC ◦ S can take values from A, B, and C only.
  • 13. L-attributed SDT ◦ This form of SDT uses both synthesized and inherited attributes with restriction of not taking values from right siblings. ◦ In L-attributed SDTs, a non-terminal can get values from its parent, child, and sibling nodes. As in the following production Example: S → ABC ◦ S can take values from A, B, and C. ◦ A can take values from S only. ◦ B can take values from S and A. ◦ C can get values from S, A, and B. No non-terminal can get values from the sibling to its right.
  • 14. SYNTAX -Directed TRANSLATION (SDT) Background: ◦ Parser uses a CFG (Context-free-Grammer) to validate the string and produce output for next phase of the compiler. Output could be either a parse tree or abstract syntax tree ◦ Now to interleave semantic analysis with syntax analysis phase of the compiler, we use Syntax Directed Translation.
  • 15. SYNTAX -Directed TRANSLATION (SDT) Definition: Syntax Directed Translation are augmented rules to the grammar that facilitate semantic analysis. Grammar + semantic rules = SDT
  • 16. Example: E -> E+T | T T -> T*F | F F -> Id Grammar RULES E -> E+T { E.val = E.val + T.val } E -> T { E.val = T.val } T -> T*F { T.val = T.val * F.val } T -> F { T.val = F.val } F -> ID { F.val = ID.lexval }
  • 17. Application of SDT ◦ Executing arithmetic expression ◦ Conversion from infix to postfix ◦ Conversion from infix to prefix ◦ Conversion from binary to decimal ◦ Counting number of reductions ◦ Creating syntax tree ◦ Generating the intermediate code ◦ Type checking ◦ Storing type info into symbol table
  • 18. Example: Grammar : E -> E+T | T. T -> T*F | F F -> digit input string: 3*5+4
  • 20. Syntax directed translation schemes ◦ The syntax directed translation scheme is used to evaluate the order of semantic rules. ◦ In translation scheme, the semantic rules are embedded within the right side of the productions. ◦ The position at which an action is to be executed is shown by enclosed between braces.
  • 21. Errors Program submitted to a compiler often have errors of various kinds So, good compiler should be able to detect as many errors as possible in various ways and also recover from them. Even in the presence of errors ,the compiler should scan the program and try to compile all of it.
  • 22. CLASSIFICATION OF COMPILE TIME ERRORS •lexical errors •Syntactic errors •Semantic errors
  • 23. Type Mismatch Int a = 10; String b=“Hello World”; Double sum=a+b; Undeclared or multiple declare variable Int a , b; int b; a = 10; b = 10; Sum = a+b;
  • 24. Actual and formal Parameter mismatch Fun (int a) { STATEMENTS; } String value = “ Hello World ” ; Fun (value); Reserved identifier mismatch int void = 10 ;
  • 25. Manage type casting When a binary arithmetic operator is applied to an integer and real. In this case, the compiler may need to be converting the integer to a real. As shown in figure given below Float position, initial, Rate; Initial = 10.5 ; Rate = 10.5 ; Position = initial + Rate * 60 ; int a=10 ; float b=15.5 ; float c= a+int(b) ;