Site icon i2tutorials

Compiler Design-Example for LALR(1) Parser-2

Example for LALR(1) Parser-2

 

STEP 3: Parsing table

 

STACKACTIONGOTO

 

ab$SA
0S36S4712
1Accept
2S36S475
36S36S4789
47r36r36r36
5r1
36S36S4789
47r36
89r2r2r2
89r2

 

Here, since 36, 47, and 89 are duplicates in the table they will not be considered. 

 

Therefore, This is the reduced LALR Parser table

For the given input string, W=”aabb” using the LALR(1) parsing table.

STACKI/P BUFFERACTION TABLEGOTO TABLEPARSING ACTION
$0aabb$[0,a]=S36Shift
$0a36abb$[36,a]=S36Shift
$0a36a36bb$[36,b]=S47Shift
$0a36a36(b47)b$[47,b]=r36[36,A]=8Reduce 

A → b

$0a36(a36A89)b$[89,b]=r2[36,A]=8Reduce 

A → aA

$0(a36A89)b$[89,b]=r2[0,A]=2Reduce 

A → aA

$0A2b$[2,b]=s47Shift
$0A2b47$[47,$]=r36[2,A]=5Reduce 

A → b

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

S → AA

$0S1$[1,$]=accept

 

Reference Link

Example for LALR(1) Parser-2

Exit mobile version