VOOZH about

URL: https://www.geeksforgeeks.org/theory-of-computation/difference-between-ambiguous-and-unambiguous-grammar/

⇱ Difference between Ambiguous and Unambiguous Grammar - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Difference between Ambiguous and Unambiguous Grammar

Last Updated : 15 Jul, 2025
Prerequisite - Context Free Grammars 1. Ambiguous Grammar : A context-free grammar is called ambiguous grammar if there exists more than one derivation tree or parse tree. Example -
S -> S + S / S * S / S / a 

2. Unambiguous Grammar : A context-free grammar is called unambiguous grammar if there exists one and only one derivation tree or parse tree. Example -
X -> AB
A -> Aa / a
B -> b 

Difference between Ambiguous and Unambiguous Grammar :
Comment

Explore