140 likes | 269 Views
Pushdown Automata – Simplifying the Grammar. Lecture 20 Section 2.2 Fri, Oct 5, 2007. The Grammar Rules. We now have the grammar rules A pp A pp A pp A pq A pp A pq A pq A pq A qq A pr A pp A pr A pr A pq A qr A pr A pr A rr A qq A qq A qq. The Grammar Rules.
E N D
Pushdown Automata – Simplifying the Grammar Lecture 20 Section 2.2 Fri, Oct 5, 2007
The Grammar Rules • We now have the grammar rules • AppAppApp • ApqAppApq • ApqApqAqq • AprAppApr • AprApqAqr • AprAprArr • AqqAqqAqq
The Grammar Rules • AqrAqqAqr • AqrAqrArr • ArrArrArr • AprAqq • AqqaAqqb • App • Aqq • Arr
The Grammar • The start symbol is Apr.
Simplifying the Grammar • We may simplify these grammar rules considerably. • Eliminate any rule involving a variable that never appears on the left. • Eliminate any rule involving a variable, other than the start symbol, that never appears on the right.
Simplifying the Grammar • Eliminate any rule involving a variable that is purely recursive. • Eliminate any unnecessary unit rules. • Use common sense to eliminate any other rules that are useless.
Simplifying the Grammar • The grammar rules are reduced to • AppAppApp | • AprAppApr | AprArr | Aqq • AqqAqqAqq | aAqqb | • ArrArrArr |
Simplifying the Grammar • Then we notice that the rules • AppAppApp | • ArrArrArr | are useless since the only other choice for App and Arr is . • We should eliminate them and replace App and Arr with everywhere they occur.
Simplifying the Grammar • Now the grammar rules are reduced to • AprApr | Apr | Aqq • AqqAqqAqq | aAqqb |
Simplifying the Grammar • Now it is obvious that the rule • AprApr is pointless, so eliminate it. • We now have • AprAqq • AqqAqqAqq | aAqqb |
Simplifying the Grammar • Now it is obvious that the unit rule • AprAqq serves no purpose. • Eliminate it, making Aqq the new start symbol.
Simplifying the Grammar • We now have • AqqAqqAqq | aAqqb | or, more simply, • SSS | aSb |
a,; a b, a; , ; , ; $ , $; p q r s Exercise • Find a context-free grammar for the language of the PDA
Exercise • Find a context-free grammar for the language of the PDA (,; ( ),(; a, ; , ; $ , $; p q r s +, ;