'Add a token; return True if this is the end of the program.'

def addtoken(self, type_, value, start_pos, prefix):

    ilabel = token_to_ilabel(self.grammar, type_, value)
    _gram = self.grammar
    _labels = _gram.labels
    _push = self._push
    _pop = self._pop
    _shift = self._shift
    while True:
        (dfa, state, node) = self.stack[(-1)]
        (states, first) = dfa
        arcs = states[state]
        for (i, newstate) in arcs:
            (t, v) = _labels[i]
            if (ilabel == i):
                assert (t < 256)
                _shift(type_, value, newstate, prefix, start_pos)
                state = newstate
                while (states[state] == [(0, state)]):
                    _pop()
                    if (not self.stack):
                        return True
                    (dfa, state, node) = self.stack[(-1)]
                    (states, first) = dfa
                return False
            elif (t >= 256):
                itsdfa = _gram.dfas[t]
                (itsstates, itsfirst) = itsdfa
                if (ilabel in itsfirst):
                    _push(t, itsdfa, newstate)
                    break
        else:
            if ((0, state) in arcs):
                _pop()
                if (not self.stack):
                    raise InternalParseError('too    much    input', type_, value, start_pos)
            else:
                self.error_recovery(self.grammar, self.stack, arcs, type_, value, start_pos, prefix, self.addtoken)
                break
