πŸŽ“ Computer Science & Engineering Portal

Master Engineering Disciplines with Structured Notes

Comprehensive academic lecture notes, exam-oriented unit summaries, laboratory manuals, and previous year question papers designed strictly for university students.

πŸ“‘

University Syllabi

AKTU & AICTE aligned semester guidelines.

πŸ“

Exam Question Papers

Previous 5 years solved university papers.

πŸ’‘

Lab Manuals & Viva

Practical codes with outputs & interview Qs.

Core Subjects & Units Hub

Click on any specific unit to immediately view its lecture notes below

Viewing All Lectures

Canonical Collection of LR(0) items

Canonical Collection of LR(0) items

  • An LR (0) item is a production G with dot at some position on the right side of the production.
  • LR(0) items is useful to indicate that how much of the input has been scanned up to a given point in the process of parsing.
  • In the LR (0), we place the reduce node in the entire row.

Example

Given grammar:

S β†’ AA  
A β†’ aA | b  

Add Augment Production and insert 'β€’' symbol at the first position for every production in G

S` β†’ β€’S  
S β†’ β€’AA  
A β†’ β€’aA   
A β†’ β€’b  

I0 State:

Add Augment production to the I0 State and Compute the Closure

I0 = Closure (S` β†’ β€’S)

Add all productions starting with S in to I0 State because "β€’" is followed by the non-terminal. So, the I0 State becomes

I0 = S` β†’ β€’S
       S β†’ β€’AA

Add all productions starting with "A" in modified I0 State because "β€’" is followed by the non-terminal. So, the I0 State becomes.

I0= S` β†’ β€’S
       S β†’ β€’AA
       A β†’ β€’aA
       A β†’ β€’b

I1= Go to (I0, S) = closure (S` β†’ Sβ€’) = S` β†’ Sβ€’

Here, the Production is reduced so close the State.

I1= S` β†’ Sβ€’

I2= Go to (I0, A) = closure (S β†’ Aβ€’A)

Add all productions starting with A in to I2 State because "β€’" is followed by the non-terminal. So, the I2 State becomes

I2 =S→A‒A
       A β†’ β€’aA
       A β†’ β€’b

Go to (I2,a) = Closure (A β†’ aβ€’A) = (same as I3)

Go to (I2, b) = Closure (A β†’ bβ€’) = (same as I4)

I3= Go to (I0,a) = Closure (A β†’ aβ€’A)

Add productions starting with A in I3.

A β†’ aβ€’A
A β†’ β€’aA
A β†’ β€’b

Go to (I3, a) = Closure (A β†’ aβ€’A) = (same as I3)
Go to (I3, b) = Closure (A β†’ bβ€’) = (same as I4)

I4= Go to (I0, b) = closure (A β†’ bβ€’) = A β†’ bβ€’
I5= Go to (I2, A) = Closure (S β†’ AAβ€’) = SA β†’ Aβ€’
I6= Go to (I3, A) = Closure (A β†’ aAβ€’) = A β†’ aAβ€’

Drawing DFA:

The DFA contains the 7 states I0 to I6.

Canonical Collection of LR(0) items

LR(0) Table

  • If a state is going to some other state on a terminal then it correspond to a shift move.
  • If a state is going to some other state on a variable then it correspond to go to move.
  • If a state contain the final item in the particular row then write the reduce node completely.

Canonical Collection of LR(0) items 1

Explanation:

  • I0 on S is going to I1 so write it as 1.
  • I0 on A is going to I2 so write it as 2.
  • I2 on A is going to I5 so write it as 5.
  • I3 on A is going to I6 so write it as 6.
  • I0, I2and I3on a are going to I3 so write it as S3 which means that shift 3.
  • I0, I2 and I3 on b are going to I4 so write it as S4 which means that shift 4.
  • I4, I5 and I6 all states contains the final item because they contain β€’ in the right most end. So rate the production as production number.

Productions are numbered as follows:

S  β†’      AA    ... (1)                              
A   β†’     aA      ... (2)   
A    β†’    b     ... (3)  
  • I1 contains the final item which drives(S` β†’ Sβ€’), so action {I1, $} = Accept.
  • I4 contains the final item which drives A β†’ bβ€’ and that production corresponds to the production number 3 so write it as r3 in the entire row.
  • I5 contains the final item which drives S β†’ AAβ€’ and that production corresponds to the production number 1 so write it as r1 in the entire row.
  • I6 contains the final item which drives A β†’ aAβ€’ and that production corresponds to the production number 2 so write it as r2 in the entire row.

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

<$CommentPager$>
<$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>