Find the canonical collection of sets of LR (0) items for Grammar - E → E + T E → T T → T * F T → F F → (E) F → id

Compiler DesignProgramming LanguagesComputer Programming

Solution

Step1− Construct the Augmented Grammar and number the productions

(0) E′ → E

(1) E → E + T

(2) E → T

(3) T → T * F

(4) T → F

(5) F → (E)

(6) F → id

Step2− Apply closure to the set of items & find goto

Square Boxes represent the new states or items, and Circle represents the repeating items.

So, all rules of I0have been completed by applying goto on I0. Now, in the same manner apply goto on I1, I2 and then goes on.

Drawing DFA


Each set of the item can be taken as a state of DFA, i.e., I0, I1 … … I11will be 11 states of DFA. They are connected using a goto function.

For example, As goto (I0, E) = I1.

∴ There will be an edge from state I0 to I1..

raja
Updated on 02-Nov-2021 10:23:03

Advertisements