This presentation includes all the details regarding the Backus Naur Form and the Extended Backus Naur Form.For more information visit : https://www.youtube.com/watch?v=hl2NLbIaU7U&t=255s
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.
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
+