/    /  Compiler Design-Example for CLR Parsing-(2)

Example for CLR Parsing-(2)

 

Step 3:

STACKACTIONGOTO

 

abcde
0S3S412
1Accept
2S6S75
3S3S48
4r3r3
5r1
6S6S7
7r3
8r2r2
9r2

 

I1 : S1 → S., $

I4 : A→ b., a/b                                                              S → AA →  r1

I5 : S → AA., $                                                             A → aA → r1

I7 : A → b., $                                                                A → b → r3

I8 : A → aA., a/b

I9 : A → aA., $

The remaining blank entries in the table are considered errors.  The given I/P string is ‘aabb’.

 

Step 4:

STACKI/P BUFFERACTION TABLEGOTO TABLEPARSING ACTION
$0aabb$[0,a]=S3Shift
$0a3abb$[3,a]=S3Shift
$0a3a3bb$[3,b]=S4Shift
$0a3a3(b4)b$[4,b]=r3[3,A]=8Reduce 

A → b

$0a3(a3A8)b$[8,b]=r2[3,A]=8Reduce 

A → aA

$0(a3A8)b$[8,b]=r2[0,A]=2Reduce 

A → aA

$0A2b$[2,b]=s7Shift
$0A2(b4)$[7,$]=r3[2,A]=5Reduce 

A → b

$0(A2A5)$[5,$]=r1[0,5]=1Reduce 

S → AA

$0S1$[1,$]=accept

 

Reference Link

Example for CLR Parsing-(2)