7.1 Context Free Grammars: 7.1.1 The Basics
7.1 Context Free Grammars: 7.1.1 The Basics
Some terminology. The is called the rewrite arrow, and the four
expressions listed above are called context free rules (you may also
see them called rewrite rules, or something similar).
Apart from the , there are two sorts of symbols in this grammar:
terminal symbols and non-terminal symbols. In the above grammar,
the terminal symbols are `a' and `b', and the non-terminal symbols are
`S', `A', and `B'. Terminal symbols never occur to the left of a rewrite
arrow. Non-terminal symbols may occur either to the right or the left of
the rewrite arrow (for example, the `S' in the above grammar occurs
both to the right and the left of in the second rule). Every context
free grammar has one special symbol, the start or sentence symbol,
which is usually written `S'. Some context free grammars also use
another special symbol, namely , for the empty string. The symbol
can only occur on the right hand side of context free rules. For
example, we could add the rule to the above grammar, but we
could not add .
S
ASB Rule 2
aSB Rule 3
aSb Rule 4
aABb Rule 1
aaBb Rule 3
aabb Rule 4
S
ASB Rule 2
ASb Rule 4
aSb Rule 3
aABb Rule 1
aAbb Rule 4
aabb Rule 3
Why are such grammars called `context free'? Because all rules
contain only one symbol on the left hand side --- and wherever we see
that symbol while doing a derivation, we are free to replace it with the
stuff on the right hand side. That is, the `context' in which a symbol on
the left hand side of a rule occurs is unimportant --- we can always use
the rule to make the rewrite while doing a derivation. (There are more
complex kinds of grammars, with more than one symbol on the left
hand side of the rewrite arrow, in which the symbols to the right and
left have to be taken into account before making a rewrite. Such
grammars can be linguistically important, but we won't study them in
this course.)
A parse tree is a finite tree all of whose interior nodes (that is, nodes
with daughters) are licensed or admitted by a grammar rule. What
does this mean? Let's look at an example:
This tree is licensed by our grammar --- that is, the presence of every
node with daughters can be justified by some rule. For example. the
top node is ok, because under the tree admissibility interpretation we
read as saying: A tree node labelled can have exactly
three daughters, labelled (reading left to right) , , and . The node
labelled A is ok, because under the tree admissibility we read the rule
as saying: A tree node labelled can have exactly one
daughter which is labelled . Similarly, all the other nodes with
daughters are `justified' or `admitted' by other rules (the terminal nodes
of the tree don't need to be justified).
If you think about it, you will see there is a close correspondence
between parse trees and derivations: every derivation corresponds to
a parse tree, and every parse tree corresponds to (maybe many)
derivations. For example, the tree above corresponds to both our
earlier derivations of `aabb'.
- Up - Next >>