140 likes | 280 Views
This lecture covers the process of simplifying grammar rules for pushdown automata (PDA). It begins with a comprehensive breakdown of the original grammar rules, including variables like App, Apr, Aqq, and Arr. The lecture outlines steps to eliminate redundant rules, unnecessary variables, and purely recursive rules. By employing common sense and systematic elimination, the grammar is significantly reduced. The final simplified rules demonstrate a more efficient structure for context-free grammar, paving the way for clearer PDA language representation.
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 +, ;