3
Most read
6
Most read
16
Most read
Topic: Ambiguous grammar & parse Tree
COURSE TITLE: THEORY OF COMPUTING
COURSE CODE: SE-234
1
Department Of Software Engineering
Ambiguous & Unambiguous Grammar
Depending on Number of Derivation Trees,
CFGs are sub-divided into 2 types:
 Ambiguous Grammars
 Unambiguous Grammars
1/3/2020Ambiguous Grammar & Parse Tree
2
The Context Free Grammars(CFGs) are
classified based on:
 Number of Derivation trees
 Number of strings
What is Ambiguous Grammar?
1/3/2020Ambiguous Grammar & Parse Tree
3
A grammar is said to be Ambiguous if
there exists two or more derivation &
parse tree for a string w.
Figure: 1
s a
s
s
s
a s
aa
a
What is Unambiguous Grammar?
1/3/2020Ambiguous Grammar & Parse Tree
4
A grammar can be unambiguous if the grammar does not contain more than one
leftmost derivation or more than one rightmost derivation or more than one parse
tree for the given input string.
b x
b
x
x
b
1/3/2020Ambiguous Grammar & Parse Tree
5
G = (V,T,P,S) is a CFG is said to be ambiguous if and only if
there exist a string in T* that has more than one parse tree.
where,
• V = finite set of variables.
• T = finite set of terminals.
• P = finite set of productions of the form, A → α, where A is
a variable and α ∈ (V ∪ T)*
• S = designated variable called the start symbol.
Definition of ambiguous & unambiguous
grammar:
1/3/2020Ambiguous Grammar & Parse Tree
6Example - 1
Check the grammar G with production rules −
X → X+X | X*X |X| a
is ambiguous or not?
Let’s find out the derivation tree for the string "a+a*a". It has two leftmost
derivations.
Derivation – 1
X → X*X
→ X+X*X [X→X+X]
→ a+X*X [X →X*X]
→ a+a*X [X→a]
→ a+a*a
Derivation – 2
X → X+X
→ a+X [X→a]
→ a+X*X [X →X*X]
→ a+a*X [X→a]
→ a+a*a
1/3/2020Ambiguous Grammar & Parse Tree
7
Figure: 3Figure: 2
Parse Tree - 1 Parse Tree - 2
Since there are two different parse trees for a single
string "a+a*a",
So the grammar G is ambiguous.
x +
x
x
x
a x
aa
*
x *
x
x
x
+x
a a
a
1/3/2020Ambiguous Grammar & Parse Tree
8Example - 2
The grammar G is with production rules-
S → T
T → 01
T → T T
From the above grammar, Check the ambiguity by the derivation &
parse tree for string “010101”.
Derivation – 1
S → T
→ TT [T→TT]
→ TTT [T→TT]
→ 01TT [T→01]
→ 0101T [T→01]
→ 010101 [T→01]
Derivation – 2
S → T
→ TT [T→TT]
→ TTT [T→TT]
→ TT01 [T→01]
→ T0101 [T→01]
→ 010101 [T→01]
1/3/2020Ambiguous Grammar & Parse Tree
9
Figure: 3Figure: 2
Parse Tree - 1 Parse Tree - 2
S
T
T T
T
T
0 1 0 1
T
0 1
S
T
T T
T
T
0 1 0 1
T
0 1
The grammar has two or more derivation & parse tree. So this is also an Ambiguous.
1/3/2020Ambiguous Grammar & Parse Tree
10
Example - 3
Given a context-free grammar G with start symbol S, terminal symbols T and
productions P, the language L(G) that G generates is defined to be the set of strings
of terminal symbols that can be obtained by derivation from S using the productions
P, i.e., the set {w ∈ T ∗ | S ⇒ w}.
T → R
T → aTc
R → ∈
R → RbR
Check that the grammar is Ambiguous or Unambiguous for the string ‘aabbbcc’ ?
1/3/2020Ambiguous Grammar & Parse Tree
11
T ⇒ aTc
⇒ aaTcc [T ⇒ aTc]
⇒ aaRcc [T ⇒ R]
⇒ aaRbRcc [R ⇒ RbR]
⇒ aaRbRbRcc [R ⇒ RbR]
⇒ aaRbRbRbRcc [R ⇒ RbR]
⇒ aabRbRbRcc [R ⇒ ∈]
⇒ aabbRbRcc [R ⇒ ∈]
⇒ aabbbRcc [R ⇒ ∈]
⇒ aabbbcc [R ⇒ ∈]
Leftmost Derivation of the string ‘aabbbcc’
T ⇒ aTc
⇒ aaTcc [T ⇒ aTc]
⇒ aaRcc [T ⇒ R]
⇒ aaRbRcc [R ⇒ RbR]
⇒ aaRbRbRcc [R ⇒ RbR]
⇒ aaRbRbRbRcc [R ⇒ RbR]
⇒ aaRbRbRbcc [R ⇒ ∈]
⇒ aaRbRbbcc [R ⇒ ∈]
⇒ aaRbbbcc [R ⇒ ∈]
⇒ aabbbcc [R ⇒ ∈]
Rightmost derivation of the string ‘aabbbcc’
1/3/2020Ambiguous Grammar & Parse Tree
12
b R
b
T
R R
R
∈
R
c
a
a T
T c
b R
∈
∈∈
b
R
b
T
R R
R
∈
R
c
a
a T
T c
∈
R
b
∈
∈
Parse Tree-1 Parse Tree-2
R
R
1/3/2020Ambiguous Grammar & Parse Tree
13
Example - 4
Consider VN = {S, E}, VT = {if, then, else} and a grammar G = (VT,VN, S, P) such that the
following grammar
S → if E then S | if E then S else S
Are productions of G. Then the string
W → if E then if E then S else S
Now check the ambiguity.
Derivation – 1
S → if E then S else S
→ if E then if E then S else S
Derivation – 2
S → if E then S
→ if E then if E then S else S
1/3/2020Ambiguous Grammar & Parse Tree
14S
Eif then S else S
if E Sthen
S
Eif then S
else Sif E Sthen
Parse Tree-1
Parse Tree-2
The string has two derivation trees. So it is ambiguous.
1/3/2020Ambiguous Grammar & Parse Tree
15
Consider the following grammar- S → aS | ∈
The language generated by this grammar-
L = { an , n>=0 } or a*
Example - 5
Let us consider a string w = “aaa”.
First Derivation-
S → aS
→ aaS [S → aS]
→ aaaS [S → aS]
→ aaa∈ [S → ∈ ]
→ aaa
Second Derivation-
S → aS
→ aaS [S → aS]
→ aaaS [S → aS]
→ aaa∈ [S → ∈]
→ aaa
Figure - 4
Parse Tree
S
Sa
a S
Sa
∈
 Here first derivation and second derivation are exactly same.
