traverse AST and dump CExpr nodes
This commit is contained in:
parent
854b82e088
commit
13fbaea4d1
14
Compiler.py
Normal file
14
Compiler.py
Normal file
@ -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')
|
11
jtlc
11
jtlc
@ -7,6 +7,9 @@ import tempfile
|
|||||||
from subprocess import *
|
from subprocess import *
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import parser
|
||||||
|
from Compiler import Compiler
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
parser = argparse.ArgumentParser(prog = 'jtlc',
|
parser = argparse.ArgumentParser(prog = 'jtlc',
|
||||||
description = "Josh's Toy Language Compiler")
|
description = "Josh's Toy Language Compiler")
|
||||||
@ -45,9 +48,15 @@ def main(argv):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def build(args, source, dest):
|
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):
|
def do_compile(args, source_fname, ofname):
|
||||||
|
Popen(['grep', '-n', '.', source_fname]).wait()
|
||||||
Popen(['gcc', '-o', ofname, '-c', source_fname]).wait()
|
Popen(['gcc', '-o', ofname, '-c', source_fname]).wait()
|
||||||
|
|
||||||
def do_link(args, ofiles):
|
def do_link(args, ofiles):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user