lex を試す
#!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'PLUS', ) t_A = r'a' t_PLUS = r'\+' def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() lex.input("a+a") while 1: tok = lex.token() if not tok: break # No more input print tok
で、
LexToken(A,'a',1,0) LexToken(PLUS,'+',1,1) LexToken(A,'a',1,2)
訳の「プログラミングミスを補足」は「捕捉」の間違いか?