Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views37 pages

Unit4 Toc

The document provides an overview of Pushdown Automata (PDA), including deterministic (DPDA) and non-deterministic (NDPDA) versions, their applications, and the comparison between them. It outlines the design requirements for machines and grammars, including tuples, transition tables, and derivation steps. Additionally, it discusses the conversion between PDAs and context-free grammars (CFG), along with examples and assignments for further practice.

Uploaded by

10322210088
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views37 pages

Unit4 Toc

The document provides an overview of Pushdown Automata (PDA), including deterministic (DPDA) and non-deterministic (NDPDA) versions, their applications, and the comparison between them. It outlines the design requirements for machines and grammars, including tuples, transition tables, and derivation steps. Additionally, it discusses the conversion between PDAs and context-free grammars (CFG), along with examples and assignments for further practice.

Uploaded by

10322210088
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Unit4

• Introduction to Pushdown Machines,


• Applications of Pushdown Machines
• NDPDA, DPDA,
• context free languages and PDA,
• comparison of deterministic and non-
deterministic versions,
• closure properties,
• Conversion PDA to CFG and vice-versa
a=0, b=0
THINGS TO BE DESCRIBED
WHILE DESIGNING A MACHINE….
• DESCRIBLE ALL 6 OR 7 TUPLES
• TRANSITION TABLE
• GRAPHICAL REPRESENTAION
• TRANSITION RULES
• DERIVATION STEPS USING SENTENTIAL FORM FOR ANY EXAMPLE.

WHILE GENERATING OR DEFINING A GRAMMAR….


• DESCRIBLE ALL 4 TUPLES
• PRODUCTION RULES
• DERIVATION STEPS USING SENTENTIAL OR DERIVATION TREE FOR
ANY EXAMPLE
NDPDA

https://www.cs.wcupa.edu/rkline/fcs/pdas.html
Palindrome examples
(deterministic)

• The machine pushes a's and b's in state s, makes a transition to f when it sees the
middle marker, c, and then matches input symbols with those on the stack and
pops the stack symbol.

Non-accepting string examples are :


• ε in state s
• ab in state s with non-empty stack
• abcab in state f with unconsumed input and non-empty stack
• abcb in state f with non-empty stack
• abcbab in state f with unconsumed input and empty stack

NOTE: Observe that this PDA is deterministic in the sense that there are no choices in
transitions.
Non-deterministic example

• there is a significant difference in that this PDA must guess when to stop
pushing symbols, jump to the final state and start matching off of the
stack.
• Therefore this machine is decidedly non-deterministic.
• In a general programming model (like Turing Machines), we have the
luxury of preprocessing the string to determine its length and thereby
knowing when the middle is coming.
Parse tree in case of NDPDA

• Assume: epsilon on every side of input symbol ( since don’t know


the mid-point or from where the reversed string begins).
NOTE:
• more than one parse tree for a single input string.
• If one of the parse or derivation tree leads to final state, then input
string is accepted.
Example 2

• The idea in both of these machines is to stack the a's and match off the b's.
• The first one is non-deterministic in the sense that it could prematurely guess that
the a's are done and start matching off b's.
• The second version is deterministic in that the first b acts as a trigger to start
matching off. Note that we have to make both states final in the second version in
order to accept ε
COMPARISON
DPDA(DETERMINISTIC PUSHDOWN AUTOMATA)
•In DPDA, the central symbol is known. Ex- abcba. Here, c denotes the central symbol
and tells that after this symbol, pop operation needs to be performed.
•There is only one move allowed in one situation.
•The representation of a dpda is wcw^r.

NDPDA/NPDA(NON DETERMINISTIC PUSHDOWN AUTOMATA)


•Central symbol is not known in case of a NPDA
•There are multiple moves possible in one situation.
•The representation of a NPDA is ww^r.

NOTE:
•NPDAs are a generalization of DPDAs: every DPDA can be simulated by an NPDA, but
the converse doesn't hold (there are context-free languages which cannot be
accepted by a DPDA).
•The main advantage of DPDAs is that we can simulate them much more easily with
our deterministic computers (real hardware is always deterministic). In fact,
simulating general DPDAs is not fast enough for most purposes, and so when parsing
code we usually use LALR grammars which are weaker than DPDAs.
• General form—of left sentential form in left-most
derivation.
Handling symbols in STACK in LMD
Rule 1: when stack top is a non-terminal

• During derivation, for a left sentential form, when non-terminal A (which


is currently on stack top) is replaced by its RHS string, then
• 1. pop A and push the string in reverse order in stack
• 2. create n states and add transitions for each RHS symbol in reverse
order, as shown in figure.
Rule 2: when stack top is a terminal

• Suppose currently READ pointer is on 0


• After replacing rule A with its RHS string on stack (in reverse order),
if the stack top symbol with RD ptr symbol, then
• 1. advance the ptr and pop stack.
• Create a state and add transition for each matching input symbol
(to represent pop).
Generalized form of Final PDA
CFG to PDA Conversion
• The first symbol on R.H.S. production must be a
terminal symbol. The following steps are used to obtain
PDA from CFG is:
Step 1: Convert the given productions of CFG into GNF.
Step 2: The PDA will only have one state {q}.
Step 3: The initial symbol of CFG will be the initial symbol in
the PDA.
Step 4: For non-terminal symbol, add the following rule:
δ(q, ε, A) = (q, α)
Where the production rule is A → α , following GNF rules.
Step 5: For each terminal symbols, add the following rule:
δ(q, a, a) = (q, ε) for every terminal symbol
Example 1
• The above steps could be shown using a tree structure for multiple
paths as shown in slide 15 and 16.
Assignment/practice
• Applications of PDA
• COMPARISON OF DPDA AND NDPDA
• Construct Pushdown automata for L =
{0n1m2m3n | m,n ≥ 0}
• Construct NPDA for accepting the language L =
{an bm cn | m,n>=1}

You might also like