Context Free Grammars (CFGs) are the backbone of Context Free Languages, providing a set of recursive rules that shape string patterns. While all regular languages can be encapsulated by CFGs, not all imaginable languages fall within its realm.
1) Classification Based on the Number of Generated Strings
A CFG is deemed non-recursive if it yields a finite set of strings, thereby becoming a non-recursive grammar.
A CFG is considered complete if it can generate an infinite array of strings, hence the term repeating grammar.
During the compilation process, the parser forms a derivation tree or a parse tree from the source code, utilizing the language’s grammar. The grammar must be devoid of ambiguity to ensure accurate parsing.
2) Classification Based on the Number of Derivation Trees
A CFG is termed clear/unambiguous if there exists only one derivation tree.
A CFG is labeled unclear/ambiguous if it can generate multiple derivation trees.
Test Series
124.8k Students
GATE Mathematics & General Aptitude (Common for All) Test Series
What is the Classification of Context Free Grammars?
Context Free Grammars (CFGs) are classified on the basis of two properties: The number of generated strings and the number of derivation trees.
What are the types of Recursive Grammars?
Recursive Grammars are further divided based on the type of recursion in the grammar: Recursive Left Grammar, Appropriate recursive grammar, and Recursive grammar in general.
What is the difference between Recursive and Non-Recursive Grammars?
A CFG is non-recursive if it produces a finite number of strings. If CFG can produce an endless amount of strings, the grammar is recursive.