diff --git a/Calculator/main.swift b/Calculator/main.swift index c54202a..f5f089c 100644 --- a/Calculator/main.swift +++ b/Calculator/main.swift @@ -8,12 +8,20 @@ import Foundation -let text = readLine() +let quit: [String] = ["q", "quit"] -if let text = text { +while true { + + print("> ", separator: "", terminator: "") + + let txt = readLine() + + guard let text = txt, !quit.contains(text.lowercased()) else { + break + } + let interpreter = Interpreter(text) + print(">> = ", separator: "", terminator: "") print(interpreter.interpret()) -} else { - fatalError("Error: no input!") + print("") } - diff --git a/Interpreter/Interpreter.swift b/Interpreter/Interpreter.swift index ce00115..f4a3166 100644 --- a/Interpreter/Interpreter.swift +++ b/Interpreter/Interpreter.swift @@ -105,8 +105,8 @@ class Interpreter { */ public func interpret() -> Int { let tree = self.parser.parse() - let rpn = RPN(tree) - rpn.print() + //let rpn = RPN(tree) + //rpn.print() return self.eval(tree) }