SlideShare a Scribd company logo
Compiler Design
BNF
Ambiquity
BNF-Backus Naur Form
• Backus normal form (BNF) is a notation technique for context-free
grammars.
• It is often used to describe the syntax of languages used in
computing.
• Such as computer programming languages, document formats,
instruction sets and communication protocols.
• They are applied wherever exact descriptions of languages are
needed.
• John Backus, a programming language designer at IBM, proposed
a metalanguage of "metalinguistic formulas" to describe the
syntax of the new programming language IAL, known today
as ALGOL 58 (1959). His notation was first used in the ALGOL 60
report.
• It is used to formally define the grammar of a language.
1/31/2017
ANKUR SRIVASTAVA ASSISTANT
PROFESSOR JIT
2
Contd…..
• It is a formal mathematical way to describe a language.
• It is used to describe the syntax of the programming languages.
• It is a way of defining syntax.
• It consists of…..
 a set of terminal symbols
 a set of non-terminal symbols
 a set of production rules of the form
 Left - Hand- Side ::= Right- Hand- Side
 where the LHS is a non-terminal symbol & the RHS is a sequence
of symbols (terminals or non-terminals).
 The meaning of the production rule is that the non-terminal on
the LHS may be replaced by the expression on the RHS.
1/31/2017
ANKUR SRIVASTAVA ASSISTANT
PROFESSOR JIT
3
Example:-Write a BNF grammar for the language of
University of Lucknow course codes.
• Example sentences:
• CSI3125
• MAT2743
• PHY1200
• CHE6581
• CSI9999
1/31/2017
ANKUR SRIVASTAVA ASSISTANT
PROFESSOR JIT
4
Solution:
• <coursecode> ::= <acadunit> <coursenumber>
• <acadunit> ::= <letter> <letter> <letter>
• <coursenumber> ::= <year> <semesters> <digit> <digit>
• <year> ::= <ugrad> | <grad>
• <ugrad> ::= 0 | 1 | 2 | 3 | 4
• <grad> ::= 5 | 6 | 7 | 9
• <semesters> ::= <onesemester> | <twosemesters>
• <onesemester> ::= <frenchone> | <englishone> | <bilingual>
• <frenchone> ::= 5 | 7
• <englishone> ::= 1 | 3
• <bilingual> ::= 9
• <twosemesters> ::= <frenchtwo> | <englishtwo>
• <frenchtwo> ::= 6 | 8
• <englishtwo> ::= 2 | 4
• <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
1/31/2017
ANKUR SRIVASTAVA ASSISTANT
PROFESSOR JIT
5
Write a BNF grammar for the language of palindromes
• Examples (spaces don't count!):
• aba
• pop
• pop a pop
• elu par cette crapule
• a man a plan a canal panama
• Solution:
 <palindrome> ::= a <palindrome> a | b <palindrome> b |
c <palindrome> c | d <palindrome> d |
e <palindrome> e | ...
|z <palindrome> z
<palindrome> ::= <letter>
<letter> ::= a | b | c | ... | y | z
1/31/2017
ANKUR SRIVASTAVA ASSISTANT
PROFESSOR JIT
6
Ambiguity or Ambiguous
Grammar
• A grammar G is said to be ambiguous if it has more
than one parse tree (left or right derivation) for at
least one string.
• C, C++, and Java have a large number of –
operators and – precedence levels.
• Instead of using a large grammar, we can: –
Write a smaller ambiguous grammar, and –
Give separate precedence and associativity.
1/31/2017
ANKUR SRIVASTAVA ASSISTANT
PROFESSOR JIT
7
Contd……
• An Ambiguous Expression Grammar G1
Expr → Expr Op Expr | ( Expr ) | Integer
Op → + | - | * | / | % | **
Ambiguous Parse of 5-4+3
Using Grammar G1
1/31/2017
ANKUR SRIVASTAVA ASSISTANT
PROFESSOR JIT
8
Exp
3+
ExpOpExp
ExpOpExp
-
45
Contd……
• E → E + E
• E → E – E
• E → id
For the string id + id – id, the above grammar
generates two parse trees:
1/31/2017
ANKUR SRIVASTAVA ASSISTANT
PROFESSOR JIT
9
THANKS

More Related Content

What's hot

Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Chapter 2: Relations
Chapter 2: RelationsChapter 2: Relations
Chapter 2: Relations
nszakir
 
Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebragavhays
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
eShikshak
 
2.1 & 2.2 grammar introduction – types of grammar
2.1 & 2.2 grammar introduction – types of grammar2.1 & 2.2 grammar introduction – types of grammar
2.1 & 2.2 grammar introduction – types of grammar
Sampath Kumar S
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
Mukesh Tekwani
 
Implication And Biconditional
Implication And Biconditional Implication And Biconditional
Implication And Biconditional
VishalVishwakarma59
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
Mobeen Mustafa
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
shah zeb
 
Escape sequences
Escape sequencesEscape sequences
Escape sequences
Way2itech
 
Chomsky Hierarchy.ppt
Chomsky Hierarchy.pptChomsky Hierarchy.ppt
Chomsky Hierarchy.ppt
AayushSingh233965
 
Recursion
RecursionRecursion
Recursion
Abdur Rehman
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
Harry Potter
 
String operation
String operationString operation
String operation
Shakila Mahjabin
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
 
BNF & EBNF
BNF & EBNFBNF & EBNF
BNF & EBNF
AshaniDickowita
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in JavaJin Castor
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Vikas Sharma
 
Semantic Analysis.pptx
Semantic Analysis.pptxSemantic Analysis.pptx
Semantic Analysis.pptx
ZarfaMasood
 

What's hot (20)

Linked List
Linked ListLinked List
Linked List
 
Chapter 2: Relations
Chapter 2: RelationsChapter 2: Relations
Chapter 2: Relations
 
Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebra
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
2.1 & 2.2 grammar introduction – types of grammar
2.1 & 2.2 grammar introduction – types of grammar2.1 & 2.2 grammar introduction – types of grammar
2.1 & 2.2 grammar introduction – types of grammar
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Implication And Biconditional
Implication And Biconditional Implication And Biconditional
Implication And Biconditional
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Escape sequences
Escape sequencesEscape sequences
Escape sequences
 
Chomsky Hierarchy.ppt
Chomsky Hierarchy.pptChomsky Hierarchy.ppt
Chomsky Hierarchy.ppt
 
Recursion
RecursionRecursion
Recursion
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
 
Recursion
RecursionRecursion
Recursion
 
String operation
String operationString operation
String operation
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
BNF & EBNF
BNF & EBNFBNF & EBNF
BNF & EBNF
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Semantic Analysis.pptx
Semantic Analysis.pptxSemantic Analysis.pptx
Semantic Analysis.pptx
 

Viewers also liked

Minimization of dfa
Minimization of dfaMinimization of dfa
Minimization of dfa
BBDITM LUCKNOW
 
Backus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsBackus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsAshutosh Pandey
 
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
 
Clinical Cardiology Cases
Clinical  Cardiology  CasesClinical  Cardiology  Cases
Clinical Cardiology Cases
hospital
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Binsent Ribera
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
BBDITM LUCKNOW
 
History of cardiology
History of cardiologyHistory of cardiology
History of cardiology
Dona Mathew
 
Future of cardiology
Future of cardiologyFuture of cardiology
Future of cardiology
mkocierz
 
Clinical Cardiology
Clinical CardiologyClinical Cardiology
Clinical Cardiology
hospital
 
Pediatric-Cardiology-101.ppt
Pediatric-Cardiology-101.pptPediatric-Cardiology-101.ppt
Pediatric-Cardiology-101.pptempite
 
Theory of design
Theory of designTheory of design
Theory of design
Manish Jain Luhadia
 
Design Theory - Lecture 01: What is design?
Design Theory - Lecture 01: What is design?Design Theory - Lecture 01: What is design?
Design Theory - Lecture 01: What is design?Bas Leurs
 
Theory of architecture
Theory of architectureTheory of architecture
Theory of architectureKrishna Jhawar
 
Basic Theory of Architecture
Basic Theory of Architecture Basic Theory of Architecture
Basic Theory of Architecture
Architecture Faculty
 
03 architectural principles & elements
03 architectural principles & elements03 architectural principles & elements
03 architectural principles & elementsJan Echiverri-Quintano
 

Viewers also liked (20)

25 bnf
25 bnf25 bnf
25 bnf
 
Minimization of dfa
Minimization of dfaMinimization of dfa
Minimization of dfa
 
Backus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsBackus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal Forms
 
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
 
Cardiology Presentation
Cardiology PresentationCardiology Presentation
Cardiology Presentation
 
Clinical Cardiology Cases
Clinical  Cardiology  CasesClinical  Cardiology  Cases
Clinical Cardiology Cases
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
 
History of cardiology
History of cardiologyHistory of cardiology
History of cardiology
 
Future of cardiology
Future of cardiologyFuture of cardiology
Future of cardiology
 
Clinical Cardiology
Clinical CardiologyClinical Cardiology
Clinical Cardiology
 
Pediatric-Cardiology-101.ppt
Pediatric-Cardiology-101.pptPediatric-Cardiology-101.ppt
Pediatric-Cardiology-101.ppt
 
Theory of design
Theory of designTheory of design
Theory of design
 
Design Theory - Lecture 01: What is design?
Design Theory - Lecture 01: What is design?Design Theory - Lecture 01: What is design?
Design Theory - Lecture 01: What is design?
 
Theory of architecture
Theory of architectureTheory of architecture
Theory of architecture
 
Basic Theory of Architecture
Basic Theory of Architecture Basic Theory of Architecture
Basic Theory of Architecture
 
03 architectural principles & elements
03 architectural principles & elements03 architectural principles & elements
03 architectural principles & elements
 

Similar to Bnf and ambiquity

System Programming Unit III
System Programming Unit IIISystem Programming Unit III
System Programming Unit IIIManoj Patil
 
Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02riddhi viradiya
 
Explaining Spreadsheets with Spreadsheets
Explaining Spreadsheets with SpreadsheetsExplaining Spreadsheets with Spreadsheets
Explaining Spreadsheets with Spreadsheets
Jácome Cunha
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Kuppusamy P
 
Constraint Grammar and Apertium
Constraint Grammar and ApertiumConstraint Grammar and Apertium
Constraint Grammar and Apertium
unhammer
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
BBDITM LUCKNOW
 
6. describing syntax and semantics
6. describing syntax and semantics6. describing syntax and semantics
6. describing syntax and semantics
Zambales National High School
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
Anshumali Singh
 
Introduction to programming c
Introduction to programming cIntroduction to programming c
Introduction to programming c
Md. Rakibuzzaman Khan Pathan
 
02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx
arifaqazi2
 
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
Pierre Schaus
 
8074448.ppt
8074448.ppt8074448.ppt
10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechz10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechz
Shahbaz Ahmad
 
Cfg part i
Cfg   part iCfg   part i
Cfg part i
Kashif Ali
 
Build your own ASR engine
Build your own ASR engineBuild your own ASR engine
Build your own ASR engine
Korakot Chaovavanich
 
201505 CSE340 Lecture 04
201505 CSE340 Lecture 04201505 CSE340 Lecture 04
201505 CSE340 Lecture 04
Javier Gonzalez-Sanchez
 
Contest Tips and Tricks
Contest Tips and TricksContest Tips and Tricks
Contest Tips and Tricksmbuzdalov
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
Dattatray Gandhmal
 

Similar to Bnf and ambiquity (20)

System Programming Unit III
System Programming Unit IIISystem Programming Unit III
System Programming Unit III
 
Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02
 
Introduction
IntroductionIntroduction
Introduction
 
Introduction
IntroductionIntroduction
Introduction
 
Explaining Spreadsheets with Spreadsheets
Explaining Spreadsheets with SpreadsheetsExplaining Spreadsheets with Spreadsheets
Explaining Spreadsheets with Spreadsheets
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Constraint Grammar and Apertium
Constraint Grammar and ApertiumConstraint Grammar and Apertium
Constraint Grammar and Apertium
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
 
6. describing syntax and semantics
6. describing syntax and semantics6. describing syntax and semantics
6. describing syntax and semantics
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Introduction to programming c
Introduction to programming cIntroduction to programming c
Introduction to programming c
 
02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx
 
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
 
8074448.ppt
8074448.ppt8074448.ppt
8074448.ppt
 
10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechz10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechz
 
Cfg part i
Cfg   part iCfg   part i
Cfg part i
 
Build your own ASR engine
Build your own ASR engineBuild your own ASR engine
Build your own ASR engine
 
201505 CSE340 Lecture 04
201505 CSE340 Lecture 04201505 CSE340 Lecture 04
201505 CSE340 Lecture 04
 
Contest Tips and Tricks
Contest Tips and TricksContest Tips and Tricks
Contest Tips and Tricks
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 

More from BBDITM LUCKNOW

Unit 5 cspc
Unit 5 cspcUnit 5 cspc
Unit 5 cspc
BBDITM LUCKNOW
 
Unit 4 cspc
Unit 4 cspcUnit 4 cspc
Unit 4 cspc
BBDITM LUCKNOW
 
Unit3 cspc
Unit3 cspcUnit3 cspc
Unit3 cspc
BBDITM LUCKNOW
 
Cse ppt 2018
Cse ppt 2018Cse ppt 2018
Cse ppt 2018
BBDITM LUCKNOW
 
Binary system ppt
Binary system pptBinary system ppt
Binary system ppt
BBDITM LUCKNOW
 
Unit 4 ca-input-output
Unit 4 ca-input-outputUnit 4 ca-input-output
Unit 4 ca-input-output
BBDITM LUCKNOW
 
Unit 3 ca-memory
Unit 3 ca-memoryUnit 3 ca-memory
Unit 3 ca-memory
BBDITM LUCKNOW
 
Unit 2 ca- control unit
Unit 2 ca- control unitUnit 2 ca- control unit
Unit 2 ca- control unit
BBDITM LUCKNOW
 
Unit 1 ca-introduction
Unit 1 ca-introductionUnit 1 ca-introduction
Unit 1 ca-introduction
BBDITM LUCKNOW
 
Yacc
YaccYacc
Lex
LexLex
Passescd
PassescdPassescd
Passescd
BBDITM LUCKNOW
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
BBDITM LUCKNOW
 
Compiler unit 5
Compiler  unit 5Compiler  unit 5
Compiler unit 5
BBDITM LUCKNOW
 
Cspc final
Cspc finalCspc final
Cspc final
BBDITM LUCKNOW
 
Validation based protocol
Validation based protocolValidation based protocol
Validation based protocol
BBDITM LUCKNOW
 

More from BBDITM LUCKNOW (17)

Unit 5 cspc
Unit 5 cspcUnit 5 cspc
Unit 5 cspc
 
Unit 4 cspc
Unit 4 cspcUnit 4 cspc
Unit 4 cspc
 
Unit3 cspc
Unit3 cspcUnit3 cspc
Unit3 cspc
 
Cse ppt 2018
Cse ppt 2018Cse ppt 2018
Cse ppt 2018
 
Binary system ppt
Binary system pptBinary system ppt
Binary system ppt
 
Unit 4 ca-input-output
Unit 4 ca-input-outputUnit 4 ca-input-output
Unit 4 ca-input-output
 
Unit 3 ca-memory
Unit 3 ca-memoryUnit 3 ca-memory
Unit 3 ca-memory
 
Unit 2 ca- control unit
Unit 2 ca- control unitUnit 2 ca- control unit
Unit 2 ca- control unit
 
Unit 1 ca-introduction
Unit 1 ca-introductionUnit 1 ca-introduction
Unit 1 ca-introduction
 
Yacc
YaccYacc
Yacc
 
Lex
LexLex
Lex
 
Passescd
PassescdPassescd
Passescd
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
 
Compiler unit 5
Compiler  unit 5Compiler  unit 5
Compiler unit 5
 
Cspc final
Cspc finalCspc final
Cspc final
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
Validation based protocol
Validation based protocolValidation based protocol
Validation based protocol
 

Recently uploaded

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 

Bnf and ambiquity

  • 2. BNF-Backus Naur Form • Backus normal form (BNF) is a notation technique for context-free grammars. • It is often used to describe the syntax of languages used in computing. • Such as computer programming languages, document formats, instruction sets and communication protocols. • They are applied wherever exact descriptions of languages are needed. • John Backus, a programming language designer at IBM, proposed a metalanguage of "metalinguistic formulas" to describe the syntax of the new programming language IAL, known today as ALGOL 58 (1959). His notation was first used in the ALGOL 60 report. • It is used to formally define the grammar of a language. 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 2
  • 3. Contd….. • It is a formal mathematical way to describe a language. • It is used to describe the syntax of the programming languages. • It is a way of defining syntax. • It consists of…..  a set of terminal symbols  a set of non-terminal symbols  a set of production rules of the form  Left - Hand- Side ::= Right- Hand- Side  where the LHS is a non-terminal symbol & the RHS is a sequence of symbols (terminals or non-terminals).  The meaning of the production rule is that the non-terminal on the LHS may be replaced by the expression on the RHS. 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 3
  • 4. Example:-Write a BNF grammar for the language of University of Lucknow course codes. • Example sentences: • CSI3125 • MAT2743 • PHY1200 • CHE6581 • CSI9999 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 4
  • 5. Solution: • <coursecode> ::= <acadunit> <coursenumber> • <acadunit> ::= <letter> <letter> <letter> • <coursenumber> ::= <year> <semesters> <digit> <digit> • <year> ::= <ugrad> | <grad> • <ugrad> ::= 0 | 1 | 2 | 3 | 4 • <grad> ::= 5 | 6 | 7 | 9 • <semesters> ::= <onesemester> | <twosemesters> • <onesemester> ::= <frenchone> | <englishone> | <bilingual> • <frenchone> ::= 5 | 7 • <englishone> ::= 1 | 3 • <bilingual> ::= 9 • <twosemesters> ::= <frenchtwo> | <englishtwo> • <frenchtwo> ::= 6 | 8 • <englishtwo> ::= 2 | 4 • <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 5
  • 6. Write a BNF grammar for the language of palindromes • Examples (spaces don't count!): • aba • pop • pop a pop • elu par cette crapule • a man a plan a canal panama • Solution:  <palindrome> ::= a <palindrome> a | b <palindrome> b | c <palindrome> c | d <palindrome> d | e <palindrome> e | ... |z <palindrome> z <palindrome> ::= <letter> <letter> ::= a | b | c | ... | y | z 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 6
  • 7. Ambiguity or Ambiguous Grammar • A grammar G is said to be ambiguous if it has more than one parse tree (left or right derivation) for at least one string. • C, C++, and Java have a large number of – operators and – precedence levels. • Instead of using a large grammar, we can: – Write a smaller ambiguous grammar, and – Give separate precedence and associativity. 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 7
  • 8. Contd…… • An Ambiguous Expression Grammar G1 Expr → Expr Op Expr | ( Expr ) | Integer Op → + | - | * | / | % | ** Ambiguous Parse of 5-4+3 Using Grammar G1 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 8 Exp 3+ ExpOpExp ExpOpExp - 45
  • 9. Contd…… • E → E + E • E → E – E • E → id For the string id + id – id, the above grammar generates two parse trees: 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 9