Sei sulla pagina 1di 3

Derivation Graphs

Derivations of sentential forms in Type 0 grammars can be displayed by derivation , or parse, graphs. Each derivation graph is a rooted, ordered, acyclic, directed graph whose nodes are labeled. The label of each node is either a nonterminal symbol, a terminal symbol, or an empty string. The derivation graph that corresponds to a derivation S 1 n is defined inductively in the following manner. a. The derivation graph D0 that corresponds to S consists of a single node labeled by the start symbol S. b. If is the production rule used in the direct derivation i i+1, 0 i < n and 0 = S, then the derivation graph Di+1 that corresponds to 0 i+1 is obtained from Di by the addition of max(| |, 1) new nodes. The new nodes are labeled by the characters of , and are assigned as common successors to each of the nodes in Di that corresponds to a character in . Consequently, the leaves of the derivation graph Di+1 are labeled by i+1. Derivation graphs are also called derivation trees or parse trees when the directed graphs are trees.

Example 1.2.13 Figure 1.2.1(a) provides examples of derivation trees for derivations in the grammar of Example 1.2.7. Figure 1.2.1(b) provides examples of derivation graphs for derivations in the grammar of Example 1.2.8.

Figure 1.2.1 (a) Derivation trees. (b) Derivation graphs.

Figure 1.2.2

A derivation graph with ordering of the usage of production rules indicated with arrows.

Leftmost Derivations
A derivation 0 n is said to be a leftmost derivation if 1 is replaced before the derivation whenever the following two conditions hold. a. b. appears to the left of 2 in i, 0 i < n. 1 and 2 are replaced during the derivation in accordance with some production rules of the form 1 1 and 2 2, respectively.
1 2

in

Example 1.2.14 The derivation graph in Figure 1.2.2 indicates the order in which the production rules are used in the derivation of a3b3c3 in Example 1.2.12. The substring 1 = aB that is replaced in the seventh step of the derivation is in the same sentential form as the substring 2 = Bb that is replaced in the sixth step of the derivation. The derivation is not a leftmost derivation because 1 appears to the left of 2 while it is being replaced after 2. On the other hand, the following derivation is a leftmost derivation for a3b3c3 in G. The order in which the production rules are used is similar to that indicated in Figure 1.2.2. The only difference is that the indices 6 and 7 should be interchanged. a a aaB aa aa aaa c B cc cc bccc ccc ccc

aaa bccc

Potrebbero piacerti anche