1. Explain context-free grammar (CFG) and its four components with the help of an example.
Ans: The context-free grammar (CFG) was developed by Chomsky in 1965. A CFG is used to specify the syntactic structure of a programming language constructs like expressions and statements. The CFG is also known as Backus-Naur Form (BNF). A CFG comprises four components, namely, nonterminals, terminals, productions, and start symbol.
The non-terminals (also known as syntactic variables) represent the set of strings in a language.
The terminals (also known as tokens) represent the symbols of the language.