0% found this document useful (0 votes)
2 views

6_parsing-slides-sanyal-part3

LR(0) items are production rules with a dot indicating the position in the right-hand side of the rule, with examples provided for clarification. An LR(0) item is complete if the dot is at the end, while kernel items have the dot not at the left end, with exceptions. The document also discusses the closure and goto functions essential for constructing the SLR parsing table.

Uploaded by

rrushikesh959
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

6_parsing-slides-sanyal-part3

LR(0) items are production rules with a dot indicating the position in the right-hand side of the rule, with examples provided for clarification. An LR(0) item is complete if the dot is at the end, while kernel items have the dot not at the left end, with exceptions. The document also discusses the closure and goto functions essential for constructing the SLR parsing table.

Uploaded by

rrushikesh959
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

LR(0) Items

LR(0) item : An LR(0) item for a grammar G is a production rule


of G with the symbol • ( read as dot or bullet) inserted at some
position in the rhs of the rule.
Example of LR(0) items : For the rule given below

decls → decls decl


the possible LR(0) items are :
I1 : decls → •decls decl
I2 : decls → decls • decl
I3 : decls → decls decl •
The rule decls → ǫ has only one LR(0) item,
I4 : decls → •

Amitabha Sanyal (IIT Bombay) Syntax Analysis IIT, Bombay 60 / 94


LR(0) Items

An LR(0) item is complete if the • is the last symbol in the rhs.


Example : I3 and I4 are complete items and I1 and I2 are incomplete
items.
An LR(0) item is called a kernel item, if the dot is not at the left
end. However the item S ′ → •S is an exception and is defined to be
a kernel item.
Example : I1 , I2 , I3 are all kernel items and I4 is a non-kernel item.

Amitabha Sanyal (IIT Bombay) Syntax Analysis IIT, Bombay 61 / 94


Canonical Collection of LR(0) Items

The construction of the SLR parsing table requires two functions closure
and goto.

closure: Let U be the collection of all LR(0) items of a cfg G . Then


closure : U → 2U .
1 closure(I ) = {I }, for I ∈ U
2 If A → α • Bβ ∈ closure(I ), then the item B → •η is added to
closure(I ).
3 Apply step (ii) above repeatedly till no more new items can be
added to closure(I ).

Example: Consider the grammar A → A a | b

closure(A → •A a) = {A → •A a, A → •b}

Amitabha Sanyal (IIT Bombay) Syntax Analysis IIT, Bombay 62 / 94


Canonical Collection of LR(0) Items

goto: goto : U × X → 2U , where X is a grammar symbol.


goto(A → α • X β, X ) = closure(A → αX • β).

Example: goto(A → •Aa, A) = closure(A → A • a) = {A → A • a}


closure and goto can be extended to a set S of LR(0) items by
appropriate generalizations
S
closure(S) = {closure(I )}
SI∈S
goto(S, X ) = I∈S {goto(I , X )}

Amitabha Sanyal (IIT Bombay) Syntax Analysis IIT, Bombay 63 / 94

You might also like