ATCD PPT Module-4
ATCD PPT Module-4
MODULE - 4
PUSH DOWN AUTOMATA(PDA)
Syntax analysis Phases of compilers part 2
1
Pushdown Automata(PDA)
Pushdown Automata(PDA)
A Pushdown Automaton (PDA) is a 7-tuple (Q, Σ, Γ, δ, q0, Z0, F) where:
• Generally, the leftmost symbol indicates the top of the stack γ and the
bottom at the right end.
• This type of triple notation is called an instantaneous description or
ID of the pushdown automata
Pushdown Automata(PDA)
Languages by PDA:
There are two cases wherein a string w is accepted by PDA.
Get the final state from the start state.
Get an empty stack from the start State.
We say that the language is accepted by the final state and the second
case we say that the language is accepted by an empty stack.
Pushdown Automata(PDA)
Example:
For input string w = “aabb” of PDA where,
M = ({q0, q1, q2}, {a, b}, {a, b, Z0}, δ, q0, Z0, {q2}),
Where δ is defined as follows
δ(q0, a, Z0) = {(q0, aZ0)} Rule (1)
δ(q0, a, a) = {(q0, aa)} Rule (2)
δ(q0, b, a) = {(q1, Ꜫ)} Rule (3)
δ(q1, b, a) = {(q1, Ꜫ)} Rule (4)
δ(q1, Ꜫ, Z0) = {(q2, Ꜫ)} Rule (5)
Pushdown Automata(PDA)
• EX: The above strings shows sequences of reduction, then reduction can be
expressed in terms of sequence of strings like
• If the substring is chosen correctly at each step, the reduction steps could be an
exact reverse of RMD.
Handle Pruning
1. What is mean by handle pruning? How it helps in shift reduce
parsing? List the action of a shift reduce parser.
2.What is handle and handle pruning? Show the working of a shift
reduce parser for
• accepting id1*id2 considering the grammar
• E→E + T |T , T→T*F |F,
F→ ( E ) |id Ans:
• During BUP , a left to right scan of the input construct a right most
derivation in reverse.
• Informally, “A Handle is a substring that matches the body of
production and whose reduction represents one step along the reverse
of a RMD.”
• “A RMD in reverse called canonical reduction sequence is obtained
by the process of handle pruning”
1. Give BUP parse tree for the following input=abbcde for grammar S→aAcBe ,A→AB|b ,B→d
.Find the handle for the above string each with right sentential form and also write shift-reduce
configuration for the same input.
a A B e
A b d
b c
Conflicts during shift reduce parsing
• LR(1) – LR Parser:
• Works on complete set of LR(1) Grammar
• Generates large table and large number of states
• Slow construction
Starts with the root nonterminal on the stack. Ends with the root nonterminal on the stack.
Continuously pops a nonterminal off the stack, and Tries to recognize a right hand side on the stack,
pushes the corresponding right hand side. pops it, and pushes the corresponding nonterminal.