1 / 16

Pushdown Automata

Pushdown Automata. CPSC 388 Ellen Walker Hiram College. PDA = FA + Stack. A PDA Transaction. Read the next symbol from the input Pop a symbol from the stack Push a symbol on the stack Enter a new state. Epsilon in PDA. Read epsilon No character is read, input location stays the same

ygonzalez
Download Presentation

Pushdown Automata

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pushdown Automata CPSC 388 Ellen Walker Hiram College

  2. PDA = FA + Stack

  3. A PDA Transaction • Read the next symbol from the input • Pop a symbol from the stack • Push a symbol on the stack • Enter a new state

  4. Epsilon in PDA • Read epsilon • No character is read, input location stays the same • Push or pop epsilon • The stack remains unchanged

  5. Format of a Transition • Items before ; are “input”, items after ; are “action” ( Current state, Input symbol, Symbol popped ; New state, Symbol pushed )

  6. PDA for anbn • Assume initial stack contains “Z” (delimiter for bottom of stack) • S1, a,  ; S2, a - leave Z on bottom • S2, a, ; S2, a - push a for each a • S2, b, a ; S3,  - pop a for each b • S3, b, a ; S3,  • S3, , Z ; S4, Z - Final state if Z reached

  7. PDA Diagram • For each state: item read, popped, pushed • State transitions using arrows as for FA • To check the item on top of the stack, then push an additional item, JFLAP allows a double-push (a, Z, aZ)

  8. PDA Diagram for anbn This PDA requires n≥1. (How can we make it accept n=0?)

  9. Formal Definition of PDA • A PDA is of the form (S, , , , , F) where • S is a finite collection of states •  is the machine's alphabet •  is the finite collection of stack symbols •  is the finite collection of transitions of the form (p,s,x; q,y) •  (an element of S) is the initial state • F (a subset of S) is the set of accept states

  10. Formal Definition of Example • States: {q0, q1, q2, q3} • Alphabet: {a, b} • Stack symbols: {Z, a} • Transitions (see slide 6) • Initial state: q2 • Accept states: {q3}

  11. All Strings with Equal # a’s and b’s • General idea: • If you see an a • If there is a b on the stack, pop it • Otherwise, push an a • If you see a b • If there is an a on the stack, pop it • Otherwise, push a b • At the end of the string, if Z is on top, then accept

  12. Build a PDA for each: • All strings of the form ambn, n>m • All strings consisting of a’s and b’s with at least 3 more a’s than b’s (Hint: use epsilon-transitions) • All palindromes over the alphabet {a,b,c} (Hint: it needs to be nondeterministic)

  13. Every RL has a PDA to accept it • Given the RL, construct an FA for it. • Make a PDA with the same FA that reads the input but ignores the stack • For each FA transition (state1, char; state2) create a pda transition (state1, char, ; state2, )

  14. PDA’s are more powerful than FA’s • Every FA has an equivalent PDA • Proof by construction on previous slide • At least one PDA does not have an equivalent FA • Proof by example: anbn • Therefore the class of languages accepted by PDA’s is a superset of the class of languages accepted by FA’s

  15. Deterministic vs. Nondeterministic PDA’s • Deterministic PDA’s • Every state/stack combination has exactly one transition • No epsilon-transitions (epsilon for both input and stack symbol) • Nondeterministic PDA’s are more powerful than deterministic PDA’s • Example: strings from a*b* that have either twice as many a’s as b’s or 3x as many a’s as b’s

  16. Not All Languages are Context Free • There is a pumping lemma for Context free languages • Similar to RL pumping lemma, but you have to pump in two places • Non CFL: anbncn • (Details are beyond the scope of this course)

More Related