Plan for Today and Thursday Bottom-Up Parsing with LR parse tables - - PDF document

plan for today and thursday
SMART_READER_LITE
LIVE PREVIEW

Plan for Today and Thursday Bottom-Up Parsing with LR parse tables - - PDF document

Plan for Today and Thursday Bottom-Up Parsing with LR parse tables JavaCUP debug information using an LR parser Building the LR Parsing Table for LR(0) items, closure, and goto, oh my! why does it need to know input token if LR(0)?


slide-1
SLIDE 1

CS453 Lecture Building LR Parse Tables 1

Plan for Today and Thursday

Bottom-Up Parsing with LR parse tables

– JavaCUP debug information – using an LR parser

Building the LR Parsing Table for LR(0)

– items, closure, and goto, oh my! – why does it need to know input token if LR(0)? Building the LR Parsing Table for LR(1) – First and Follow sets – building the table

Debugging shift/reduce and reduce/reduce errors

LR parse tables and pushdown automata

CS453 Lecture Building LR Parse Tables 2

Example LR Parse Table

[0] S -> ( S ) [1] S’ -> S EOF [2] S -> ID

Action Goto State ( ) $/EOF ID S s3 s1 2 1 r2 r2 r2 r2 2 accept 3 s3 s1 4 4 s5 5 r0 r0 r0 r0

slide-2
SLIDE 2

CS453 Lecture Building LR Parse Tables 3

Building the LR Parse Table for LR(0)

[0] S -> ( S ) [1] S’ -> S EOF [2] S -> ID

CS453 Lecture Building LR Parse Tables 4

LR(0) states for nested parens example

slide-3
SLIDE 3

CS453 Lecture Building LR Parse Tables 5

Building the Table from the State Diagram

Action Goto State ( ) $/EOF ID S s3 s1 2 1 r2 r2 r2 r2 2 accept 3 s3 s1 4 4 s5 5 r0 r0 r0 r0

CS453 Lecture Building LR Parse Tables 6

Building the LR Parse Table for LR(0), another example

(0) S’ -> E $ (1) E -> E || B (2) E -> B (3) B -> t (4) B -> f

slide-4
SLIDE 4

CS453 Lecture Building LR Parse Tables 7

FIRST and FOLLOW sets

FIRST( gamma )

– gamma is a string of terminals and nonterminals – FIRST(gamma) is any terminals that can start a string derived from gamma

nullable(X)

– X is a nonterminal – nullable(X) is true if X can derive the empty string

FOLLOW( X )

– X is a nonterminal – FOLLOW(X) is all terminals that can immediately follow X in strings generated from the grammar

CS453 Lecture Building LR Parse Tables 8

(0) S’ -> E $ (1) E -> T + E (2) E -> T (3) T -> x

Building the LR Parse Table for LR(1)

Symbol FIRST x x + + T x E x S x Action Goto State x + $ T E s3 g2 g1 1 accept 2 s4 r2 3 r3 r3 4 s3 g2 g5 5 r1

slide-5
SLIDE 5

CS453 Lecture Building LR Parse Tables 9

Example LR Parse Table

[0] S -> ( S ) [1] S’ -> S EOF [2] S -> ID

Action Goto State ( ) $/EOF ID S s3 s1 2 1 r2 r2 r2 r2 2 accept 3 s3 s1 4 4 s5 5 r0 r0 r0 r0

CS453 Lecture Building LR Parse Tables 10

Pushdown Automata for Grammar