'From the input stream, predict what alternative will succeed
using this DFA (representing the covering regular approximation
to the underlying CFL).  Return an alternative number 1..n.  Throw
an exception upon error.'

def predict(self, input):

    mark = input.mark()
    s = 0
    try:
        for _ in xrange(50000):
            specialState = self.special[s]
            if (specialState >= 0):
                s = self.specialStateTransition(specialState, input)
                if (s == (-1)):
                    self.noViableAlt(s, input)
                    return 0
                input.consume()
                continue
            if (self.accept[s] >= 1):
                return self.accept[s]
            c = input.LA(1)
            if ((c >= self.min[s]) and (c <= self.max[s])):
                snext = self.transition[s][(c - self.min[s])]
                if (snext < 0):
                    if (self.eot[s] >= 0):
                        s = self.eot[s]
                        input.consume()
                        continue
                    self.noViableAlt(s, input)
                    return 0
                s = snext
                input.consume()
                continue
            if (self.eot[s] >= 0):
                s = self.eot[s]
                input.consume()
                continue
            if ((c == EOF) and (self.eof[s] >= 0)):
                return self.accept[self.eof[s]]
            self.noViableAlt(s, input)
            return 0
        else:
            raise RuntimeError('DFA    bang!')
    finally:
        input.rewind(mark)