So, this is an example of an unambiguous grammar.
1/3/2020Ambiguous Grammar & Parse Tree
16Example - 6
The following Grammar generates prefix expressions with
operands x and y and binary operators +, -, and *:
E → +EE | *EE | -EE | x | y
Now find leftmost and rightmost derivations and derivation
tree for the string ‘+*-xyxy’.
+ E E
E
y
* E E
EE-
yx
x
Parse Tree:
E → +EE
→ +*EEE [E → *EE]
→+*-EEEE [E → -EE]
→+*-xEEE [E → x]
→+*-xyEE [E → y]
→+*-xyxE [E → x]
→+*-xyxy [E → y]
Left Derrivation:
In this grammar, there is no more derivation and parse tree.
So this is also unambiguous.
1/3/2020Ambiguous Grammar & Parse Tree
17Example - 7
Consider the given grammar
S → S+S | S-S | S*S | S/S | (S) | x | y | z
is the productions of G. Then for the string W → (x+y)*x-z*y/(x+x) ; check the ambiguity.
S → S*S
→ (S)*S
→ (S+S)*S
→ (x+y)*S
→ (x+y)*S-S
→ (x+y)*x-S
→ (x+y)*x-S*S
→ (x+y)*x-z*S
→ (x+y)*x-z*S/S
→ (x+y)*x-z*y/S
→ (x+y)*x-z*y/(S)
→ (x+y)*x-z*y/(S+S)
→ (x+y)*x-z*y/(x+x)
S → S/S
→ S/(S)
→ S/(S+S)
→ S/(x+x)
→ S*S/(x+x)
→ S*y/(x+x)
→ S-S*y/(x+x)
→ S-z*y/(x+x)
→ S*S-z*y/(x+x)
→ S*x-z*y/(x+x)
→ (S)*x-z*y/(x+x)
→ (S+S)*x-z*y/(x+x)
→ (x+y)*x-z*y/(x+x)
Derivation – 1 Derivation – 2
In this grammar, there are more than two derivation and parse tree. So this is an ambiguous.
1/3/2020Ambiguous Grammar & Parse Tree
18
Reference from:
 Basics of Compiler Design - by Torben Ægidius Mogensen
 Introduction to the Theory of Computation_3rd Edition – by Michael Sipser
 Introduction to Automata Theory, Language, and Computation – by John E. Hopcroft
 https://www.javatpoint.com/automata-ambiguity-in-grammar
 https://www.geeksforgeeks.org/ambiguous-grammar/
