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

def addtoken(self, type, value, context):

    ilabel = self.classify(type, value, context)
    while True:
        (dfa, state, node) = self.stack[(-1)]
        (states, first) = dfa
        arcs = states[state]
        for (i, newstate) in arcs:
            (t, v) = self.grammar.labels[i]
            if (ilabel == i):
                self.shift(type, value, newstate, context)
                state = newstate
                while (states[state] == [(0, state)]):
                    self.pop()
                    if (not self.stack):
                        return True
                    (dfa, state, node) = self.stack[(-1)]
                    (states, first) = dfa
                return False
            if (t >= 256):
                itsdfa = self.grammar.dfas[t]
                (itsstates, itsfirst) = itsdfa
                if (ilabel in itsfirst):
                    self.push(t, self.grammar.dfas[t], newstate, context)
                    break
        else:
            if ((0, state) in arcs):
                self.pop()
                if (not self.stack):
                    raise ParseError('too    much    input', type, value, context)
            else:
                raise ParseError('bad    input', type, value, context)
