Lexical analyzer in python