bottom up parsing of a pda for context free grammar productions: p = e t | e + t

25
Bottom up parsing of a PDA for context free grammar Productions: 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).

Upload: maxim

Post on 24-Feb-2016

40 views

Category:

Documents


0 download

DESCRIPTION

Bottom up parsing of a PDA for context free grammar Productions: P = E  T | E + T T  F | T * F F  A | (E) A  0 | 1 | 2 |…|9. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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).

Page 2: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 3: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 4: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 5: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 6: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 7: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 8: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 9: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 10: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 11: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 12: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 13: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 14: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 15: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 16: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 17: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 18: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 19: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 20: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 21: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 22: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 23: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 24: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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

Page 25: Bottom up parsing of a  PDA for context free grammar Productions: P =   E    T | E + T

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.