1/3/2020Ambiguous Grammar & Parse Tree
19
1/3/2020Ambiguous Grammar & Parse Tree
20

More Related Content

PPTX
Specification-of-tokens
PPTX
Compiler design syntax analysis
PPT
Context free grammars
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
PPTX
Recognition-of-tokens
PPTX
CONTEXT FREE GRAMMAR
PPTX
Automata theory - CFG and normal forms
PDF
COMPILER DESIGN- Syntax Directed Translation
Specification-of-tokens
Compiler design syntax analysis
Context free grammars
Type Checking(Compiler Design) #ShareThisIfYouLike
Recognition-of-tokens
CONTEXT FREE GRAMMAR
Automata theory - CFG and normal forms
COMPILER DESIGN- Syntax Directed Translation

What's hot (20)

PPTX
Introduction TO Finite Automata
PPTX
Lexical analyzer generator lex
PPTX
Context free grammar
PPT
Regular expressions-Theory of computation
PPTX
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
PPTX
Regular expressions
PPTX
Regular Expression to Finite Automata
PPTX
Lexical analysis - Compiler Design
PPT
Intermediate code generation (Compiler Design)
PPT
Parsing
PPTX
2.5 ambiguity in context free grammars
PPT
Lecture 3,4
PPT
Ll(1) Parser in Compilers
PPT
1.Role lexical Analyzer
PPT
Top down parsing
PPTX
Asymptotic notations
PPTX
Lefmost rightmost TOC.pptx
PPTX
Automata theory -Conversion of ε nfa to nfa
PPT
Lecture 3,4
PDF
Automata theory
Introduction TO Finite Automata
Lexical analyzer generator lex
Context free grammar
Regular expressions-Theory of computation
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
Regular expressions
Regular Expression to Finite Automata
Lexical analysis - Compiler Design
Intermediate code generation (Compiler Design)
Parsing
2.5 ambiguity in context free grammars
Lecture 3,4
Ll(1) Parser in Compilers
1.Role lexical Analyzer
Top down parsing
Asymptotic notations
Lefmost rightmost TOC.pptx
Automata theory -Conversion of ε nfa to nfa
Lecture 3,4
Automata theory
Ad

Similar to Ambiguous & Unambiguous Grammar (20)

