def exp(self): return Real(decimal_math.exp(self._as_decimal())) def log(self): return Real(decimal_math.log(self._as_decimal()))
t.lexer.skip(1) # Build the lexer lex.lex() # Parsing rules precedence = ( ('left','PLUS','MINUS'), ('left','TIMES','DIVIDE'), ('right','UMINUS'), ('right','RAISE_TO'), ) names = {'e': exp(Decimal(1)), 'pi': pi(), '_last': Decimal(0)} reserved_names = ['e','pi','_last'] def p_statement_assign(t): 'statement : NAME EQUALS expression' if t[1] in reserved_names: print "Name %s reserved" % t[1] else: names[t[1]] = t[3] def p_set_last_to(t): 'statement : SET_TO NAME' if t[2] in reserved_names: print "Name %s reserved" % t[2] else: names[t[2]] = names['_last']
t.lexer.skip(1) # Build the lexer lex.lex() # Parsing rules precedence = ( ('left', 'PLUS', 'MINUS'), ('left', 'TIMES', 'DIVIDE'), ('right', 'UMINUS'), ('right', 'RAISE_TO'), ) names = {'e': exp(Decimal(1)), 'pi': pi(), '_last': Decimal(0)} reserved_names = ['e', 'pi', '_last'] def p_statement_assign(t): 'statement : NAME EQUALS expression' if t[1] in reserved_names: print "Name %s reserved" % t[1] else: names[t[1]] = t[3] def p_set_last_to(t): 'statement : SET_TO NAME' if t[2] in reserved_names: print "Name %s reserved" % t[2]