Docsity

LR Parsing - Lecture Notes | Programming Languages | CS 4610, Study notes of Programming Languages

Toggle sidebar
bg1
CS 415 โ€“ Discussion Section Notes 4
Claire Le Goues
February 21, 2008
1 LR Parsing
We should practice.
Consider the following LR(0) grammar (borrowed from my recent CS 671 home-
work), with terminals {โˆ’ ( )}:
Sโ†’ โˆ’S
Sโ†’T
Sโ†’๎˜
Tโ†’Tโˆ’
Tโ†’(S)
Letโ€™s work out the DFA for this on the board. We begin by adding a new start
symbol, S0, to our grammar...
S0โ†’S
Sโ†’ โˆ’S
Sโ†’T
Sโ†’๎˜
Tโ†’Tโˆ’
Tโ†’(S)
The first state might look like:
1
pf3

Partial preview of the text

Download LR Parsing - Lecture Notes | Programming Languages | CS 4610 and more Study notes Programming Languages in PDF only on Docsity!

CS 415 โ€“ Discussion Section Notes 4

Claire Le Goues

February 21, 2008

1 LR Parsing

We should practice.

Consider the following LR(0) grammar (borrowed from my recent CS 671 home- work), with terminals {โˆ’ ( )}:

S โ†’ โˆ’S

S โ†’ T

S โ†’ 

T โ†’ T โˆ’

T โ†’ (S)

Letโ€™s work out the DFA for this on the board. We begin by adding a new start symbol, Sโ€ฒ, to our grammar...

Sโ€ฒ^ โ†’ S

S โ†’ โˆ’S

S โ†’ T

S โ†’ 

T โ†’ T โˆ’

T โ†’ (S)

The first state might look like:

Sโ€ฒ^ โ†’ โ€ข S

S โ†’ โ€ข โˆ’S

S โ†’ โ€ข T

S โ†’ โ€ข 

T โ†’ โ€ข T โˆ’

T โ†’ โ€ข (S)

How do we do the rest?

That was fun. Next up: letโ€™s make a parsing table from that DFA. (note: