Concept:
Chomsky hierarchy classifies grammars into four types: Type 0 (Unrestricted), Type 1 (Context-Sensitive), Type 2 (Context-Free), and Type 3 (Regular).
• Context-Free Grammar (CFG): Capable of describing recursive structures.
• Programming Languages: Require nesting, such as balanced parentheses and nested loops.
Step 1: Understanding the limitations of Regular Grammars.
Regular grammars cannot handle "nesting" or "matching" structures.
They cannot verify if every opening brace has a corresponding closing brace.
Step 2: Matching CFG to language syntax.
Most syntax in C, Java, or Python is defined by "Context-Free" rules.
Backus-Naur Form (BNF), used to specify language standards, is a notation for CFG.
Step 3: Identifying the role in compilers.
The "Parser" stage of a compiler uses a CFG to build a Parse Tree.
This tree represents the logical structure of the source code.