Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Calc1
#python 3.6.9 # ------------------------------------------------------------ # calclex.py # # tokenizer for a simple expression evaluator for # numbers and +,-,*,/ # ------------------------------------------------------------ import ply.lex as lex # List of token names. This is always required tokens = ( 'NUMBER', 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'LPAREN', 'RPAREN', 'RESIDUO', 'GUIONES', 'NUMDEC', 'IGUAL', 'VAR' ) # Regular expression rules for simple tokens t_PLUS = r'\+' t_MINUS = r'-' t_TIMES = r'\*' t_DIVIDE = r'/' t_LPAREN = r'\(' t_RPAREN = r'\)' t_RESIDUO = r'\%' t_GUIONES = r'====' t_ignore = ' \t' # A string containing ignored characters (spaces and tabs) def t_VAR(t): r'[a-zA-Z][a-zA-Z0-9]*' return t def t_IGUAL(t): r'=' return t def t_NUMDEC(t) : r'[-+]?\d+\.\d+' t.value = float(t.value) return t def t_NUMBER(t): r'\d+' t.value = int(t.value) return t # Define a rule so we can track line numbers def t_newline(t): r'\n+' t.lexer.lineno += t.value.count('\n') # Error handling rule def t_error(t): print("Illegal character '%s'" % t.value[0]) t.lexer.skip(1) # Build the lexer lexer = lex.lex() # --- Probar el lexer construido data1 ="Var23 = 40 + 89.23" lexer.input(data1) # Tokenize while True: tok = lexer.token() if not tok: break """ more = input("teclee mas expresiones: ") if not more: break lexer.input(more) """ print(tok)
run
|
edit
|
history
|
help
0
PyDeque
Atur Cara Mizan 2
Celcius to Fahrenheit
S
Python mehrfachvererbung
binary
pip install pyowm==2.7.1
PyEnDecode
PyLSV
Multi-Layer Neural Networks