I wrote one of these a while back: <a href="http://knot.appspot.com/e/simple-python-scanner" rel="nofollow">http://knot.appspot.com/e/simple-python-scanner</a><p>For his example, it needs one more line:<p><pre><code> simple = Scan(
IDENTIFIER = r'[\w_]\w*',
OPERATOR = r'[-+\*=]',
DIGIT = r'\d+(\.\d+)?',
END_STATEMENT = r';',
SPACE = r'\s+',
)
simple.ignore('SPACE')
simple('foo = 5 * 30; bar = bar - 60;')
# generates tokens.</code></pre>