def main_of_analizer(jackfilename):

    #getting jack file name
    (jfilename, jextension) = os.path.splitext(jackfilename)
    jackxml = jfilename + ".xml"  #just to be consistent with the book

    compiler = CompilationEngine(jackfilename, jackxml)
Пример #2
0
def main():
    files = []
    in_path = sys.argv[1]
    if os.path.isfile(in_path):
        print('main: in: file')
        in_file_name = os.path.basename(in_path)
        files.append(in_path)
    else:
        print('main: in: directory')
        for entry in os.scandir(in_path):
            if entry.path.endswith('.jack'):
                files.append(entry.path)
                
    for in_f in files:
        out_file_path = make_out_file_path(in_f)
        print(f'compiling file: {in_f}')
        print(f'out: {out_file_path}')
        tokenizer = JackTokenizer(in_f)  
        compilation_engine = CompilationEngine(tokenizer, out_file_path)
        compilation_engine.compile_class()
Пример #3
0
    def run(self):

        if isdir(self.path_source):
            directory_file_list  = listdir(self.path_source)
            for f in directory_file_list :
                if f.endswith(".jack") :
                    tok = JackTokenizer(self.path_source + '/' + f)
                    vmw   = VMWriter(self.path_source  + '/' \
                                        + f.partition('.')[0] + '.vm')
                    eng = CompilationEngine(tok,vmw)
                    eng.compile_class()
        else :
            if f.endswith(".jack") :
                tok = JackTokenizer(self.path_source + '/' + f)
                vmw   = VMWriter(self.path_source  + '/' \
                                    + f.partition('.')[0] + '.vm')
                eng = CompilationEngine(tok,vmw)
                eng.compile_class()
Пример #4
0
#------------------------------------------------------------------------------
# Main:
#------------------------------------------------------------------------------

if fullCompiler: #if option was ommited meaning full compilation
	if is_dir: #if it is a directory compile all '*.jack' files
		for d in directory:
			#strips '.jack' off the end and adds '.vm'
			temp_out = re.search('(.*)(\.jack)',d)
			out_file = temp_out.group(1)+'.vm'

			#prints out what file it is compiling at the moment
			print("Compiling: "+d+"....")

			compiler = CompilationEngine(d,out_file)
			compiler.compileClass()

	else: #if not a directory
		compiler = CompilationEngine(in_file,out_file)
		compiler.compileClass()

else: #option for tokenized output selected
	if is_dir: #if it is a directory
		for d in directory:
			#Strips '.jack' off the end and adds '2.xml'
			temp_out = re.search('(.*)(\.jack)',d)
			out_file = temp_out.group(1)+'2.xml'

			compilerxml = CompilationEngineXML(d,out_file)
			compilerxml.compileClass()