Using the LR(0) machineTopAnouncementsConstructing the LR(0) Machine for a Grammar

Constructing the LR(0) Machine for a Grammar

  1. To make the ideas we talked about last time precise (and eventually prove that we can use them to construct a correct parser) we need to refresh your knowledge of finite automata a bit.
  2. First, recall the structure of a deterministic finite state machine.
    1. A finite set of states, .
    2. An input alphabet, .
    3. A transition function : x -> .
    4. A subset F of called the set of final states.
    5. An element 0 of called the initial state.
  3. While you are at it, recall (or at least note) that we can explain the behavior of a deterministic finite state machine by defining a function that extends to strings over the input alphabet. In particular, we can define : x * -> recursively as and then state that the language accepted by the machine is
    { *  | ( 0, ) F }
  4. 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()
  5. The closure of a set of LR(0) items can be computed using a simple (but important) little algorithm
  6. 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:
  7. A somewhat interesting example.
    < S` > < S > $
    < S > < S > a < S > b  |  c


Computer Science 434
Department of Computer Science
Williams College

Using the LR(0) machineTopAnouncementsConstructing the LR(0) Machine for a Grammar