November 2016
Intermediate to advanced
480 pages
14h 42m
English
You have seen that every call to a function that might throw an error must be marked with try and that any call with try must either be inside a do/catch block or inside a function that itself is marked with throws.
These rules work together to make sure you are handling any potential errors.
Try modifying your evaluate(_:) function to break one of these rules.
Listing 20.21 Modifying evaluate(_:) illegally
...
func evaluate(_ input: String) {
print("Evaluating: \(input)")
let lexer = Lexer(input: input)
let tokens = try lexer.lex()
do {
let tokens = try lexer.lex() print("Lexer output: \(tokens)") let parser = Parser(tokens: tokens) let result = try parser.parse() print("Parser ...Read now
Unlock full access