PPTX
L11 context-free grammers 2.pptx parse tree
PDF
Lecture6 syntax analysis_2
PPTX
Context Free Grammar presentation 2025.pptx
PPT
Context free grammar
PPTX
6-Role of Parser, Construction of Parse Tree and Elimination of Ambiguity-06-...
DOCX
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
PPTX
Ambiguity Grammar.pptx
PPTX
Lexhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
PDF
cfl2.pdf
PDF
Syntax Analysis_73 pages notes IIIT Manipur.pdf
PPTX
4. languages and grammars
PDF
ambiguity grammar.pdf
DOCX
8-Practice problems on operator precedence parser-24-05-2023.docx
PDF
Parse Tree
PDF
syntaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pdf
PDF
Ch2_Compilers A Simple One-Pass Compiler.pdf
PPTX
Ayan Das_25300121057.pptx
PDF
3b. LMD & RMD.pdf
PPTX
Chapter3pptx__2021_12_23_22_52_54.pptx
L11 context-free grammers 2.pptx parse tree
Lecture6 syntax analysis_2
Context Free Grammar presentation 2025.pptx
Context free grammar
6-Role of Parser, Construction of Parse Tree and Elimination of Ambiguity-06-...
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
Ambiguity Grammar.pptx
Lexhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
cfl2.pdf
Syntax Analysis_73 pages notes IIIT Manipur.pdf
4. languages and grammars
ambiguity grammar.pdf
8-Practice problems on operator precedence parser-24-05-2023.docx
Parse Tree
syntaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pdf
Ch2_Compilers A Simple One-Pass Compiler.pdf
Ayan Das_25300121057.pptx
3b. LMD & RMD.pdf
Chapter3pptx__2021_12_23_22_52_54.pptx
Ad

Recently uploaded (20)

PDF
Presentation on cloud computing and ppt..
PPTX
Animal Farm powerpointpresentation- Kopie – Kopie.pptx
PDF
Books and book chapters(CITATIONS AND REFERENCING) (LORENA).pdf
PPTX
History Subject for High School_ Military Dictatorships by Slidesgo.pptx
PDF
Financial Managememt CA1 for Makaut Student
PPTX
Challenges, strengths and prospects of Pakistan in.pptx
PPTX
Knowledge Knockout ( General Knowledge Quiz )
PPTX
Brief presentation for multiple products
PDF
Community User Group Leaders_ Agentblazer Status, AI Sustainability, and Work...
PDF
Unit 3 Ratio Analysis.pdf xdvdssdfsdfsd sdf
PPTX
TG Hospitality workshop Vietnam (1).pptx
PPTX
Pharmaceutical industry and drugdevelopment.pptx
PDF
Pitch Style Data Report Template Preview
PPTX
Training for Village Watershed Volunteers.pptx
PDF
soft skills for kids in India - LearnifyU
PPT
Lessons from Presentation Zen_ how to craft your story visually
PPTX
Ulangan Harian_TEOREMA PYTHAGORAS_8.pptx
PPTX
HOW TO HANDLE THE STAGE FOR ACADEMIA AND OTHERS.pptx
PPTX
ECO VAULT AUTOMATIC DIAPER DISPENSER AND SHREDDER
Presentation on cloud computing and ppt..
Animal Farm powerpointpresentation- Kopie – Kopie.pptx
Books and book chapters(CITATIONS AND REFERENCING) (LORENA).pdf
History Subject for High School_ Military Dictatorships by Slidesgo.pptx
Financial Managememt CA1 for Makaut Student
Challenges, strengths and prospects of Pakistan in.pptx
Knowledge Knockout ( General Knowledge Quiz )
Brief presentation for multiple products
Community User Group Leaders_ Agentblazer Status, AI Sustainability, and Work...
Unit 3 Ratio Analysis.pdf xdvdssdfsdfsd sdf
TG Hospitality workshop Vietnam (1).pptx
Pharmaceutical industry and drugdevelopment.pptx
Pitch Style Data Report Template Preview
Training for Village Watershed Volunteers.pptx
soft skills for kids in India - LearnifyU
Lessons from Presentation Zen_ how to craft your story visually
Ulangan Harian_TEOREMA PYTHAGORAS_8.pptx
HOW TO HANDLE THE STAGE FOR ACADEMIA AND OTHERS.pptx
ECO VAULT AUTOMATIC DIAPER DISPENSER AND SHREDDER

