Find Canonical Parsing Table (CLR) or LR (1) Parsing Table for Grammar. S → CC C → c C | d

Compiler DesignProgramming LanguagesComputer Programming

Solution

Step1 − Construct Augmented Grammar

(0) S′ → S

(1) S → CC

(2) C → cC

(3) C → d.

Step2 − Find closure & goto to construct LR (1) items

Applying goto on I7, I8, I9

In I7, I8, I9 we have production C → d ∙, $, c → cC ∙, c | d and ∙ C → cC ∙, $ respectively, i.e., the dot cannot be shifted further.

So, goto cannot be applied to I7, I8, I9.

Drawing DFA

First of all, 10 states, i.e.,I0 to I9 will act as nodes for DFA.

Edges are joined using goto statements. For example, goto(I0, S) = I1

∴ There will be an edge from I0 to I1 labeled S.

Similarly, other nodes are connected by seeing all goto statements in LR (1) items of grammar.

raja
Updated on 02-Nov-2021 11:46:03

Advertisements