Untitled

mail@pastecode.io avatar
unknown
python
4 years ago
493 B
1
Indexable
Never
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,')')