Formal definition of Context-Free Grammer
Here’s the formal definition of a Context-Free Grammar (CFG). Definition A Context-Free Grammar is a 4-tuple: G = ( V , Σ , R , S ) G = (V, \Sigma, R, S) where: V V — A finite set of nonterminal symbols (or variables). Σ \Sigma — A finite set of terminal symbols , such that V ∩ Σ = ∅ V \cap \Sigma = \varnothing R R — A finite set of production rules of the form A → α A \rightarrow \alpha where A ∈ V A \in V and α ∈ ( V ∪ Σ ) ∗ \alpha \in (V \cup \Sigma)^* (that is, α \alpha is any finite string of terminals and/or nonterminals, possibly empty). S S — A distinguished element of V V , called the start symbol . ✅ Key condition that makes it “context-free” : In every production A → α A \rightarrow \alpha , the left-hand side consists of exactly one nonterminal symbol A . Characteristics of CFGs Each production’s LHS must be a single nonterminal (unlike context-sensitive grammars). They can describe nested a...