Esempio n. 1
0
def cross_check():
    import python_yacc
    import python_lex
    python_lex.BACKWARDS_COMPATIBLE = True
    python_yacc.BACKWARDS_COMPATIBLE = True

    text = """
a | 1 ^ 9
b ^ 2 & 8
c & 3 | 7
d << 4 >> 3
e >> 5 << -1
f+g*9
h*i**10
j/k//3
m%n+1
o//p+4

"""
    #text = open("/usr/local/lib/python2.6/decimal.py").read()
    text = open("sample.py").read()
    my_output = None
    try:
        import time
        t1 = time.time()
        my_tree = python_yacc.parse(text)
        t2 = time.time()
        print "Parse time", t2-t1
        my_output = str(my_tree)
    except NotImplementedError, x:
        import traceback
        traceback.print_exc()
Esempio n. 2
0
def execfile(source_filename):
    text = open(source_filename).read()
    tree = python_yacc.parse(text, source_filename)
    code = codegen(tree)
    mod = types.ModuleType("__main__", tree.doc)
    setattr(mod, "__file__", source_filename)
    sys.modules["__main__"] = mod
    exec code in mod.__dict__
Esempio n. 3
0
def execfile(source_filename):
    text = open(source_filename).read()
    tree = python_yacc.parse(text, source_filename)
    code = codegen(tree)
    mod = types.ModuleType("__main__", tree.doc)
    setattr(mod, "__file__", source_filename)
    sys.modules["__main__"] = mod
    exec code in mod.__dict__
Esempio n. 4
0
def compile_file(source_filename, pyc_filename=None):
    if pyc_filename is None:
        pyc_filename = source_filename + "c"

    text = open(source_filename).read()
    mtime = os.path.getmtime(source_filename)
    tree = python_yacc.parse(text, source_filename)
    code = codegen(tree)
    
    save_bytecode(code, pyc_filename, mtime)
Esempio n. 5
0
def compile_file(source_filename, pyc_filename=None):
    if pyc_filename is None:
        pyc_filename = source_filename + "c"

    text = open(source_filename).read()
    mtime = os.path.getmtime(source_filename)
    tree = python_yacc.parse(text, source_filename)
    code = codegen(tree)
    
    save_bytecode(code, pyc_filename, mtime)
Esempio n. 6
0
	def change_in_text(self):
		self.ui.button_save.setEnabled(True)
		text = self.ui.editor_window.toPlainText()
		if text[-1:] == ' ' or text[-1:] == '\t' or text[-1:] == '\n':
			try:
				tree = python_yacc.parse(str(self.ui.editor_window.toPlainText()), self.filename)
			except SyntaxError as e:
				print 'Syntax Error'
				# podkreslenie bledu
			except IndentationError:
				print 'Indentation Error'
Esempio n. 7
0
__author__ = 'xu'
from PModule import PModule
from Compiler import *
import python_yacc
import sys
#compile function in python
#a function can be compiled directly means:
#(1)this function has no args
#(2)this function won't use variable out of the function block
if len(sys.argv) > 1:
	filename = sys.argv[1]
else:
	filename = "test9.py"
test_file = open(filename)
content = test_file.read()
print content
comp = python_yacc.parse(content, "result.py")
print comp
module = Module.new("main")
executor = ExecutionEngine.new(module)
module._set_data_layout(executor.target_data.__str__())
module._set_target("x86_64-pc-linux-gnu")
compiler = Compiler("main.ll", module)
pmodule = PModule(comp, compiler, "main")
pmodule.compile()

writer = open(filename[0:-2] + "ll", mode="w")
pmodule.compiler.output(writer)
#compiler.output(writer)