Python lexical analyzer implementation