!# #! + Pushdown utomata CS5 ecture Pushdown utomata where pushdown automaton is a 6tuple are finite sets is the set of states is the input alphabet is the stack alphabet is the transition function is the start state 5 is the set of accept states 6 CS5 ecture Pushdown utomata cont d t each computational step a PD does the following nondeterministically decides whether to read the next input symbol the current stack symbol; for input symbol stack symbol the choices are ; if the input or stack are empty there are fewer than choices; if it reads moves past then if from the stack; if the choice is it pops it nondeterministically selects the next state a symbol to be put on the stack according to the transition function It halts when either i there is no next move or ii no input symbols are left the current state is an accept state CS5 ecture Pushdown utomata cont d can be represented if accepts a word there exist satisfying the following conditions with as + * where ' for some + ere the stack is read from top to bottom or left to right CS5 ecture
PD Example / Design Idea Use a special symbol to mark the bottom of the stack Using wouldn t work because is always there First put onto the stack all the s preceding the s Then try to match the stacked s with the s is the top The input string is in if only if the bottom symbol when all the input symbols have been read CS5 ecture 5 Example cont d is the initial state 7 7 6 5 We use to place the on the stack to read s push them onto the stack react to the first to read s pop s from the stack react to the by going to accept state s a diagram 5 6 7 CS5 ecture 6 Example cont d s a transition table where blank means empty set Input Stack 5 6 5 5 7 6 6 denote the configuration in which the the stack word is the remaining input is et state is 5 is accepted by a path 6 5 5 5 7 6 6 CS5 ecture 7 PD Example s s is the initial state has an eual number of / 7 6 5 7 6 6 5 5 5 6 ere are omitted State is used to place on the stack is used to pop stack symbols matching a complementary input symbol to recognize when we re done is used to push unmatched s onto the stack to push unmatched s onto the stack 5 6 CS5 ecture
9 PD Example cont d 5 Example 6 6 7 CS5 ecture 9 PDs Recognize CFs Theorem Each contextfree language is recognized by a PD be produced by a Chomsky normal form grammar Proof et ; IDE Construct a PD that performs leftmost derivations step of a derivation using is implemented by popping the lefth side pushing the righth side of the rule onto the stack step using is implemented by popping the lefth side comparing the righth side to the input symbol expending that symbol CS5 ecture PD Recognize CFs cont d It has one accept state stack alphabet is s input alphabet is on the stack repeats the following until pushes a then an it halts enters the accept state If pops a stack symbol halts nondeterministically chooses a production rule If takes no action back to step pushes a then for some variables onto the stack If then a then ; if reads the next input symbol If halts CS5 ecture if S in G S S C if C in G a if a in G CS5 ecture
C C J K CFs Capture PD Theorem Every language recognized by PD is context free Proof et * be recognized by a PD We can assume has a uniue final state when it enters the state the stack is empty ** In a single move CFs Capture PD cont d s to ** divide each state involving push pop into two states one for push only the other for pop only Idea for ensuring * Modify a new stack symbol a new initial state a cleanup state either pops or pushes but not both to create a new PD to mark bottom of stack for putting on the stack for clearing the stack a new uniue accepting state which has CS5 ecture CFs Capture PD cont d The only permissible action in is to put one on the stack without reading an input symbol go to the old initial state In each state in the action of is the same except that there is an transition from each former accepting state to The goal in state is to remove stack symbols one after another to enter upon observing a becomes a pair of moves in followed by CS5 ecture D in D ab c r becomes r ab c r CS5 ecture 5 CFs Capture PD cont d satisfies * ** Now suppose is the uniue final state of / FG E GI Construct a CFG where is the initial state of Key idea For any states is a variable generating the strings that can take from to while preserving the stack Then by taking as the start state as the accept state we have a variable that generates precisely the strings accepted by thus can serve as start symbol FG CS5 ecture 6
P C OM CFs Capture PD cont d corresponds to the set of all strings FG More precisely the variable under the following conditions expended by ends with state starts with the stack height is always at least For some at the start as well as at the end precisely CS5 ecture 7 Production rules F F M G FM FG N C FG then N C N if x y p r p r b d x cd s push pop p p rs stack preserving transitions pr r b c x x y CS5 ecture CFs Regular anguages First proof ny F can be viewed as a PD that never pops or pushes the stack Second proof uild a CFG for a F where a for p we use P aq for r we use R CS5 ecture 9 Properties of ContextFree anguages Theorem The contextfree languages are closed under union concatenation star be the Proof et be the start symbols of two CFGs et new start symbol of the new CFG we are creating 5 works for union 5 / dding works for concatenation 5 dding works for star dding This also shows how regular expressions can be converted to euivalent CFGs providing a rd proof that regular languages are CFs CS5 ecture