Now the npda performs nondeterministically one of the following:•Push the input symbol onto the pushdown.100

,Λ,SΛ,-S,S,a,a,b,b,c,c,cS, abb,Sε,ε,ε,ε,ε,ε,ε,ε,ε$,Figure 6.1: npda for CFGG(by top-down construction)•IfA→αis any production and the top of the pushdown isαRthen pop offαRonesymbol at a time and then push the nonterminalA.At the end, when $ is encountered, if the pushdown contains the start symbolSthe inputis accepted.The correctness of this construction relies on showing that this procedure backtracks a rightmost derivation.The pda for the above grammar is shown in Figure 6.2.b,a,b,*,cbc,*,a,*,a1S,Sc,S,1SS1$,S,-ε,ε,ε,ε,*,ε,*,ε,ε,1ε,*,Figure 6.2: npda for CFGG(by bottom-up construction)In summary, a top-down recognizer can apply a productionA→αby replacing thetopmost symbolAbyαRor can match the input symbol with the pushdown symbol and101

pop the pushdown. A bottom-up recognizer can apply the above production by replacingαR(by popping off one symbol at a time) byAor can push the input symbol read onthe pushdown.Extensive literature exists on these two types of recognition. Under someconditions, the resulting pushdowns become deterministic. The subclass of CFGs for whichthe top-down procedure yields a deterministic pda are known asLLgrammars (the firstLspecifies that the input string is read left to right and the secondLspecifies that therecognition is done by following the leftmost derivation), and the subclass of CFGs for whichthe bottom-up procedure results in a deterministic pda are known asLRgrammars (thefirst symbolLspecifies that the input is read left to right and the second symbolRspecifiesthat the recognition is done by following the rightmost derivation).For simplicity, assume that there is noǫproduction.Let the input string bex=a1a2···an$.Suppose the current input symbol read isaiand the topmost symbol of thepushdown isA. There can be several productions each withAas the left hand symbol. If thepda can deterministically choose the production to apply based onaiandAthen the gram-mar is anLL(1) grammar. (Our standard pda model needs a minor change. We assumedthat if a transition is labeledai, Athen the pda automatically advances to the next inputsymbolai+1. For this construction, the pda stays onaiand the only time it advances is whenit matches and popsaifrom the pushdown.) If the grammar can deterministically choosethe production based onaiai+1···ai+k−1andA, then the grammar is anLL(k) grammar.(AnLL(k) grammar permits lengthklook aheadon the input tape.) ZZZ: ExplainLR(k)grammars.Before establishing the next result that npda’s can be converted into CFGs, we simplifynpdas to a special class of one state npdas. Initially the pushdown contains a special symbolUin it. In these automata, the push operation is based on only the input symbol; i.e. unlikein usual npdas, the operation is independent of the top symbol of the pushdown. Instead ofthe normal pop, based on the input symbol, the pda can replace up to 2 top symbols of thepushdown by a single symbol. Acceptance is based on the pushdown ending up in a specialsymbolSwhen $ is encountered on the input. The main advantages gained by introducingthese special pdas are two fold: there is only one state and the push operation is independentof the top symbol of the pushdown.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 155 pages?

Upload your study docs or become a

Course Hero member to access this document

Term

Fall

Professor

kosaraju

Tags

Nondeterministic finite state machine, Automata theory