Page 1
Wink Notes
B.Tech CSE — 4th Semester
Theory of Automata and Formal Languages
— Unit - 3 —
1. Context-Free Grammars (CFG)
In Unit 2, we proved that regular languages (DFAs/REs) cannot count. They cannot handle languages with nested dependencies like .
To describe these more complex, nested languages (which form the foundation of all programming language syntax, like matching nested `{ }` brackets in C++), Noam Chomsky introduced Context-Free Grammars.
1.1 The CFG Definition
A CFG is a 4-tuple . The variables , terminals , and start symbol are the same as regular grammars. The massive power difference lies in the Production Rules .
The CFG Rule: Every production must be in the form:
Where:
- (Exactly ONE single Non-Terminal variable on the Left side).
- (The Right side can be literally ANYTHING. Any combination of terminals, non-terminals, mixed together in any order, or even the empty string ).
Because the left side is just a single isolated variable 'A', we can replace 'A' with regardless of the surrounding context. Hence, "Context-Free".