Untitled
unknown
python
5 years ago
493 B
4
Indexable
import ply.lex as lex tokens = ['DATE'] t_DATE = r'([0-2][0-9]|3[0-1]) \- (0[1-9]|1[0-2]) \- ([1-2][0-9][0-9][0-9])' def t_error(t): print("Error: %s" % repr(t.value[0])) t.lexer.skip(1) def t_newline(t): r'\n' t.lexer.lineno+=1 __file__ = "Ej01.ipynb" lexer = lex.lex() data=input('Ingrese cadena: ') lexer.input(data) print('Token - Lexema') while True: tok = lexer.token() if not tok: break print('(',tok.type, ',',tok.value,')')
Editor is loading...