Bottom up parsing of a PDA for context free grammarProductions:
P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
This is a nondeterministic PDA that is uses basic math operators. We will check the equation (3 + 4) * 5 to determine if it is part of the language.
* This presentation is best viewed in a slide show. All writing in red corresponds to other red writing on the slide (mostly used to show transitions).
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed (next step )
Derivation Step
( 3 + 4 ) * 5 PUSH ( -
Z0
Stack
The stackIs empty
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed (next step )
Derivation Step
3 + 4 ) * 5 PUSH 3 -
(
Z0
Stack
( is pushedonto the stack
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
+ 4 ) * 5 POP 3, PUSH A
3
(
Stack
3 is pushedonto the stack
Z0
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
+ 4 ) * 5 POP A, PUSH F (A+4)*5
A
(
Stack
3 is poppedfrom the stackand A is pushed
Z0
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
+ 4 ) * 5 POP F, PUSH T (F+4)*5
F
(
Stack
A is poppedfrom the stackand F is pushed
Z0
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
+ 4 ) * 5 POP T, PUSH E (T+4)*5
T
(
Stack
F is poppedfrom the stackand T is pushed
Z0
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
+ 4 ) * 5 PUSH + (E+4)*5
E
(
Stack
T is poppedfrom the stackand E is pushed
Z0
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
4 ) * 5 PUSH 4 (E+4)*5
+
E
Stack
(
Z0
+ is pushed onto the stack
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
) * 5 POP 4, PUSH A (E+4)*5
4
+
Stack
E
(
4 is pushed onto the stack
Z0
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
) * 5 POP A, PUSH F (E+A)*5
A
+
Stack
E
(
4 is poppedfrom the stackand A is pushed
Z0
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
) * 5 POP F, PUSH T (E+F)*5
F
+
Stack
E
(
A is poppedfrom the stackand F is pushed
Z0
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
) * 5 POP T+E, PUSH E (E+T)*5
T
+
Stack
E
(
F is poppedfrom the stackand T is pushed
Z0
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
) * 5 PUSH ) (E)*5
E
(
Stack
Z0
T, +, E arepopped from the stackand E is pushed
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
* 5 POP ( E ), PUSH F (E)*5
)
E
Stack
(
Z0
) is pushed
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
* 5 POP F, PUSH T F*5
F
Z0
Stack
( E ) arepopped from the stackand F is pushed
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
* 5 PUSH * T*5
T
Z0
Stack
F is popped from the stackand T is pushed
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
5 PUSH 5 T*5
*
T
Stack
Z0
* is pushed
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
POP 5, push A T*5
5
*
Stack
T
Z0
5 is pushed
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
POP A, push F T*A
A
*
Stack
T
Z0
5 is poppedand A is pushed
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
POP T * F, push T T*F
F
*
Stack
T
Z0
A is poppedand F is pushed
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
POP T, PUSH E T
T
Z0
Stack
F*T is poppedand T is pushed
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
POP E E
E
Z0
Stack
T is poppedand E is pushed
Bottom up processing of (3+4)*5P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
Unread Input Action to be Preformed next
Derivation Step
- P
Z0
Stack
E is popped, Leaving zo on The stack and The process is complete
Bottom up processing of (3+4)*5
E
T
* FT
F
E( )
E + T
3
T
FA 4
FA
5
A
P = E T | E + T T F | T * F F A | (E) A 0 | 1 | 2 |…|9
This is the complete tree that we just parsed from the bottom up.
Top Related