             }
         }
         
-        func evaluateRPN(characters: SequenceOf<Character>) -> SequenceOf<Int> {
-            return lazySequence { yield in
+        func evaluate(tokens: SequenceOf<Token>) -> SequenceOf<Int> {
+            return lazySequence { _yield in
+
+                func yield(result: Int) {
+                    trace("evaluate", "yield(\(result))")
+                    _yield(result)
+                }
+                
                 var stack = Stack<Int>()
-                for token in tokenize(characters) {
+                for token in tokens {
+                    trace("evaluate", "next token is \(token)")
+                    
                     switch token {
                         
                     case .Integer(let value):
+                        trace("evaluate", "push(\(value))")
                         stack.push(value)
                         
                     case .Plus:
                         let a = stack.pop()
                         let b = stack.pop()
-                        stack.push(a + b)
+                        let sum = a + b
+                        trace("evaluate", "pop \(a) and \(b); push sum \(sum)")
+                        stack.push(sum)
                         
                     case .Multiply:
                         let a = stack.pop()
                         let b = stack.pop()
-                        stack.push(a * b)
+                        let product = a * b
+                        trace("evaluate", "pop \(a) and \(b); push product \(product)")
+                        stack.push(product)
                         
                     case .GetResult:
                         let result = stack.pop()
+                        trace("evaluate", "pop \(result)")
                         yield(result)
                     }
                 }
             }
         }
         
-        // Auxiliary function to convert a String to a sequence of character values
-        func evaluateRPNString(string: String) -> SequenceOf<Int> {
-            return evaluateRPN(SequenceOf(string.generate()))
-        }
-        
         // Should generate the results [3, 200, 30] (1+2, 10*20, (1+2)*10)
-        let results = evaluateRPNString("1 2 + =  10 20 * =  1 2 + 10 * =")
+        let inputString = "1 2 + =  10 20 * =  1 2 + 10 * ="
+        let results = evaluate(tokenize(characterSequenceFromString(inputString)))
         
         let resultsArray = Array<Int>(results)
         XCTAssertEqual(3, resultsArray.count)

        //
        // The implementation uses two lazy sequences:
        //
        // - The tokenizer reads a sequence of characters to lazily produce a sequence of tokens
        // - The parser reads the sequence of tokens to lazily produce a sequence of expression results
        //
        // This use of two sequences makes it easy to keep the tokenizer's state machine separate
        // from the parser's state machine without tokenizing the entire input before passing it to
        // the parser. (The tokenizer and parser run on separate background threads.)
        //
        // This test simply parses a string, but this could be combined with code from testAsyncReadFileByLine()
        // to add another layer of lazy evaluation.
        
        enum Token {
            case Integer(Int)
            case Multiply
            case Plus
            case GetResult
        }
        
        struct Stack<T> {
            var values = Array<T>()
            

            }
        }
        
        func characterSequenceFromString(string: String) -> SequenceOf<Character> {
            trace("characterSequenceFromString", "create character sequence")
            return SequenceOf(string.generate())
        }
        
        // Returns sequence of tokens scanned from character sequence
        func tokenize(characters: SequenceOf<Character>) -> SequenceOf<Token> {
            enum ScannerState {
                case LookingForToken
                case ScanningInteger
            }
            
            return lazySequence { _yield in
                
                func yield(token: Token) {
                    trace("tokenize", "yield(\(token))")
                    _yield(token)
                }
                
                var state = ScannerState.LookingForToken
                var scannedIntegerDigits = ""
                
                func yieldScannedInteger() {
