How to Convert a ContextFree Grammar to Greibach
How to Convert a Context-Free Grammar to Greibach Normal Form Roger L. Costello August 16, 2014
Objective This mini-tutorial will answer these questions: 1. What is Greibach Normal Form? 2
Objective This mini-tutorial will answer these questions: 1. What is Greibach Normal Form? 2. What are the benefits of having a grammar in Greibach Normal Form? 3
Objective This mini-tutorial will answer these questions: 1. What is Greibach Normal Form? 2. What are the benefits of having a grammar in Greibach Normal Form? 3. What algorithm can be used to convert a context -free grammar to Greibach Normal Form? 4
What is Greibach Normal Form? A context-free grammar is in Greibach Normal Form if the right-hand side of each rule has one terminal followed by zero or more nonterminals: A → a. X zero or more non-terminal symbols one terminal symbol 5
Example of a grammar in Greibach Normal Form S → a. B | b. A A → a | a. S | b. AA B → b | b. S | a. BB Every right-hand side consists of exactly one terminal followed by zero or more non-terminals. 6
Example of a grammar not in Greibach Normal Form terminal at end is not allowed S → a. Bc B→b Not in Greibach Normal Form 7
What are the benefits of Greibach Normal Form? • 8
Example derivation Grammar in Greibach Normal Form S → a. B | b. A A → a | a. S | b. AA B → b | b. S | a. BB 9
Contrast to a grammar that’s not in Greibach Normal Form Grammar not in Greibach Normal Form S → a. A A→B B→C C→a 10
Greibach Normal Form is a Prefix Notation Grammar in Greibach Normal Form Expr → +AB A→ 5 B → *CD C→ 2 D→ 3 11
Benefits of Greibach Normal Form • Strings can be quickly parsed. • Expressions can be efficiently evaluated. 12
Every grammar has an equivalent grammar in Greibach normal form To every ε-free context-free grammar we can find an equivalent grammar in Greibach normal form. 13
Grammar and its equivalent Greibach Normal Form grammar S → a. Bc B→b convert Not Greibach Normal Form S → a. BC B→b C→c Greibach Normal Form 14
Grammar and its equivalent Greibach Normal Form grammar S → Bc B→b convert Not Greibach Normal Form S → b. C C→c Greibach Normal Form 15
Algorithm • We have seen a couple simple examples of converting grammars to Greibach Normal Form. • They didn’t reveal a systematic approach to doing the conversion. • The following slides show a systematic approach (i. e. , algorithm) for doing the conversion. 16
But first … Before we examine the algorithm, we need to understand two concepts: 1. Chomsky Normal Form 2. Left-recursive rules 17
Chomsky Normal Form • We will see that the algorithm requires the grammar be converted to Chomsky Normal Form. • A context-free grammar is in Chomsky Normal Form if each rule has one of these forms: 1. X → a 2. X → YZ • That is, the right-hand side is either a single terminal or two non-terminals. See my tutorial on how to convert a context-free grammar to Chomsky normal form: http: //xfront. com/formal-languages/Transforming-Context-Free-Grammars-to 18 Chomsky-Normal-Form. pptx
Left-recursive rules • The algorithm requires that the grammar have no left-recursive rules. • This is a left-recursive rule: Ak → Akα | β • The alternative (β) allows a derivation to “break out of” the recursion. • Every left-recursive rule must have an alternative (β) that allows breaking out of the recursion. 19
Algorithm to eliminate left-recursion • Let’s see how to eliminate the left-recursion in this rule: Ak → Akα | β • The rule generates this language: βαn, n≥ 1 • To see this, look at a few derivations: 20
Eliminate left-recursion • We want to eliminate the left-recursion in this rule: Ak → Akα | β • And we know the rule produces βαn • We can easily generate αn with this rule: An+1 → αAn+1 | α (Assume the grammar has “n” rules. So An+1 is a new rule that we just created. ) 21
How to eliminate left-recursion • The language βαn can, as we’ve seen, be generated using a left-recursive rule: A k → A kα | β • But the language can also be generated using these rules: Ak → βAn+1 → αAn+1 | α • With those two rules we have eliminated the left recursion. 22
Multiple left-recursive alternatives • Of course, Ak may have multiple alternatives that are left-recursive: A k → A kα 1 | A kα 2 | … | A kαr • And Ak may have multiple other alternatives: A k → β 1 | β 2 | … | βs • So Ak may generate: – β 1 followed by a string X: β 1 X … – βs followed by a string X: βsα X={α 1, …, αr}+ 23
Rule to generate {α 1, …, αr}+ We need rules to generate a string X: An+1 → αi i = 1. . r An+1 → αi An+1 i = 1. . r 24
Rule to generate {α 1, …, αr}+ And we need a rule to generate β 1 An+1, …, βs. An+1 : Ak → βi An+1 i = 1. . s 25
Beautiful definition of how to eliminate left-recursion • Replace this left-recursive rule: A k → A k α 1 | A k α 2 | … | A k α r | β 1 | β 2 | … | βs • By these rules: Ak → βi An+1 i = 1. . s An+1 → αi i = 1. . r An+1 → αi An+1 i = 1. . r 26
Here’s the algorithm to convert a grammar to Greibach Normal Form • First, convert the grammar rules to Chomsky Normal Form. After doing so all the rules are in one of these forms: 1. 2. Ai → a, where “a” is a terminal symbol A i → A j. A k The first form is in Greibach Normal Form, the second isn’t. • Then, order the rules followed by substitution: – Convert the rules to ascending order: each rule is then of the form: Ai → Ai+m. X – After ordering, the highest rule will be in Greibach Normal Form: An → a. X. The next-to-highest rule will depend on the highest-rule: An-1 → An. Y. Substitute An with its rhs: An-1 → a. XY. Now that rule is in Greibach Normal Form. Continue down the rules, doing the substitution. rhs = right-hand side 27
Apply the Algorithm to this Grammar Convert this grammar, G, to Greibach Normal Form: S → Ab A → a. S A→a First, what language does G generate? Answer: L(G) = anbn Let’s derive a couple sentences to convince ourselves: 28
Step 1 Change the names of the non-terminal symbols to Ai S → Ab A → a. S A→a Change S to A 1, A to A 2 A 1 → A 2 b A 2 → a. A 1 A 2 → a 29
Step 2 Convert the grammar to Chomsky Normal Form. A 1 → A 2 b A 2 → a. A 1 A 2 → a A 1 → A 2 A 3 A 2 → A 4 A 1 A 2 → a A 3 → b A 4 → a Chomsky Normal Form 30
Step 3 Modify the rules so that the non-terminals are in ascending order. By “ascending order” we mean: if Ai → Aj. X is a rule, then i < j 31
kth rule not in ascending order Suppose the first k-1 rules are in ascending order but the kth rule is not. Thus, Ak → Aj. X is a rule and k ≥ j. 32
2 cases • We want to put this rule Ak → Aj. X into ascending order. • We must deal with two cases: 1. k > j 2. k = j (left-recursive rule) 33
Case 1: k > j A k → A j. X Replace this with the rhs of the rule(s) for Aj. If the resulting rule(s) is still not in ascending order, continue replacing until it is in ascending order. 34
Example These rules are in ascending order But this is not in ascending order … A 7 → A 10 U A 7 → A 8 X A 8 → A 15 Y A 9 → A 7 Z Replace this with the rhs of A 7 … A 7 → A 10 U A 7 → A 8 X A 8 → A 15 Y A 9 → A 10 UZ A 9 → A 8 XZ Now replace this with the rhs of A 8. Repeat until A 9 is in ascending order. 35
Beautiful definition of how to modify Ak → Aj. X, k > j • Let Aj be this rule: A j → Y 1 | … | Y m • Replace the rule Ak → Aj. X by these rules: Ak → Yi. X i = 0. . m • Each Yi begins with either a terminal symbol or some Am where j < m. • Recursively repeat the substitution for each Yi that begins with Am and k > m. 36
Avoid getting into a loop! … A 7 → A 7 U A 7 → A 8 X A 8 → A 15 Y A 9 → A 7 Z Suppose we replace A 7 with the rhs of this rule: We then have this: A 9 → A 7 UZ We’re stuck in a loop!
Process A 7 before A 9 … A 7 → A 7 U A 7 → A 8 X A 8 → A 15 Y A 9 → A 7 Z This rule is not in ascending order. Before processing A 9 we must process A 1 – A 8 (put them in ascending order). Earlier we showed how to eliminate left-recursion.
Worst Case: k-1 substitutions A 1 → A 2 X 1 A 2 → A 3 X 2 A 3 → A 4 X 3 A 4 → A 5 X 4 A 5 → A 6 X 4 A 6 → A 7 X 5 A 7 → A 8 X 6 A 8 → A 9 X 7 A 9 → A 1 X 8 Replace this with the rhs of A 1. Now we have A 9 → A 2 X 1 so replace A 2 with the rhs of A 2. Now we have A 9 → A 3 X 2 X 1 so replace A 3 … and so forth. In the worst case, for rule Ak we will need to make k-1 substitutions. 39
Apply Step 3 to our Grammar Modify the rules with k > j: A 1 → A 2 A 3 A 2 → A 4 A 1 A 2 → a A 3 → b A 4 → a Already in order: 1 < 2 and 2 < 4 40
Case 2: k = j • The grammar may have some left-recursive rules; that is, rules like this: Ak → Ak. X • We want to eliminate the left-recursion. • See the earlier slides for how to eliminate left recursion. 41
Apply Case 1 and Case 2 processing to A 1, then A 2, then … • The previous slides for Step 3 might be a bit misleading. They seem to say: “First process all rules where k > j and then process all rules where k = j. ” That is incorrect. • Start at A 1 and ensure it is in ascending order. Only after you’ve put A 1 in ascending order do you process A 2. And so forth.
Eliminate left recursion in our Grammar Replace left-recursive rules: A 1 → A 2 A 3 A 2 → A 4 A 1 A 2 → a A 3 → b A 4 → a No left-recursive rules 43
Step 4 • Let An be the highest order variable (non-terminal). • Then the rhs of An must be a terminal symbol (otherwise the rhs would be a non-terminal symbol, An → An+1 X and An+1 would be the highest order variable). • The leftmost symbol on the rhs of any rule for An-1 must be either An or a terminal symbol. If it is An then replace An with the rhs of the An rule(s). Repeat for An-2, An-3, …, A 1. After doing this we end up with rules whose rhs starts with a terminal symbol. 44
Beautiful definition of how to modify An-1 → An. X • Let An be this rule: A n → a 1 Y 1 | … | a m Y m • Let An-1 be this rule: An-1 → An. X • Replace the rule An-1 → An. X by these rules: An-1 → ai. Yi. X i = 0. . m 45
Apply Step 4 to our Grammar Replace left-most non-terminals, working from A 4 to A 1: A 1 → A 2 A 3 A 2 → A 4 A 1 A 2 → a A 3 → b A 4 → a Replace A 4 by a A 1 → A 2 A 3 A 2 → a. A 1 A 2 → a A 3 → b A 4 → a Replace A 2 by a. A 1 Repl ace A 2 by a A 1 → a. A 1 A 3 A 1 → a. A 3 A 2 → a. A 1 A 2 → a A 3 → b A 4 → a 46
Step 5 Change symbol names back to their original names. A 1 → a. A 1 A 3 A 1 → a. A 3 A 2 → a. A 1 A 2 → a A 3 → b A 4 → a Change A 1 to S, A 2 to A S → a. SA 3 S → a. A 3 A → a. S A→a A 3 → b A 4 → a 47
Grammar is now in Greibach Normal Form S → Ab A → a. S A→a Not in Greibach Normal Form L(G) = anbn S → a. SA 3 S → a. A 3 A → a. S A→a A 3 → b A 4 → a Greibach Normal Form L(G) = anbn 48
Unused rules S → a. SA 3 S → a. A 3 A → a. S A→a A 3 → b A 4 → a Cannot reach these rules from the start symbol, S. So remove them. 49
Grammar without unused rules S → a. SA 3 S → a. A 3 → b Still in Greibach Normal Form 50
Verify the grammar generates anbn S → a. SA 3 S → a. A 3 → b Let’s do a couple derivations to convince ourselves that it generates a nbn 51
Recap of the steps • • • Step 0: Determine the language that the grammar generates Step 1: Change the non-terminal names to Ai Step 2: Convert the grammar to Chomsky normal form Step 3 a: Modify the rules Ak → Aj. X, k > j so that the leftmost nonterminal Aj, k ≤ j Step 3 b: Eliminate left-recursion Step 4: If the leftmost symbol on the rhs of rule An-1 is An, replace that An with the rhs of the An rules. Then do Step 4 for An-2. Repeat until at A 1. Step 5: Change the non-terminal names back to their original names. Step 6: Remove unused rules. Step 7: Verify that the new grammar generates the same language as the original language. 52
Minimize work Step 1 says: Change the non-terminal names to Ai That is just another way of saying that we are to give the symbol names an ordering. Choose the ordering wisely as it can impact the amount of work needed to do the conversion. 53
Good ordering for this grammar? S → AB A→a B→b Change S to A 1 A to A 2, B to A 3 A 1 → A 2 A 3 A 2 → a A 3 → b Change S to A 3 A to A 2, B to A 1 A 3 → A 2 A 1 A 2 → a A 1 → b 54
Compare the orderings A 1 → A 2 A 3 A 2 → a A 3 → b A 3 → A 2 A 1 A 2 → a A 1 → b This rule is in ascending order This rule is not in ascending order so we will have to work to get it into ascending order 55
Lesson Learned To minimize the amount of work needed to convert a grammar to Greibach Normal Form, assign a lower number to X and a higher number to Y if there is a rule X → Y. For example, change X to A 1 and Y to A 2. 56
Convert this grammar For the following grammar find an equivalent grammar in Greibach Normal Form : S → S + A A → AB S→A A→B B → (S) B→a B→b B→c 57
Step 0 • Determine the language that the grammar generates S → S + A A → AB S→A A→B B → (S) B→a B→b B→c • The grammar generates the language containing simple arithmetic expressions with addition and multiplication (in the guise of concatenation) 58
Derive a + bc + b S → S + A A → AB S→A A→B B → (S) B→a B→b B→c a + bc + b is generated by: S →S+A →S+b →S+A+b → S + AB + b → S + Ac + b → S + Bc + b → S + bc + b → A + bc + b → B + bc + b → a + bc + b 59
Step 1 Change the non-terminal names to Ai S→S+A S→A A → AB A→B B → (S) B→a B→b B→c Change S to A 1, A to A 2, B to A 3 A 1 → A 1 + A 2 A 1 → A 2 A 3 → (A 1) A 3 → b A 2 → A 3 → a A 3 → c 60
Step 2 Convert the grammar to Chomsky normal form See next slide 61
Convert the grammar to Chomsky normal form: A 1 → A 1 + A 2 → A 2 A 3 → (A 1) A 3 → b A 1 → A 2 → A 3 → a A 3 → c A 1 → A 1 A 4 A 2 A 1 → A 2 A 4 → + A 2 → A 2 A 3 A 2 → A 3 → A 5 A 1 A 6 A 3 → a A 5 → ( A 6 → ) A 3 → b A 3 → c A 1 → A 1 A 7 A 1 → A 2 A 4 → + A 7 → A 4 A 2 → A 2 A 3 A 2 → A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c Continued 62
Convert the grammar to Chomsky normal form: A 1 → A 1 A 7 A 1 → A 2 A 4 → + A 7 → A 4 A 2 → A 2 A 3 A 2 → A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c A 1 → A 1 A 7 A 1 → A 2 A 4 → + A 7 → A 4 A 2 → A 2 A 3 A 2 → A 5 A 8 A 2 → a A 2 → b A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c Continued 63
A 1 → A 1 A 7 A 1 → A 2 A 4 → + A 7 → A 4 A 2 → A 2 A 3 A 2 → A 5 A 8 A 2 → a A 2 → b A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c A 1 → A 1 A 7 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → A 4 A 2 → A 2 A 3 A 2 → A 5 A 8 A 2 → a A 2 → b A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c Now it’s in Chomsky Normal Form 64
Step 3 Process the rules, from lowest to highest, putting them into ascending order A 1 → A 1 A 7 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → A 4 A 2 → A 2 A 3 A 2 → A 5 A 8 A 2 → a A 2 → b A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c 65
A 1 → A 1 A 7 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → A 4 A 2 → A 2 A 3 A 2 → A 5 A 8 A 2 → a A 2 → b A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → A 4 A 2 A 9 → A 7 A 9 A 2 → A 2 A 3 A 2 → A 5 A 8 A 2 → a A 2 → b A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c 66
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → A 4 A 2 A 9 → A 7 A 9 A 2 → A 2 A 3 A 2 → A 5 A 8 A 2 → a A 2 → b A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → A 4 A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c 67
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → A 4 A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c 68
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 1 A 6 A 3 → b A 3 → c A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → a A 5 → ( A 6 → ) A 8 → A 2 A 3 A 6 A 8 → A 5 A 8 A 6 A 8 → A 2 A 6 A 8 → A 5 A 6 A 8 → a. A 6 A 8 → b. A 6 A 3 → b A 3 → c 69
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → A 5 A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → A 5 A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → A 5 A 8 A 6 A 8 → A 2 A 6 A 8 → A 5 A 6 A 8 → a. A 6 A 8 → b. A 6 70
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → A 5 A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → A 5 A 8 A 6 A 8 → A 2 A 6 A 8 → A 5 A 6 A 8 → a. A 6 A 8 → b. A 6 71
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → A 5 A 8 A 6 A 8 → A 2 A 6 A 8 → A 5 A 6 A 8 → a. A 6 A 8 → b. A 6 72
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → A 5 A 6 A 8 → a. A 6 A 8 → b. A 6 73
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 74
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 75
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → A 7 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 76
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → A 5 A 8 A 10 → a A 10 → b A 10 → c A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 77
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → (A 8 A 10 → a A 10 → b A 10 → c A 10 → A 3 A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 78
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → (A 8 A 10 → a A 10 → b A 10 → c A 10 → A 5 A 8 A 10 → a. A 10 → b. A 10 → c. A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 79
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → (A 8 A 10 → a A 10 → b A 10 → c A 10 → (A 8 A 10 → a. A 10 → b. A 10 → c. A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 Done! Every rule is in ascending order. We started at A 1 and worked our way to A 10. Wow! 80
Step 4 Process the rules, from A 10 to A 1, putting them into Greibach Normal Form 81
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → (A 8 A 10 → a A 10 → b A 10 → c A 10 → (A 8 A 10 → a. A 10 → b. A 10 → c. A 10 A 3 → A 5 A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 The rules A 10 - A 4 are already in Greibach Normal Form so our starting point is A 3. 82
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → A 5 A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → (A 8 A 10 → a A 10 → b A 10 → c A 10 → (A 8 A 10 → a. A 10 → b. A 10 → c. A 10 A 3 → (A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 83
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → (A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → A 5 A 8 A 2 → a A 2 → b A 10 → (A 8 A 10 → a A 10 → b A 10 → c A 10 → (A 8 A 10 → a. A 10 → b. A 10 → c. A 10 A 3 → (A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 84
A 1 → A 2 A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → (A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → (A 8 A 2 → a A 2 → b A 10 → (A 8 A 10 → a A 10 → b A 10 → c A 10 → (A 8 A 10 → a. A 10 → b. A 10 → c. A 10 A 3 → (A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 85
A 1 → (A 8 A 10 A 3 A 9 A 1 → a. A 10 A 3 A 9 A 1 → b. A 10 A 3 A 9 A 1 → (A 8 A 3 A 9 A 1 → a. A 3 A 9 A 1 → b. A 3 A 9 A 1 → A 5 A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → (A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → (A 8 A 2 → a A 2 → b A 10 → (A 8 A 10 → a A 10 → b A 10 → c A 10 → (A 8 A 10 → a. A 10 → b. A 10 → c. A 10 A 3 → (A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 86
A 1 → (A 8 A 10 A 3 A 9 A 1 → a. A 10 A 3 A 9 A 1 → b. A 10 A 3 A 9 A 1 → (A 8 A 3 A 9 A 1 → a. A 3 A 9 A 1 → b. A 3 A 9 A 1 → (A 8 A 9 A 1 → A 2 A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → (A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → (A 8 A 2 → a A 2 → b A 10 → (A 8 A 10 → a A 10 → b A 10 → c A 10 → (A 8 A 10 → a. A 10 → b. A 10 → c. A 10 A 3 → (A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 87
A 1 → (A 8 A 10 A 3 A 9 A 1 → a. A 10 A 3 A 9 A 1 → b. A 10 A 3 A 9 A 1 → (A 8 A 3 A 9 A 1 → a. A 3 A 9 A 1 → b. A 3 A 9 A 1 → (A 8 A 10 A 3 A 1 → a. A 10 A 3 A 1 → b. A 10 A 3 A 1 → (A 8 A 3 A 1 → a. A 3 A 1 → b. A 3 A 1 → A 5 A 8 A 1 → a A 1 → b A 4 → + A 7 → +A 2 A 9 → +A 2 A 9 A 2 → (A 8 A 10 A 2 → a. A 10 A 2 → b. A 10 A 2 → (A 8 A 2 → a A 2 → b A 10 → (A 8 A 10 → a A 10 → b A 10 → c A 10 → (A 8 A 10 → a. A 10 → b. A 10 → c. A 10 A 3 → (A 8 A 3 → b A 3 → a A 3 → c A 5 → ( A 6 → ) A 8 → (A 8 A 10 A 3 A 6 A 8 → a. A 10 A 3 A 6 A 8 → b. A 10 A 3 A 6 A 8 → (A 8 A 3 A 6 A 8 → a. A 3 A 6 A 8 → b. A 3 A 6 A 8 → (A 8 A 6 A 8 → A 2 A 6 A 8 → (A 6 A 8 → a. A 6 A 8 → b. A 6 88
A 1 → (A 8 A 10 A 3 A 9 A 2 → (A 8 A 10 A 3 → (A 8 A 3 → b A 1 → a. A 10 A 3 A 9 A 2 → a. A 10 A 3 → a A 3 → c A 1 → b. A 10 A 3 A 9 A 2 → b. A 10 A 5 → ( A 1 → (A 8 A 3 A 9 A 2 → (A 8 A 6 → ) A 1 → a. A 3 A 9 A 2 → a A 8 → (A 8 A 10 A 3 A 6 A 1 → b. A 3 A 9 A 2 → b A 8 → a. A 10 A 3 A 6 A 1 → (A 8 A 9 A 10 → (A 8 → b. A 10 A 3 A 6 A 1 → (A 8 A 10 A 3 A 10 → a A 8 → (A 8 A 3 A 6 A 1 → a. A 10 A 3 A 10 → b A 8 → a. A 3 A 6 A 1 → b. A 10 A 3 A 10 → c A 8 → b. A 3 A 6 A 1 → (A 8 A 3 A 10 → (A 8 A 10 A 8 → (A 8 A 6 A 1 → a. A 3 A 10 → a. A 10 A 8 → A 2 A 6 A 1 → b. A 3 A 10 → b. A 10 A 8 → (A 6 A 1 → (A 8 A 10 → c. A 10 A 8 → a. A 6 A 1 → a A 8 → b. A 6 A 1 → b A 4 → + A 7 → +A 2 All the rules are now in Greibach Normal Form! A 9 → +A 2 A 9 89
- Slides: 89