SlideShare a Scribd company logo
Jul 7, 2014
BNF
Metalanguages
 A metalanguage is a language used to talk about a
language (usually a different one)
 We can use English as its own metalanguage (e.g.
describing English grammar in English)
 It is essential to distinguish between the
metalanguage terms and the object language terms
BNF
 BNF stands for either Backus-Naur Form or Backus
Normal Form
 BNF is a metalanguage used to describe the
grammar of a programming language
 BNF is formal and precise
 BNF is a notation for context-free grammars
 BNF is essential in compiler construction
 There are many dialects of BNF in use, but…
 …the differences are almost always minor
BNF
 < > indicate a nonterminal that needs to be further
expanded, e.g. <variable>
 Symbols not enclosed in < > are terminals; they
represent themselves, e.g. if, while, (
 The symbol ::= means is defined as
 The symbol | means or; it separates alternatives, e.g.
<addop> ::= + | -
 This is all there is to “plain” BNF; but we will discuss
extended BNF (EBNF) later in this lecture
BNF uses recursion
 <integer> ::= <digit> | <integer> <digit>
or
<integer> ::= <digit> | <digit> <integer>
 Recursion is all that is needed (at least, in a formal
sense)
 "Extended BNF" allows repetition as well as recursion
 Repetition is usually better when using BNF to
construct a compiler
BNF Examples I
 <digit> ::=
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
 <if statement> ::=
if ( <condition> ) <statement>
| if ( <condition> ) <statement>
else <statement>
BNF Examples II
 <unsigned integer> ::=
<digit> | <unsigned integer> <digit>
 <integer> ::=
<unsigned integer>
| + <unsigned integer>
| - <unsigned integer>
BNF Examples III
 <identifier> ::=
<letter>
| <identifier> <letter>
| <identifier> <digit>
 <block> ::= { <statement list> }
 <statement list> ::=
<statement>
| <statement list> <statement>
BNF Examples IV
 <statement> ::=
<block>
| <assignment statement>
| <break statement>
| <continue statement>
| <do statement>
| <for loop>
| <goto statement>
| <if statement>
| . . .
Extended BNF
 The following are pretty standard:
 [ ] enclose an optional part of the rule

Example:
<if statement> ::=
if ( <condition> ) <statement> [ else <statement> ]
 { } mean the enclosed can be repeated any number of times
(including zero)

Example:
<parameter list> ::= ( )
| ( { <parameter> , } <parameter> )
Variations
 The preceding notation is the original and most
common notation
 BNF was designed before we had boldface, color, more
than one font, etc.
 A typical modern variation might:
 Use boldface to indicate multi-character terminals
 Quote single-character terminals (because boldface isn’t so
obvious in this case)
 Example:
 if_statement ::=
if "(" condition ")" statement [ else statement ]
Limitations of BNF
 No easy way to impose length limitations, such as
maximum length of variable names
 No easy way to describe ranges, such as 1 to 31
 No way at all to impose distributed requirements, such
as, a variable must be declared before it is used
 Describes only syntax, not semantics
 Nothing clearly better has been devised
The End
http://cuiwww.unige.ch/db-research/Enseignement/analyseinfo/AboutBNF.html

More Related Content

What's hot

2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammars2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammars
Sampath Kumar S
 
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion | Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
FabMinds
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
Akila Krishnamoorthy
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
suthi
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
Context free langauges
Context free langaugesContext free langauges
Context free langauges
sudhir sharma
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
Ronak Thakkar
 
Variants of Turing Machine
Variants of Turing MachineVariants of Turing Machine
Variants of Turing Machine
Rajendran
 
Python built in functions
Python built in functionsPython built in functions
Python built in functions
Rakshitha S
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
Divyanshu Rasauria
 
C++ shared libraries and loading
C++ shared libraries and loadingC++ shared libraries and loading
C++ shared libraries and loading
Rahul Jamwal
 
minimization the number of states of DFA
minimization the number of states of DFAminimization the number of states of DFA
minimization the number of states of DFA
Archana Gopinath
 
Types of grammer - TOC
Types of grammer - TOCTypes of grammer - TOC
Types of grammer - TOC
AbhayDhupar
 
Characteristics of c#
Characteristics of c#Characteristics of c#
Characteristics of c#
Prasanna Kumar SM
 
STL in C++
STL in C++STL in C++
STL in C++
Surya Prakash Sahu
 
Theory of Automata
Theory of AutomataTheory of Automata
Theory of Automata
Farooq Mian
 
Flat unit 1
Flat unit 1Flat unit 1
Flat unit 1
VenkataRaoS1
 
Converting Scikit-Learn to PMML
Converting Scikit-Learn to PMMLConverting Scikit-Learn to PMML
Converting Scikit-Learn to PMML
Villu Ruusmann
 
Basic blocks - compiler design
Basic blocks - compiler designBasic blocks - compiler design
Basic blocks - compiler design
hmnasim15
 

What's hot (20)

2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammars2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammars
 
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion | Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Context free langauges
Context free langaugesContext free langauges
Context free langauges
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
 
Variants of Turing Machine
Variants of Turing MachineVariants of Turing Machine
Variants of Turing Machine
 
Python built in functions
Python built in functionsPython built in functions
Python built in functions
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
 
C++ shared libraries and loading
C++ shared libraries and loadingC++ shared libraries and loading
C++ shared libraries and loading
 
minimization the number of states of DFA
minimization the number of states of DFAminimization the number of states of DFA
minimization the number of states of DFA
 
Types of grammer - TOC
Types of grammer - TOCTypes of grammer - TOC
Types of grammer - TOC
 
Characteristics of c#
Characteristics of c#Characteristics of c#
Characteristics of c#
 
STL in C++
STL in C++STL in C++
STL in C++
 
Theory of Automata
Theory of AutomataTheory of Automata
Theory of Automata
 
Flat unit 1
Flat unit 1Flat unit 1
Flat unit 1
 
Converting Scikit-Learn to PMML
Converting Scikit-Learn to PMMLConverting Scikit-Learn to PMML
Converting Scikit-Learn to PMML
 
Basic blocks - compiler design
Basic blocks - compiler designBasic blocks - compiler design
Basic blocks - compiler design
 

Viewers also liked

Bnf and ambiquity
Bnf and ambiquityBnf and ambiquity
Bnf and ambiquity
BBDITM LUCKNOW
 
Lecture 15 16
Lecture 15 16Lecture 15 16
Lecture 15 16
Najmul Hassan
 
Lecture 21 22
Lecture 21 22Lecture 21 22
Lecture 21 22
Najmul Hassan
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
bolovv
 
Introduction to compiler construction
Introduction to compiler constructionIntroduction to compiler construction
Introduction to compiler construction
Yuji Shimojo
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Binsent Ribera
 

Viewers also liked (6)

Bnf and ambiquity
Bnf and ambiquityBnf and ambiquity
Bnf and ambiquity
 
Lecture 15 16
Lecture 15 16Lecture 15 16
Lecture 15 16
 
Lecture 21 22
Lecture 21 22Lecture 21 22
Lecture 21 22
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
 
Introduction to compiler construction
Introduction to compiler constructionIntroduction to compiler construction
Introduction to compiler construction
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 

Recently uploaded

“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 

Recently uploaded (20)

“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 

25 bnf

  • 2. Metalanguages  A metalanguage is a language used to talk about a language (usually a different one)  We can use English as its own metalanguage (e.g. describing English grammar in English)  It is essential to distinguish between the metalanguage terms and the object language terms
  • 3. BNF  BNF stands for either Backus-Naur Form or Backus Normal Form  BNF is a metalanguage used to describe the grammar of a programming language  BNF is formal and precise  BNF is a notation for context-free grammars  BNF is essential in compiler construction  There are many dialects of BNF in use, but…  …the differences are almost always minor
  • 4. BNF  < > indicate a nonterminal that needs to be further expanded, e.g. <variable>  Symbols not enclosed in < > are terminals; they represent themselves, e.g. if, while, (  The symbol ::= means is defined as  The symbol | means or; it separates alternatives, e.g. <addop> ::= + | -  This is all there is to “plain” BNF; but we will discuss extended BNF (EBNF) later in this lecture
  • 5. BNF uses recursion  <integer> ::= <digit> | <integer> <digit> or <integer> ::= <digit> | <digit> <integer>  Recursion is all that is needed (at least, in a formal sense)  "Extended BNF" allows repetition as well as recursion  Repetition is usually better when using BNF to construct a compiler
  • 6. BNF Examples I  <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  <if statement> ::= if ( <condition> ) <statement> | if ( <condition> ) <statement> else <statement>
  • 7. BNF Examples II  <unsigned integer> ::= <digit> | <unsigned integer> <digit>  <integer> ::= <unsigned integer> | + <unsigned integer> | - <unsigned integer>
  • 8. BNF Examples III  <identifier> ::= <letter> | <identifier> <letter> | <identifier> <digit>  <block> ::= { <statement list> }  <statement list> ::= <statement> | <statement list> <statement>
  • 9. BNF Examples IV  <statement> ::= <block> | <assignment statement> | <break statement> | <continue statement> | <do statement> | <for loop> | <goto statement> | <if statement> | . . .
  • 10. Extended BNF  The following are pretty standard:  [ ] enclose an optional part of the rule  Example: <if statement> ::= if ( <condition> ) <statement> [ else <statement> ]  { } mean the enclosed can be repeated any number of times (including zero)  Example: <parameter list> ::= ( ) | ( { <parameter> , } <parameter> )
  • 11. Variations  The preceding notation is the original and most common notation  BNF was designed before we had boldface, color, more than one font, etc.  A typical modern variation might:  Use boldface to indicate multi-character terminals  Quote single-character terminals (because boldface isn’t so obvious in this case)  Example:  if_statement ::= if "(" condition ")" statement [ else statement ]
  • 12. Limitations of BNF  No easy way to impose length limitations, such as maximum length of variable names  No easy way to describe ranges, such as 1 to 31  No way at all to impose distributed requirements, such as, a variable must be declared before it is used  Describes only syntax, not semantics  Nothing clearly better has been devised