enum Symbol {

    asNonterminal: Nonterminal

    asTerminal: Terminal

}


struct Item {

    getLHS: Nonterminal

    getLeft: ListOf Symbol

    getRight: ListOf Symbol

}


canonical_collection: C0 := extern


states: ListOf (SetOf Item)

{

    return (canonical_collection.states)

}


goto(state: State, symbol: Symbol): Maybe State

{

    return (canonical_collection.goto(state, symbol))

}    


goto'(state: State, sentential_form: ListOf Symbol): Maybe State

{

    for (i: Int := 0; sentential_form[i] != Nil; i++)

    {

        state := goto(state, sentential_form[i])

        if (state == Nothing)

            break

    }

    return state

}


getPRED(state: State, sentential_form: ListOf Symbol): SetOf Symbol

{

    result: SetOf Symbol := empty

    for (state' in canonical_collection.states)

    {

        switch (goto'(state', sentential_form))

        {

        case (Just state''):

            if (state == state'')

            {

                result := insert(result, state'')

            }

            break

        case Nothing:

        }

    }

    return result

}


getLA(state: State, item: Item): SetOf Terminal

{

    if (state == state0 && item == Item { getLHS := s', getLeft := [], getRight := [asNonterminal s] })

    {

        return (singleton(EOF))

    }

    else

    {

        result: SetOf Terminal := empty

        for (state' in getPRED(state, item.getLeft))

        {

            for (item' in state')

            {

                if (item'.getRight[0] == item.getLHS)

                {

                    result := union(result, getFIRST(&item'.getRight[1]) <+> getLA(state', item'))

                }

            }

        }

        return result

    }

}