SlideShare a Scribd company logo
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

Linux file system
Linux file systemLinux file system
Linux file system
Md. Tanvir Hossain
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
Mukesh Chinta
 
Distributed Database System
Distributed Database SystemDistributed Database System
Distributed Database SystemSulemang
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
Tasif Tanzim
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidancewahab13
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data StructureAnuj Modi
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
Protap Mondal
 
process control block
process control blockprocess control block
process control block
Vikas SHRIVASTAVA
 
File system Os
File system OsFile system Os
File system Os
Nehal Naik
 
Signed Addition And Subtraction
Signed Addition And SubtractionSigned Addition And Subtraction
Signed Addition And Subtraction
Keyur Vadodariya
 
Characteristic of dabase approach
Characteristic of dabase approachCharacteristic of dabase approach
Characteristic of dabase approach
Luina Pani
 
File system structure
File system structureFile system structure
File system structure
sangrampatil81
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMSkoolkampus
 
File organization 1
File organization 1File organization 1
File organization 1
Rupali Rana
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Ravindra Raju Kolahalam
 
System Administration: Introduction to system administration
System Administration: Introduction to system administrationSystem Administration: Introduction to system administration
System Administration: Introduction to system administration
Khang-Ling Loh
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
Muhammad SiRaj Munir
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architecture
Yisal Khan
 

What's hot (20)

Linux file system
Linux file systemLinux file system
Linux file system
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Distributed Database System
Distributed Database SystemDistributed Database System
Distributed Database System
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Distributed database
Distributed databaseDistributed database
Distributed database
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
process control block
process control blockprocess control block
process control block
 
File system Os
File system OsFile system Os
File system Os
 
Signed Addition And Subtraction
Signed Addition And SubtractionSigned Addition And Subtraction
Signed Addition And Subtraction
 
Characteristic of dabase approach
Characteristic of dabase approachCharacteristic of dabase approach
Characteristic of dabase approach
 
File system structure
File system structureFile system structure
File system structure
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 
File organization 1
File organization 1File organization 1
File organization 1
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
System Administration: Introduction to system administration
System Administration: Introduction to system administrationSystem Administration: Introduction to system administration
System Administration: Introduction to system administration
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architecture
 

Recently uploaded

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 

Recently uploaded (20)

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 

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>