10.1. Context-Free Grammars
A context-free grammar (CFG) is a set of
recursive rewriting rules (productions) used
to generate patterns of strings.
A CFG consists of the following components:
-
a set of terminal symbols,
which are the characters of the alphabet
that appear in the strings generated by the grammar.
-
a set of nonterminal symbols,
which are placeholders for patterns of terminal symbols
that can be generated by the terminal symbols.
-
a set of productions, which are rules for
replacing (or rewriting) nonterminal symbols (on the left
side of the production) in a string with other nonterminal or
terminal symbols (on the right side of the production).
-
a start symbol,
which is a special nonterminal symbol
that appears in the initial string generated by the grammar.
To generate a string of terminal symbols from a CFG, we:
-
Begin with a string consisting of the start symbol;
-
Apply one of the productions with the start symbol on the left hand
side, replacing the start symbol with the right hand side of the production;
-
Repeat the process of selecting nonterminal symbols in the string,
and replacing them with the right hand side of some corresponding production,
until all nonterminals have been replaced by terminal symbols.
Created by unroff & hp-tools.
© by Hans-Peter Bischof. All Rights Reserved (1998).
Last modified: 27/July/98 (12:14)