Hello, i am currently writing an assembler for the theoretical SIC/xe machine and i decided to do it in python.
Very new to python but i thought it would be fund to do it in and willing to learn. So far i know what to do and have the diea except i cannot implement it in python code yet. I can do it in java or c++.
Basically i want to parse through the source.txt file and since the source is made with 3 columns i decide to split by tab and match there.
here is my sample code
def main():
comment = "."
SYMTAB = {"START":' ', "BYTE":" ","WORD":" ", "RESB":" ","RESW":" ","END":" ","BASE":" ","NOBASE":" "}
OPTAB = {"ADDR":" ", "COMPR":" ", "SUBR":" ", "ADD":" ", "SUB":" ", "MUL":" ", "DIV":" ", "COMP":" ", "J":" ", "JEQ":" ", "JGT":" ",
"JLT":" ", "JSUB":" ", "LDA":" ", "LDB":" ", "LDCH":" ", "LDL":" ", "LDT":" ", "LDX":" ", "RSUB":" ", "TIX":" ", "TIXR":" ", "RD":" ", "TD":" ", "WD":" ",
"STA":" ", "STB":" ", "STCH":" ", "STL":" ", "STX":" ", "CLEAR":" "}
inf = open("source.txt", 'rU')
outf = open ("temp.txt", 'w')
LOCCTR = 0
lines = inf.readlines()
for line in lines:
if line.find("START") > -1:
about = line.split()
outf.write(about[2])
LOCCTR = about[2]
for line in lines:
while line.find("END") < -1:
print line
outf.close()
inf.close()
return 0
if __name__ == '__main__':
main()
I would like to know how to iterate better through lines with python.
Please ask me more questions if necessary
i have attached a sample source.txt file as well so you can see how it is. As you can see its separated in 3 columns but sometimes the first column is empty.