Assignment 5: LALR(1) Parsing
Due: 12/2/03

  1. For the last assignment, I asked you to construct the LR(0) and LR(1) machines for the following grammar:

    < E > ( < E > , < L > )  |  ident
    < L > < E >  |  < E > , < L >

    Now, to complete the process...
    1. For each state in the LR(1) machine indicate which state in the LR(0) machine corresponds to the set of core items for the state from the LR(1) machine.
    2. Build the LALR(1) machine for the grammar.
    3. Is the grammar LALR(1)?
  2. The key to the correctness of an LR(0) parser is based on the theorem:
    Theorem 1
    The LR(0) finite state machine satisfies the property that [ N 1 . 2 ] LR(0) ( 0, )
    if and only if [ N 1 . 2 ]
    is valid for
    A similar result holds for the LR(1) machine:
    Theorem 2
    The LR(1) finite state machine satisfies the property that [ N 1 . 2, a ] LR(1) ( 0, )
    if and only if [ N 1 . 2, a ]
    is valid for

    The LALR(1) machine is formed by replacing the LR(0) items in each state of the LR(0) machine with the union of all the LR(1) items found in the states of the LR(1) machine that correspond to . That is, the set:

    { [ N 1 . 2 , x ] | for some ' in the LR(1) machine, [ N 1 . 2 , x ] ' & = core( ' ) }

    Using the definition of validity for LR(1) items, do the items in the states of the LALR(1) machine satisfy the same property as the items in the states of the LR(1) machine. In particular, for the LALR(1) machine is it the case that:

    1. [ N 1 . 2 ; a ] LALR(1) ( 0, ) if [ N 1 . 2 ; a] is valid for .
    2. [ N 1 . 2 ; a ] LALR(1) ( 0, ) only if [ N 1 . 2 ; a ] is valid for .
    Justify your answers with proofs or counter examples. You may assume the correctness of theorems 1 and 2 in your answer.

Computer Science 434
Department of Computer Science
Williams College