<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def lex(self, text, start=0):
 """Lexically analyze `text`. Yields pairs (`name`, `tokentext`). """

        max = len(text)
        eaten = start
        s = self.state
        r = self.regexes
        toks = self.toks
        while eaten < max:
            for match in r[s].finditer(text, eaten):
                name = match.lastgroup
                tok = toks[name]
                toktext = match.group(name)
                eaten += len(toktext)
                yield (tok.name, toktext)

                if tok.next:
                    s = tok.next
                    break

        self.state = s