Ambiguous & Unambiguous Grammar

  • 1. Topic: Ambiguous grammar & parse Tree COURSE TITLE: THEORY OF COMPUTING COURSE CODE: SE-234 1 Department Of Software Engineering
  • 2. Ambiguous & Unambiguous Grammar Depending on Number of Derivation Trees, CFGs are sub-divided into 2 types:  Ambiguous Grammars  Unambiguous Grammars 1/3/2020Ambiguous Grammar & Parse Tree 2 The Context Free Grammars(CFGs) are classified based on:  Number of Derivation trees  Number of strings
  • 3. What is Ambiguous Grammar? 1/3/2020Ambiguous Grammar & Parse Tree 3 A grammar is said to be Ambiguous if there exists two or more derivation & parse tree for a string w. Figure: 1 s a s s s a s aa a
  • 4. What is Unambiguous Grammar? 1/3/2020Ambiguous Grammar & Parse Tree 4 A grammar can be unambiguous if the grammar does not contain more than one leftmost derivation or more than one rightmost derivation or more than one parse tree for the given input string. b x b x x b
  • 5. 1/3/2020Ambiguous Grammar & Parse Tree 5 G = (V,T,P,S) is a CFG is said to be ambiguous if and only if there exist a string in T* that has more than one parse tree. where, • V = finite set of variables. • T = finite set of terminals. • P = finite set of productions of the form, A → α, where A is a variable and α ∈ (V ∪ T)* • S = designated variable called the start symbol. Definition of ambiguous & unambiguous grammar:
  • 6. 1/3/2020Ambiguous Grammar & Parse Tree 6Example - 1 Check the grammar G with production rules − X → X+X | X*X |X| a is ambiguous or not? Let’s find out the derivation tree for the string "a+a*a". It has two leftmost derivations. Derivation – 1 X → X*X → X+X*X [X→X+X] → a+X*X [X →X*X] → a+a*X [X→a] → a+a*a Derivation – 2 X → X+X → a+X [X→a] → a+X*X [X →X*X] → a+a*X [X→a] → a+a*a
  • 7. 1/3/2020Ambiguous Grammar & Parse Tree 7 Figure: 3Figure: 2 Parse Tree - 1 Parse Tree - 2 Since there are two different parse trees for a single string "a+a*a", So the grammar G is ambiguous. x + x x x a x aa * x * x x x +x a a a
  • 8. 1/3/2020Ambiguous Grammar & Parse Tree 8Example - 2 The grammar G is with production rules- S → T T → 01 T → T T From the above grammar, Check the ambiguity by the derivation & parse tree for string “010101”. Derivation – 1 S → T → TT [T→TT] → TTT [T→TT] → 01TT [T→01] → 0101T [T→01] → 010101 [T→01] Derivation – 2 S → T → TT [T→TT] → TTT [T→TT] → TT01 [T→01] → T0101 [T→01] → 010101 [T→01]
  • 9. 1/3/2020Ambiguous Grammar & Parse Tree 9 Figure: 3Figure: 2 Parse Tree - 1 Parse Tree - 2 S T T T T T 0 1 0 1 T 0 1 S T T T T T 0 1 0 1 T 0 1 The grammar has two or more derivation & parse tree. So this is also an Ambiguous.
  • 10. 1/3/2020Ambiguous Grammar & Parse Tree 10 Example - 3 Given a context-free grammar G with start symbol S, terminal symbols T and productions P, the language L(G) that G generates is defined to be the set of strings of terminal symbols that can be obtained by derivation from S using the productions P, i.e., the set {w ∈ T ∗ | S ⇒ w}. T → R T → aTc R → ∈ R → RbR Check that the grammar is Ambiguous or Unambiguous for the string ‘aabbbcc’ ?
  • 11. 1/3/2020Ambiguous Grammar & Parse Tree 11 T ⇒ aTc ⇒ aaTcc [T ⇒ aTc] ⇒ aaRcc [T ⇒ R] ⇒ aaRbRcc [R ⇒ RbR] ⇒ aaRbRbRcc [R ⇒ RbR] ⇒ aaRbRbRbRcc [R ⇒ RbR] ⇒ aabRbRbRcc [R ⇒ ∈] ⇒ aabbRbRcc [R ⇒ ∈] ⇒ aabbbRcc [R ⇒ ∈] ⇒ aabbbcc [R ⇒ ∈] Leftmost Derivation of the string ‘aabbbcc’ T ⇒ aTc ⇒ aaTcc [T ⇒ aTc] ⇒ aaRcc [T ⇒ R] ⇒ aaRbRcc [R ⇒ RbR] ⇒ aaRbRbRcc [R ⇒ RbR] ⇒ aaRbRbRbRcc [R ⇒ RbR] ⇒ aaRbRbRbcc [R ⇒ ∈] ⇒ aaRbRbbcc [R ⇒ ∈] ⇒ aaRbbbcc [R ⇒ ∈] ⇒ aabbbcc [R ⇒ ∈] Rightmost derivation of the string ‘aabbbcc’
  • 12. 1/3/2020Ambiguous Grammar & Parse Tree 12 b R b T R R R ∈ R c a a T T c b R ∈ ∈∈ b R b T R R R ∈ R c a a T T c ∈ R b ∈ ∈ Parse Tree-1 Parse Tree-2 R R
  • 13. 1/3/2020Ambiguous Grammar & Parse Tree 13 Example - 4 Consider VN = {S, E}, VT = {if, then, else} and a grammar G = (VT,VN, S, P) such that the following grammar S → if E then S | if E then S else S Are productions of G. Then the string W → if E then if E then S else S Now check the ambiguity. Derivation – 1 S → if E then S else S → if E then if E then S else S Derivation – 2 S → if E then S → if E then if E then S else S
  • 14. 1/3/2020Ambiguous Grammar & Parse Tree 14S Eif then S else S if E Sthen S Eif then S else Sif E Sthen Parse Tree-1 Parse Tree-2 The string has two derivation trees. So it is ambiguous.
  • 15. 1/3/2020Ambiguous Grammar & Parse Tree 15 Consider the following grammar- S → aS | ∈ The language generated by this grammar- L = { an , n>=0 } or a* Example - 5 Let us consider a string w = “aaa”. First Derivation- S → aS → aaS [S → aS] → aaaS [S → aS] → aaa∈ [S → ∈ ] → aaa Second Derivation- S → aS → aaS [S → aS] → aaaS [S → aS] → aaa∈ [S → ∈] → aaa Figure - 4 Parse Tree S Sa a S Sa ∈  Here first derivation and second derivation are exactly same. So, this is an example of an unambiguous grammar.
  • 16. 1/3/2020Ambiguous Grammar & Parse Tree 16Example - 6 The following Grammar generates prefix expressions with operands x and y and binary operators +, -, and *: E → +EE | *EE | -EE | x | y Now find leftmost and rightmost derivations and derivation tree for the string ‘+*-xyxy’. + E E E y * E E EE- yx x Parse Tree: E → +EE → +*EEE [E → *EE] →+*-EEEE [E → -EE] →+*-xEEE [E → x] →+*-xyEE [E → y] →+*-xyxE [E → x] →+*-xyxy [E → y] Left Derrivation: In this grammar, there is no more derivation and parse tree. So this is also unambiguous.
  • 17. 1/3/2020Ambiguous Grammar & Parse Tree 17Example - 7 Consider the given grammar S → S+S | S-S | S*S | S/S | (S) | x | y | z is the productions of G. Then for the string W → (x+y)*x-z*y/(x+x) ; check the ambiguity. S → S*S → (S)*S → (S+S)*S → (x+y)*S → (x+y)*S-S → (x+y)*x-S → (x+y)*x-S*S → (x+y)*x-z*S → (x+y)*x-z*S/S → (x+y)*x-z*y/S → (x+y)*x-z*y/(S) → (x+y)*x-z*y/(S+S) → (x+y)*x-z*y/(x+x) S → S/S → S/(S) → S/(S+S) → S/(x+x) → S*S/(x+x) → S*y/(x+x) → S-S*y/(x+x) → S-z*y/(x+x) → S*S-z*y/(x+x) → S*x-z*y/(x+x) → (S)*x-z*y/(x+x) → (S+S)*x-z*y/(x+x) → (x+y)*x-z*y/(x+x) Derivation – 1 Derivation – 2 In this grammar, there are more than two derivation and parse tree. So this is an ambiguous.
  • 18. 1/3/2020Ambiguous Grammar & Parse Tree 18 Reference from:  Basics of Compiler Design - by Torben Ægidius Mogensen  Introduction to the Theory of Computation_3rd Edition – by Michael Sipser  Introduction to Automata Theory, Language, and Computation – by John E. Hopcroft  https://www.javatpoint.com/automata-ambiguity-in-grammar  https://www.geeksforgeeks.org/ambiguous-grammar/