Chapter 4: Syntax Analysis

Example

Grammar: I 2 : goto(I 0 ,T) I6 : goto(I1 ,+) I9 : goto(I6 ,T)
E ' E E T. E E + .T E E + T.
E E+T | T T T. *F T .T * F T T. * F
T T*F | F I3 : goto(I0 ,F) T .F goto(I6 ,F) is I 3
F (E) | id T F. F .(E) goto(I6 ,( ) is I4
I 0 : closure(E ' .E) I4 : goto( I0 ,( ) F .id goto(I6 ,id) is I5
E ' .E F (.E) I 7 : goto(I2 ,*) I 10 : goto(I 7 ,F)
E .E + T E .E + T T T * .F T T * F.
E .T E .T F .(E) goto(I7 ,( ) is I4
T .T * F T .T * F F .id goto(I7 ,id) is I5
T .F T .F I 8 : goto(I4 ,E) I 11 : goto(I8 ,) )
F .(E) F .(E) F (E.) F (E).
F .id F .id E E. + T goto(I8 ,+) is I6
I 1 : goto(I0 ,E) I5 : goto( I0 ,id) goto(I4 ,T) is I2 goto(I9 ,*) is I 7
E ' E. F id. goto(I 4 ,F) is I3  
E E. + T   goto(I 4 ,( ) is I4  
    goto(I4 ,id) is I5  

Let's take an example here. We have earlier calculated the closure I0 . Here, notice that we need to calculate goto (I0 ,E), goto(I0 ,T), goto(I 0 , F) , goto (I0 , ( ) and goto(I0 , id). For calculating goto(I0 , E), we take all the LR(0) items in I 0 , which expect E as input (i.e. are of the form A α .E ß ), and advance ".". Closure is then taken of this set. Here, goto(I 0 , E) will be closure { E ' E. , E E.+T }. The closure adds no item to this set, and hence goto(I 0 , E)={ E ' E. , E E.+T }.