|  |  |  | Building an LR(1) Machine | 
 
 1 .
1 .  2 , a ]
          
          is an LR(1) item or LR(1) configuration for G if
	  N
2 , a ]
          
          is an LR(1) item or LR(1) configuration for G if
	  N 
            
 1
1  2 is a production in G and 
          a
2 is a production in G and 
          a  ( Vt  U
( Vt  U  ).  The symbol `a' is called
          the lookahead.
).  The symbol `a' is called
          the lookahead.
       
 1 .
1 .  2, a ]
     
      is valid for
2, a ]
     
      is valid for 
 ( Vn  U Vt )* if there is a
      rightmost derivation
( Vn  U Vt )* if there is a
      rightmost derivation
      Ssuch that
N omega

1
2 omega

 1 =
1 =  and 
      a
 and 
      a  First(omega).
 First(omega).
      goto(, x ) = { [ N

1 x .
2 , a ] | [ N

1 . x
2 , a]
}
 of LR(1) items for a grammar G with 
           productions P, we define  closure(
 of LR(1) items for a grammar G with 
           productions P, we define  closure( ) to be the smallest
           set of LR(1) items such that:
) to be the smallest
           set of LR(1) items such that:
            )
) 
 
	    
 1 . N2
1 . N2  2,a]
2,a] 
                                  closure(
 closure( ) 
                     and N2
) 
                     and N2 
            
 3
3  P
                 then, for each b
P
                 then, for each b  First(
 First(  2 a ),
		   [N2
2 a ),
		   [N2 
            .
 .  3, b]
3, b]  closure(
  closure( )
)
       (
, x) = closure ( goto (
, x ) )
 . S $,
. S $,  ] ) as its
            initial state.
] ) as its
            initial state.
      
            E 
            ( L , E )
( L , E )  
E 
            S
S 
L 
            L , E
L , E 
L 
            E
E 
S 
            ident
ident 
S 
            ( S )
( S )
	 
 
 1 . , x ] and
      either another reduce item of the form [ M
1 . , x ] and
      either another reduce item of the form [ M 
            
 2 . , x ] or
      a shift item of the form [ M
2 . , x ] or
      a shift item of the form [ M 
            alpha. x
alpha. x  2 , y ].
2 , y ].
 with input x if state
 
      with input x if state  contains a shift item of the form
      [ N
 contains a shift item of the form
      [ N 
            alpha. x
alpha. x  , a], reduces using production
      N
, a], reduces using production
      N 
            
 if state
 if state  contains a reduce item of
      the form [ N
 contains a reduce item of
      the form [ N 
            
 . , x ] and reports error otherwise.
. , x ] and reports error otherwise.
|  |  |  | Building an LR(1) Machine |