Skip to content

Commit

Permalink
Improved terminal input and printing
Browse files Browse the repository at this point in the history
Multiple calculations can now be calculated after each other, quit with "q" or "quit"
Removed RPN printing from terminal
  • Loading branch information
domenicw committed Jan 15, 2018
1 parent e59733c commit 9b207cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions Calculator/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
}

4 changes: 2 additions & 2 deletions Interpreter/Interpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 9b207cb

Please sign in to comment.