TopA Quick Review of Finite AutomataConstructing the LR(0) Machine for a Grammar

Constructing the LR(0) Machine for a Grammar

  1. Now, we can give a general definition of the LR(0) machine for an arbitrary grammar G.

    Of course, we need a few more definitions:

    goto
    Given a set of LR(0) items for a grammar G, we define
    goto( , x ) = { [ N 1 x . 2 ]  | [ N 1 . x 2 ] }
    closure
    Given a set of LR(0) items for a grammar G with productions P, we define closure() to be the smallest set of LR(0) items such that:
    1. closure()
    2. if [N1 1 . N2 2] closure() and N2 3 P then [N2 . 3] closure()
  2. The closure of a set of LR(0) items can be computed using a simple (but important) little algorithm
  3. With these definitions and the assumption that the start symbol S of G is replaced by a new start symbol S' and that the rule S' S $ is added to the set of productions (The $ just stands for end-of-input). The definition of the LR(0) machine is:
  4. A somewhat interesting example.
    < S` > < S > $
    < S > < S > a < S > b  |  c


Computer Science 434
Department of Computer Science
Williams College

TopA Quick Review of Finite AutomataConstructing the LR(0) Machine for a Grammar