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

Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting AlgorithmsRahul Jamwal
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 
Arrays searching-sorting
Arrays searching-sortingArrays searching-sorting
Arrays searching-sortingAjharul Abedeen
 
Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortManishPrajapati78
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++Bishal Sharma
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsMohamed Loey
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structureMeherul1234
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up ParsingGerwin Ocsena
 
Chapter 09 design and analysis of algorithms
Chapter 09  design and analysis of algorithmsChapter 09  design and analysis of algorithms
Chapter 09 design and analysis of algorithmsPraveen M Jigajinni
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide shareDevashish Kumar
 

What's hot (20)

Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting Algorithms
 
COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Arrays searching-sorting
Arrays searching-sortingArrays searching-sorting
Arrays searching-sorting
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Module 11
Module 11Module 11
Module 11
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge Sort
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
BNF & EBNF
BNF & EBNFBNF & EBNF
BNF & EBNF
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Chapter 09 design and analysis of algorithms
Chapter 09  design and analysis of algorithmsChapter 09  design and analysis of algorithms
Chapter 09 design and analysis of algorithms
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 

Viewers also liked

Backus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsBackus Naur and Chomsky Normal Forms
Backus Naur and Chomsky Normal FormsAshutosh Pandey
 
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 constructionYuji Shimojo
 
Clinical Cardiology Cases
Clinical  Cardiology  CasesClinical  Cardiology  Cases
Clinical Cardiology Caseshospital
 
History of cardiology
History of cardiologyHistory of cardiology
History of cardiologyDona Mathew
 
Future of cardiology
Future of cardiologyFuture of cardiology
Future of cardiologymkocierz
 
Clinical Cardiology
Clinical CardiologyClinical Cardiology
Clinical Cardiologyhospital
 
Pediatric-Cardiology-101.ppt
Pediatric-Cardiology-101.pptPediatric-Cardiology-101.ppt
Pediatric-Cardiology-101.pptempite
 
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
 
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 SpreadsheetsJácome Cunha
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler DesignKuppusamy P
 
Constraint Grammar and Apertium
Constraint Grammar and ApertiumConstraint Grammar and Apertium
Constraint Grammar and Apertiumunhammer
 
02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptxarifaqazi2
 
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
 
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 cstechzShahbaz Ahmad
 
Contest Tips and Tricks
Contest Tips and TricksContest Tips and Tricks
Contest Tips and Tricksmbuzdalov
 

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 (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

Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 

Recently uploaded (20)

Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 

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