         
         do {
             while !isAtEnd() {
-                statements.append(try statement())
+                if let declaration = try declaration() {
+                    statements.append(declaration)
+                }
             }
         } catch {
             return nil


        if match(.number, .string) {
            return Expr.Literal(value: previous().literal)
        }

        if match(.leftParen) {


    private func expression() throws -> Expr {
        return try equiality()
    }
    
    private func declaration() throws -> Stmt? {
        do {
            if match(.Var) {
                return try varDeclaration()
            }
            
            return try statement()
        } catch Error.parseFailure {
            synchronize()
            return nil // Recovered from error mode. Return nil and continue parsing.
        }
    }
    
    private func statement() throws -> Stmt {
