while line: while line == '\n' or line.startswith('//'): line = readfile.readline() if '//' in line: line = line[:line.find('//')] if '/*' in line: aline = line[:line.find('/*')] while line.find('*/') < 0: line = readfile.readline() bline = line[line.find('*/') + 2:] line = aline + bline copyfile.write(line) line = readfile.readline() copyfile.close() readfile.close() readCopyFile = open('copyfile', 'r') writeXmlFile = open(filename.strip('.jack') + '.xml', 'w') writeVmFile = open(filename.strip('.jack') + '.vm', 'w') outputCompile = CompilationEngine.Compile(readCopyFile, writeXmlFile, writeVmFile) outputCompile.compileClass() readCopyFile.close() writeXmlFile.close() writeVmFile.close() os.remove('copyfile') if option != '-x': os.remove(filename.strip('.jack') + '.xml')
filename = sys.argv[1] readfile = open(filename, 'r') #clear all the // /* ... notes, create a new file to save the result copyfile = open('copyfile', 'w') line = readfile.readline() while line: while line == '\n' or line.startswith('//'): line = readfile.readline() if '//' in line: line = line[:line.find('//')] if '/*' in line: aline = line[:line.find('/*')] while line.find('*/') < 0: line = readfile.readline() bline = line[line.find('*/') + 2:] line = aline + bline copyfile.write(line) line = readfile.readline() copyfile.close() readfile.close() rfile = open('copyfile', 'r') wfile = open(filename.strip('.jack') + '.xml', 'w') outputCompile = CompilationEngine.Compile(rfile, wfile) outputCompile.compileClass() rfile.close() wfile.close() os.remove('copyfile')