diff --git a/Compiler.py b/Compiler.py new file mode 100644 index 0000000..41f809b --- /dev/null +++ b/Compiler.py @@ -0,0 +1,14 @@ + +from parser.nodes import * + +class Compiler(object): + def __init__(self): + pass + + def compile(self, ast, out): + ast.visit(self.first_pass, out) + + def first_pass(self, node, out): + if isinstance(node, CExprNode): + out.write(node.cstring) + out.write('\n') diff --git a/jtlc b/jtlc index 0795227..b4964f3 100755 --- a/jtlc +++ b/jtlc @@ -7,6 +7,9 @@ import tempfile from subprocess import * import re +import parser +from Compiler import Compiler + def main(argv): parser = argparse.ArgumentParser(prog = 'jtlc', description = "Josh's Toy Language Compiler") @@ -45,9 +48,15 @@ def main(argv): return 0 def build(args, source, dest): - dest.write('hi\n') + f = open(source, 'r') + contents = f.read() + f.close() + result = parser.parse(contents) + c = Compiler() + c.compile(result, dest) def do_compile(args, source_fname, ofname): + Popen(['grep', '-n', '.', source_fname]).wait() Popen(['gcc', '-o', ofname, '-c', source_fname]).wait() def do_link(args, ofiles):