SlideShare a Scribd company logo
1 of 21
BNF EBNF
• What is BNF?
• Why need BNF?
• What does BNF look like?
• Examples of BNF
• Parse trees
• Examples of parse trees
• Origin of EBNF
• Examples
What is BNF?
• BNF = Backus-Naur Form
• It is a formal, mathematical way to specify context-free grammars
• BNF is Meta language (Meta language - a language that describes a
language, which can describe a programming language).
• It is precise and unambiguous
Why need BNF?
• Before BNF, people specified programming languages ambiguously,
i.e., with English
“He fed her cat food.”
Can have different meanings,
• He fed a woman’s cat some food.
• He fed a woman some food that was intended for cats.
• He somehow encouraged some cat food to eat something.
Peter NaurJohn Backus
What does BNF look like?
BNF grammar consists of 4 parts,
• The set of tokens
• The set of non terminal symbols
• The start symbol
• The set of productions
LHS = RHS
Non-terminals = Terminals/non-terminals
“or”
“is defined as”
Assign -> id := expr
id -> A|B|C
expr -> id+ expr | id * expr |(expr)|id
Terminal
Nonterminal
What does BNF look like?
Example 1
A := B*(A+C)
Solution -->
Assign -> id := expr
A := expr
A := id*expr
A := B*(expr)
A := B*(id + expr)
A := B*(A + expr)
A := B*(A + id)
A := B*(A + C)
Example 2
A := (B * A) + C
Solution -->
Assign -> id := expr
A := (expr)
A := (id*expr)
A := (B*expr)
A := (B*(expr))
This cannot be derived.
Example 3
A:=A+B*C
Solution -->
Assign -> id := expr
A:=id+expr
A:=A+expr
A:=A+id*expr
A:=A+B*expr
A:=A+B*id
A:=A+B*C
Parse Trees
• A Parse tree is a hierarchical representation of a derivation.
• A grammar is ambiguous if it generates a sentential form that has two
or more distinct parse trees.
Example 1
A := B*(A+C)
<assign>
id := <expr>
A id * <expr>
B ( expr )
id + expr
A id
C
Example 3
A:=A+B*C
<assign>
Id := <expr>
A id + <expr>
A id * <expr>
B id
C
<assign>
Id := <expr>
A <expr> + <expr>
id <expr> * <expr>
A id id
B C
Origin of EBNF
• Stands for “Extended Backus-Naur Form”.
• Increase readability and write ability.
• Optional [ ]
<if_cond> if <logic> then <stmt>
• Repetition { }
<stmts> <stmt> { ; <stmt> } * 0 or more
+ 1 or more
eg:- digit { digit } digit can be 1 or more
• Group ( )
value + integer | - integer
value ( + | - )integer
+
Syntax Graphs
• <stmt> <var> = <expr>
var = expr
• <var> A | B | C
A
B
C
<var>
<stmt>
<stmt> <stmt> | ; <stmt>
<var> a | ab
<stmt>
;
a
b
Example 1
<expr> <term> + <term> | <term> - <term>
Example 2
<program> begin <stmt_list> end
<term> <term>
-
+
<expr>
begin end<stmt_list>
Example 3
<stmt> <var> = <expression>
<var> = <expression>
<stmt>

More Related Content

What's hot

Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptxSyed Zaid Irshad
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating SystemJanki Shah
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMSkoolkampus
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Knowledge representation In Artificial Intelligence
Knowledge representation In Artificial IntelligenceKnowledge representation In Artificial Intelligence
Knowledge representation In Artificial IntelligenceRamla Sheikh
 
Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)Ravinder Kamboj
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationDbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationBIT Durg
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
File organization 1
File organization 1File organization 1
File organization 1Rupali Rana
 

What's hot (20)

Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
Hashing
HashingHashing
Hashing
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Knowledge representation In Artificial Intelligence
Knowledge representation In Artificial IntelligenceKnowledge representation In Artificial Intelligence
Knowledge representation In Artificial Intelligence
 
Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationDbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
File organization 1
File organization 1File organization 1
File organization 1
 
System calls
System callsSystem calls
System calls
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 

Recently uploaded

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Recently uploaded (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

BNF & EBNF

  • 2. • What is BNF? • Why need BNF? • What does BNF look like? • Examples of BNF • Parse trees • Examples of parse trees • Origin of EBNF • Examples
  • 3. What is BNF? • BNF = Backus-Naur Form • It is a formal, mathematical way to specify context-free grammars • BNF is Meta language (Meta language - a language that describes a language, which can describe a programming language). • It is precise and unambiguous
  • 4. Why need BNF? • Before BNF, people specified programming languages ambiguously, i.e., with English “He fed her cat food.” Can have different meanings, • He fed a woman’s cat some food. • He fed a woman some food that was intended for cats. • He somehow encouraged some cat food to eat something.
  • 6. What does BNF look like? BNF grammar consists of 4 parts, • The set of tokens • The set of non terminal symbols • The start symbol • The set of productions LHS = RHS Non-terminals = Terminals/non-terminals
  • 7. “or” “is defined as” Assign -> id := expr id -> A|B|C expr -> id+ expr | id * expr |(expr)|id Terminal Nonterminal What does BNF look like?
  • 8. Example 1 A := B*(A+C) Solution --> Assign -> id := expr A := expr A := id*expr A := B*(expr) A := B*(id + expr) A := B*(A + expr) A := B*(A + id) A := B*(A + C)
  • 9. Example 2 A := (B * A) + C Solution --> Assign -> id := expr A := (expr) A := (id*expr) A := (B*expr) A := (B*(expr)) This cannot be derived.
  • 10. Example 3 A:=A+B*C Solution --> Assign -> id := expr A:=id+expr A:=A+expr A:=A+id*expr A:=A+B*expr A:=A+B*id A:=A+B*C
  • 11. Parse Trees • A Parse tree is a hierarchical representation of a derivation.
  • 12. • A grammar is ambiguous if it generates a sentential form that has two or more distinct parse trees.
  • 13. Example 1 A := B*(A+C) <assign> id := <expr> A id * <expr> B ( expr ) id + expr A id C
  • 14. Example 3 A:=A+B*C <assign> Id := <expr> A id + <expr> A id * <expr> B id C
  • 15. <assign> Id := <expr> A <expr> + <expr> id <expr> * <expr> A id id B C
  • 16. Origin of EBNF • Stands for “Extended Backus-Naur Form”. • Increase readability and write ability.
  • 17. • Optional [ ] <if_cond> if <logic> then <stmt> • Repetition { } <stmts> <stmt> { ; <stmt> } * 0 or more + 1 or more eg:- digit { digit } digit can be 1 or more • Group ( ) value + integer | - integer value ( + | - )integer +
  • 18. Syntax Graphs • <stmt> <var> = <expr> var = expr • <var> A | B | C A B C <var> <stmt>
  • 19. <stmt> <stmt> | ; <stmt> <var> a | ab <stmt> ; a b
  • 20. Example 1 <expr> <term> + <term> | <term> - <term> Example 2 <program> begin <stmt_list> end <term> <term> - + <expr> begin end<stmt_list>
  • 21. Example 3 <stmt> <var> = <expression> <var> = <expression> <stmt>