# Path: pycell/chars_in_file.py
# def chars_in_file(f):
#     """
#     Provides an iterator through all the characters in a file, individually.
#     """
#     assert_implements(f, Readable)
#     ch = f.read(1)
#     while ch != "":
#         yield ch
#         ch = f.read(1)
# 
# Path: pycell/env.py
# class Env:
#     def __init__(self, parent=None, stdin=None, stdout=None, stderr=None):
#         """
#         Supply _either_ std{in,out,err} _or_ parent, not both.
#         """
#         self.stdin = stdin
#         self.stdout = stdout
#         self.stderr = stderr
#         self.parent = parent
#         if parent is not None:
#             assert stdin is None
#             assert stdout is None
#             assert stderr is None
#             self.stdin = parent.stdin
#             self.stdout = parent.stdout
#             self.stderr = parent.stderr
#         self.items = {}
# 
#     def get(self, name):
#         if name in self.items:
#             return self.items[name]
#         elif self.parent is not None:
#             return self.parent.get(name)
#         else:
#             return None
# 
#     def set(self, name, value):
#         self.items[name] = value
# 
#     def contains(self, name):
#         return name in self.items
# 
#     def __str__(self):
#         ret = ""
#         for k, v in self.items.items():
#             ret += "%s=%s\n" % (k, v)
#         ret += ".\n" + str(self.parent)
#         return ret
# 
# Path: pycell/lexer.py
# def lex(chars_iter):
#     chars = PeekableStream(chars_iter)
#     while chars.next is not None:
#         c = chars.move_next()
#         if c in " \n":              pass           # Ignore white space
#         elif c in "(){},;=:":       yield (c, "")  # Special characters
#         elif c in "+-*/":           yield ("operation", c)
#         elif c in ("'", '"'):       yield ("string", _scan_string(c, chars))
#         elif re.match("[.0-9]", c): yield ("number", _scan(c, chars, "[.0-9]"))
#         elif re.match("[_a-zA-Z]", c):
#             yield ("symbol", _scan(c, chars, "[_a-zA-Z0-9]"))
#         elif c == "\t":
#             raise Exception("Tab characters are not allowed in Cell.")
#         else:
#             raise Exception("Unrecognised character: '" + c + "'.")
# 
# Path: pycell/parser.py
# def parse(tokens_iterator):
#     parser = Parser(PeekableStream(tokens_iterator), ";")
#     while parser.tokens.next is not None:
#         p = parser.next_expression(None)
#         if p is not None:
#             yield p
#         parser.tokens.move_next()


import pycell.library
from pycell.chars_in_file import chars_in_file
from pycell.env import Env
from pycell.lexer import lex
from pycell.parser import parse
        return compile_function_def(expr, env, indent)
    elif typ == "assignment":
        return compile_assignment(expr, env, indent)
    elif typ == "call":
        return compile_call(expr, env, indent)
    elif typ == "operation":
        return compile_operation(expr, env, indent)
    else:
        raise Exception("Compiling unknown type '%s'." % str(expr))


def compile_list(exprs, env, indent=0, return_last = False):
    ret = ""
    lst_exprs = list(exprs)
    for i, expr in enumerate(lst_exprs):
        ret += " " * indent
        if return_last and i == len(lst_exprs) - 1:
            ret += "return "
        ret += compile_expr(expr, env, indent)
        ret += ";\n"
    return ret


def compile_(output, filename):
    env = Env()
    with open(output, "w") as outfile:
        outfile.write(
            compile_list(parse(lex(pycell.library.as_text(env))), env))
        with open(filename, encoding="ascii") as infile:
            outfile.write(

# Path: pycell/chars_in_file.py
# def chars_in_file(f):
#     """
#     Provides an iterator through all the characters in a file, individually.
#     """
#     assert_implements(f, Readable)
#     ch = f.read(1)
#     while ch != "":
#         yield ch
#         ch = f.read(1)
# 
# Path: pycell/env.py
# class Env:
#     def __init__(self, parent=None, stdin=None, stdout=None, stderr=None):
#         """
#         Supply _either_ std{in,out,err} _or_ parent, not both.
#         """
#         self.stdin = stdin
#         self.stdout = stdout
#         self.stderr = stderr
#         self.parent = parent
#         if parent is not None:
#             assert stdin is None
#             assert stdout is None
#             assert stderr is None
#             self.stdin = parent.stdin
#             self.stdout = parent.stdout
#             self.stderr = parent.stderr
#         self.items = {}
# 
#     def get(self, name):
#         if name in self.items:
#             return self.items[name]
#         elif self.parent is not None:
#             return self.parent.get(name)
#         else:
#             return None
# 
#     def set(self, name, value):
#         self.items[name] = value
# 
#     def contains(self, name):
#         return name in self.items
# 
#     def __str__(self):
#         ret = ""
#         for k, v in self.items.items():
#             ret += "%s=%s\n" % (k, v)
#         ret += ".\n" + str(self.parent)
#         return ret
# 
# Path: pycell/lexer.py
# def lex(chars_iter):
#     chars = PeekableStream(chars_iter)
#     while chars.next is not None:
#         c = chars.move_next()
#         if c in " \n":              pass           # Ignore white space
#         elif c in "(){},;=:":       yield (c, "")  # Special characters
#         elif c in "+-*/":           yield ("operation", c)
#         elif c in ("'", '"'):       yield ("string", _scan_string(c, chars))
#         elif re.match("[.0-9]", c): yield ("number", _scan(c, chars, "[.0-9]"))
#         elif re.match("[_a-zA-Z]", c):
#             yield ("symbol", _scan(c, chars, "[_a-zA-Z0-9]"))
#         elif c == "\t":
#             raise Exception("Tab characters are not allowed in Cell.")
#         else:
#             raise Exception("Unrecognised character: '" + c + "'.")
# 
# Path: pycell/parser.py
# def parse(tokens_iterator):
#     parser = Parser(PeekableStream(tokens_iterator), ";")
#     while parser.tokens.next is not None:
#         p = parser.next_expression(None)
#         if p is not None:
#             yield p
#         parser.tokens.move_next()


# Path: pycell/compile_.py
import pycell.library
from pycell.chars_in_file import chars_in_file
from pycell.env import Env
from pycell.lexer import lex
from pycell.parser import parse

        return compile_function_def(expr, env, indent)
    elif typ == "assignment":
        return compile_assignment(expr, env, indent)
    elif typ == "call":
        return compile_call(expr, env, indent)
    elif typ == "operation":
        return compile_operation(expr, env, indent)
    else:
        raise Exception("Compiling unknown type '%s'." % str(expr))


def compile_list(exprs, env, indent=0, return_last = False):
    ret = ""
    lst_exprs = list(exprs)
    for i, expr in enumerate(lst_exprs):
        ret += " " * indent
        if return_last and i == len(lst_exprs) - 1:
            ret += "return "
        ret += compile_expr(expr, env, indent)
        ret += ";\n"
    return ret


def compile_(output, filename):
    env = Env()
    with open(output, "w") as outfile:
        outfile.write(
            compile_list(parse(lex(pycell.library.as_text(env))), env))
        with open(filename, encoding="ascii") as infile:
            outfile.write(

                compile_list(parse(lex(chars_in_file(infile))), env))