#Author: Josh Wretlind #Python Assignment #3 #Class: CSCI 410 - Elements of Computing Systems #Written in: Python 2.7 import sys,string,os from Parser import Parser infile = sys.argv[1] # Sys.argv is the system argument list object outfile = sys.argv[2] parse = Parser(infile) outfilecontents = "" while parse.hasMoreCommands(): parse.advance() outfilecontents += parse.output() output = open(outfile, 'w') output.write(outfilecontents) parse.stats()
from Code import Code from Symbol import Symbol infile = sys.argv[1] # Sys.argv is the system argument list object outfile = infile.replace(".asm", ".hack") parse = Parser(infile) outfilecontents = "" code = Code() sym = Symbol() i = 0 numOfNonLabelSymbols = 0 while parse.hasMoreCommands(): parse.advance() parse.output() parse.stripwhitespace() if len(parse.parsedline) != 0 and parse.parsedline != "\n" and parse.commandType() == 2: if not sym.contains(parse.symbol()): sym.addEntry(parse.symbol(), str(i)) if len(parse.parsedline) != 0 and parse.parsedline != "\n" and parse.commandType() != 2: i += 1 parse = Parser(infile) while parse.hasMoreCommands(): parse.advance() parse.output() parse.stripwhitespace() if ( len(parse.parsedline) != 0 and parse.parsedline != "\n"