i2tutorials

Compiler Design-SLR(1) Parser- Part (2)

SLR(1) Parser- Part (2)

 

The below is the graphical representation of the given productions

 

Step 2: Construction of SLR Parser table.

StackActionGoto
ab$SA
0S3S412
1Accept
2S3S45
3S3S46
4
5R1

I1 : S’ → S •

I5 : S → AA •

I6 : A → aA •

I4 : A → b •

 

FIRST(S) = {a, b}          FOLLOW = {$}

FIRST(A) = {a, b}          FOLLOW = {a, b, $}

Step 3: Parsing of the input string 

The given string is ‘aabb’

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]=6Reduce 

r3: A → b

$0a3a3A6b$[6,b]=r2[3,A]=6Reduce 

A → aA

$(0a3A6)b$[6,b]=r2[0,A]=2Reduce 

A → aA

$0A2b$[2,b]=s4Shift
$0A2b4$[4,$]=r3[2,A]=5Reduce 

A → b

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

A → A • A

$0S1$[1,$]=accept

 

  1. Construction of SLR Parser

StackActionGoto
id+*()$ETF
0S5S4123
1S6
2S7
3
4S5S4823
593
6S5S4
7S5S410
8S6S11
9S7
10
11

 

Reference Link

SLR(1) Parser- Part (2)

Exit mobile version