0% found this document useful (0 votes)
18 views

CLR and Lalr

CLR AND LALR

Uploaded by

ulfmqb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

CLR and Lalr

CLR AND LALR

Uploaded by

ulfmqb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

SLR PARSER

Steps:
1. create augment grammar
2. generate kernel items
3. find closure
4. compute goto()
5. construct parsing table
6. parse the string

Let us consider grammar:

S->L=R

S->R

L->*R

L->id

R->L
• Step :1 Create augment grammar
S is start symbol in the given grammar
Augment grammar is S’-> S

• Step :2 Generate kernel items


Introduce dot in RHS of the production

.
S’-> S
• Step :3 Find closure
(Rule: A -> α.Xβ i.eS’->
if there
.S is nonterminal next topresence
Since dot then Include X production))
of S (nonterminal)next to dot, introduce S production

S-> . L=R Since presence of L (nonterminal)next to dot, introduce L production

S-> . R I0 Since presence of R (nonterminal)next to dot, introduce R production

L-> . *R
L-> . Id
R-> . L
CLR PARSER

Steps:
1. create augment grammar
2. generate kernel items and add 2nd component
3. find closure
4. compute goto()
5. construct parsing table
Rule to find 2nd component:
6. parse the string
Consider the production of the form : A-> α .Bβ , a
Let us consider grammar: THEN 2nd component of B is : β , if it is terminal
First (β ) if it is non terminal
S->L=R a, if there is no β

S->R

L->*R

L->id

R->L
• Step :1 Create augment grammar
S is start symbol in the given grammar
Augment grammar is S’-> S

• Step :2 Generate kernel items and add 2nd component


Introduce dot in RHS of the production
Add $ as 2nd component separated by comma

.
S’-> S , $
• Step :3 Find closure
(Rule: A -> α.Xβ i.e if thereS’-> .S , $
is nonterminal next to dot then Include X production))
S-> . L=R
S-> . R I0
L-> . *R
L-> . Id
R-> . L
S’-> .S , $ Next find 2nd component:
S-> . L=R, $ I0 compare each of the production with A-> α .Bβ , a
S-> . R, $ S’ -> . s, $ here no β, so $ is 2nd comp to S
L-> . *R, =/$
L-> . Id,=/$ S -> . L=R,$ here β is = so add it as 2nd comp to L

R-> . L, $ S-> . R, $ here no β, so $ is 2nd comp to R


L production is not in standard form
R-> . L, $ here no β, so $ is 2nd comp to L

Rule to find 2nd component:

Consider the production of the form : A-> α .Bβ , a


THEN 2nd component of B is : β , if it is terminal
First (β ) if it is non terminal
a, if there is no β
Step :4 compute goto()

L
*

I5’
I4’
I5
id
R *
*
I3

I5’
To construct: LALR PARSER
We notice that some states in CLR parser have the same core items and differ only in
possible lookahead symbols.

Such as
I4 and I4’
I5 and I5’
I7 and I7’
I8 and I8’

So we shrink the obtained CLR parser by merging such states to form LALR Parser

Hence

CLR PARSER has 14 States (I0, I1,I2,I3,I4,I4’,I5,I5’,I6,I7,I7’,I8,I8’,I9)

LALR PARSER has 10 states (I0, I1,I2,I3,I4,I5,I6,I7,I8,I9)


LALR PARSER

You might also like