PDA corresponding to CFG

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

Top-Down PDA Sequence of steps to which string X= [][[][]] has to be accepted by NPDA NT(G) Grammar has productions s  [S]S|^
1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
Theory Of Automata By Dr. MM Alam
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Introduction to Computability Theory
Theory of Computation What types of things are computable? How can we demonstrate what things are computable?
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Chapter 7 PDA and CFLs.
Pushdown Automata (PDAs)
Lecture # 19. Example Consider the following CFG ∑ = {a, b} Consider the following CFG ∑ = {a, b} 1. S  aSa | bSb | a | b | Λ The above CFG generates.
Lecture Pushdown Automata. stack stack head finite control tape head tape.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Lecture # 22. PDA of language {a n b n : n=0,1,2,3, …}
Lecture # 26 Theory Of Automata By Dr. MM Alam 1.
1 Chapter 6 Simplification of CFGs and Normal Forms.
Lecture # 31 Theory Of Automata By Dr. MM Alam 1.
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
1 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations pop, push, and nop. PDAs always.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
February 1, 2016CS21 Lecture 121 CS21 Decidability and Tractability Lecture 12 February 1, 2016.
Lecture # 21.
Formal Languages, Automata and Models of Computation
Recap lecture 35 Regular grammar, null productions and examples, nullable productions and examples, unit productions and example, Chomsky Normal Form (Definition)
Pushdown Automata.
Closed book, closed notes
Recap lecture 33 Example of trees, Polish Notation, examples, Ambiguous CFG, example,
Syntax Specification and Analysis
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSC312 Automata Theory Grammatical Format Chapter # 13 by Cohen
Theorem 29 Given any PDA, there is another PDA that accepts exactly the same language with the additional property that whenever a path leads to ACCEPT,
Recap Lecture 34 Example of Ambiguous Grammar, Example of Unambiguous Grammer (PALINDROME), Total Language tree with examples (Finite and infinite trees),
PDA’s - A new format for FAs
PDAs Accept Context-Free Languages
Pushdown Automata.
Recap lecture 38 Example of PDA with table for running a string, Equivalent PDA, PDA for EVEN EVEN Language. Non-Derterministic PDA, Example of Non-Derterministic.
Pushdown Automata.
Lecture 9 Theory of AUTOMATA
PARSE TREES.
Pushdown Automata Reading: Chapter 6.
Context-Free Languages
LR(1) grammars The Chinese University of Hong Kong Fall 2010
Kleene’s Theorem Muhammad Arif 12/6/2018.
Last Lecture We began to show CFL = PDA
Midterm #2 — Review problems
Recap lecture 44 Decidability, whether a CFG generates certain string (emptiness), examples, whether a nonterminal is used in the derivation of some word.
ReCap Chomsky Normal Form, Theorem regarding CNF, examples of converting CFG to be in CNF, Example of an FA corresponding to Regular CFG, Left most and.
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Recap lecture 42 Row language, nonterminals defined from summary table, productions defined by rows, rules for defining productions, all possible productions.
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Recap lecture 18 NFA corresponding to union of FAs,example, NFA corresponding to concatenation of FAs,examples, NFA corresponding to closure of an FA,examples.
Recap lecture 37 New format for FAs, input TAPE, START, ACCEPT , REJECT, READ states Examples of New Format of FAs, PUSHDOWN STACK , PUSH and POP states,
Lecture # 13.
Recap Lecture 17 converting NFA to FA (method 3), example, NFA and Kleene’s theorem method 1, examples, NFA and Kleene’s theorem method 2 , NFA corresponding.
Recap lecture 11 Proof of Kleene’s theorem part II (method with different steps), particular examples of TGs to determine corresponding REs.
Recap lecture 25 Intersection of two regular languages is regular, examples, non regular languages, example.
Recap lecture 19 NFA corresponding to Closure of FA, Examples, Memory required to recognize a language, Example, Distinguishing one string from another,
Recap lecture 23 Mealy machines in terms of sequential circuit.
Task Construct CFG that generates the language L = {w  {a,b}*: length(w)  2 and second letter of w from right is a}
Recap Lecture 15 Examples of Kleene’s theorem part III (method 3), NFA, examples, avoiding loop using NFA, example, converting FA to NFA, examples, applying.
Recap lecture 20 Recap Theorem, Example, Finite Automaton with output, Moore machine, Examples.
Recap lecture 40 Recap of example of PDA corresponding to CFG, CFG corresponding to PDA. Theorem, HERE state, Definition of Conversion form, different.
Finite Automaton with output
Recap lecture 41 Recap of PDA in conversion form, example of PDA in conversion form, joints of the machine, new pictorial representation of PDA in conversion.
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

PDA corresponding to CFG Theorem: Corresponding to any CFG there exists a PDA accepting the language generated by the CFG. Since an algorithm has already been discussed to convert the CFG in CNF, so the PDA can be constructed corresponding to the CFG. As the CFG in CNF generates all the nonnull words of the corresponding CFL, so accepting the null string (if it is contained in the CFL), can be managed separately. Following is an example in this regard

Example Consider the following CFG which is in CNF and does not generate the null string S  SB|AB A  CC B  b C  a The corresponding PDA will be

a b ∆ C B ∆ PP RD3 S A S RD1 RD2 AT ST PH S PH B PH C PH B PH S PH A

Example continued … Here the STACK alphabet = {S, A, B, C}, where the TAPE alphabet ={a, b} Note: It may be noted that when the POP state is entered either a nonterminal is replaced by two nonterminals at the top of the STACK accommodating a production, or a nonterminal is popped out from the top of the stack and a READ state is entered to read a specified letter from the TAPE or else the machine crashes.

Example continued … The choice of path taken at POP state to accommodate the word belonging to the CFL can be determined by the left most derivation of the word. Consider the word aab with its left most derivation, as follows

Example continued … Working-String Generation Production Used S  AB S  AB step 1  CCB A  CC step 2  aCB C  a step 3  aaB C  a step 4  aab B  b step 5

Example continued … First of all the START state is entered The PUSH S state is entered aab∆… ∆… TAPE STACK aab∆… S TAPE STACK

Example continued … The POP state is entered and to accommodate the production S  AB, PUSH B and PUSH A states are entered. Then the POP state is entered and to accommodate the production A  CC, PUSH C, PUSH C states are entered aab∆… AB TAPE STACK

Example continued … aab CCB TAPE STACK The POP state is entered and to accommodate the production C  a, READ1 is entered and the letter a is read from the TAPE.

Example continued … aab CB TAPE STACK The POP state is entered and to accommodate the production C  a, READ1 state is entered and the letter a is read from the TAPE aab B TAPE STACK

Example continued … The POP state is entered and to accommodate the production B  b, READ2 state is entered and the letter b is read from the TAPE STACK TAPE  aab

Example continued … The  shown in the STACK indicates that there are no nonterminals in the working string and  is read from the STACK which leads to READ3 state where the  is read from the TAPE and the ACCEPT state is entered which shows that the word aab is accepted by the PDA. Following is the table showing all the observations discussed above, for the word aab

Example continued … aab CB POP CCB PUSH C CCB B AB PUSH A AB PUSH B  S PUSH S START TAPE STACK STATE Left most derivation

Example continued … aab  ACCEPT READ3 POP READ2 aab B READ1 aaB CB aCB Following is an example of building the PDA corresponding to the given CFG

Example Consider the following CFG S  XY X  aX | bX |a Y  Ya | Yb | a First of all, converting the CFG to be in CNF, introduce the nonterminals A and B as A  a B  b The following CFG is in CNF

Example continued … X  AX | BX |a Y  YA | YB | a A  a B  b S  XY The PDA corresponding to the above CFG will be

a b a a B A X Y ∆ ∆ PP RD5 S X X Y Y RD3 RD4 RD1 RD2 AT ST PH S PH X PH A PH B PH Y PH X PH A PH B PH Y PH Y

Example continued … The word aaab can be generated as Working-String Generation Production Used S  XY S  XY step 1  AXY X  AX step 2  aXY A  a step 3  aaY X  a step 4  aaYB Y  YB step 5  aaaB Y  a step 6  aaab B  b step 7

Example continued … ∆ (PP) ∆ aaab (RD4) ∆ (PP) XY (RD2) B (PP) B (RD3)XY (RD4) ∆ (PP) XY (PHA)AXY (RD2) B (PH X)XY (PP) B (PP) Y aabb (PH Y)YB (PH X) XY (PH B) B (PH Y) Y (PP) ∆ (RD1) Y (PH S) S (ST) ∆ STACK TAPE

Summing Up PDA corresponding to CFG, Examples of PDA corresponding to CFG