Context-free Grammars and Derivations
Learn about context-free grammar and look at some examples.
We'll cover the following
Let’s formally define context-free grammar (CFG).
Context-free grammar
A context-free grammar is a formal grammar consisting of the following:
- A set of variables (i.e., a nonterminal alphabet), , one of which is a start variable.
- An alphabet, , of terminal symbols.
- A set of production rules of the form , where and , a string of terminals and/or variables.
Let’s look at some illustrations of CFGs for some of the languages.
Examples of CFGs
The following CFG generates the language :
Get hands-on with 1400+ tech skills courses.