def main(): interpreter = Interpreter() while True: try: buffer = raw_input('serval> ') except EOFError: print break lexer = Lexer(buffer) try: expressions = Parser(lexer).parse() if not expressions: continue expression = expressions[0] if is_load(expression): load(interpreter, expression) continue result_expr = interpreter.interpret(expression) if procedure.is_compound_procedure(result_expr): print procedure.get_procedure_repr(result_expr) else: print result_expr except Exception as e: print str(e) continue
def _interpret(self, text, interpreter=None): from serval.lexer import Lexer from serval.parser import Parser from serval.interpreter import Interpreter from serval.expression.procedure import ( is_compound_procedure, get_procedure_repr) if interpreter is None: interpreter = Interpreter() expressions = Parser(Lexer(text)).parse() for expr in expressions: result_expr = interpreter.interpret(expr) if is_compound_procedure(result_expr): result = get_procedure_repr(result_expr) else: result = str(result_expr) return result
def _interpret(self, text, interpreter=None): from serval.lexer import Lexer from serval.parser import Parser from serval.interpreter import Interpreter from serval.expression.procedure import (is_compound_procedure, get_procedure_repr) if interpreter is None: interpreter = Interpreter() expressions = Parser(Lexer(text)).parse() for expr in expressions: result_expr = interpreter.interpret(expr) if is_compound_procedure(result_expr): result = get_procedure_repr(result_expr) else: result = str(result_expr) return result