Closure operation
. If I is a set of items for a grammar G then closure(I) is a set constructed as follows:
- Every item in I is in closure (I)
- If A
α .B ß is in closure(I) and B
γ is a production then B
. γ is in closure(I)
. Intuitively A
α .B ß indicates that we might see a string derivable from B ß as input
. If input B
γ is a production then we might see a string derivable from γ at this point
As stated earlier, closure operation requires us to find all such alternate ways to expect further input. If I is a set of items for a grammar G then closure( I ) is the set of items constructed from I by the two rules:
1. Initially, every item in I is added to closure (I).
2. If A
α .B ß is in closure( I ) and B
γ is a production then add the item B
. γ to I , if it is not already there. We apply this rule until no more new items can be added to closure( I ).
Intuitively A
α .B ß in closure( I ) indicates that, at some point in the parsing process, we think we might next see a substring derivable from B ß as input. If B
γ is a production, we also expect we might see a substring derivable from γ at this point. For this reason, we also include B
. γ in closure( I ).