I'm starting the Assembler and I'm just completely stuck. I can't even figure out what language I want to write it in. I have very little experience with file input and output. I have the most experience in Java, and minor experience in C and python. Python seemed to be a popular choice because of it's simplicity and many built in functions. But in any language I'm completely lost in how to deal with files.
I kind of have a general idea of what I need to do. I want to open the file, take each line and cut out all the junk like whitespace and comments and such. I'm not sure how to go about this, and what I do with the line after its been purged of junk. Do I put it in a new file that I later use to translate to machine code? Does it just modify the original input file?
Here's a simple Python program that copies one file to another file. If you are running on a Mac or Linux system it should already be able to run the python program from the command line. If you are running on windows see this post.
Note that the readline() functions returns an empty string at end-of-file.
Thanks for the example Mark! I've been playing around with it and I think I've made some progress. A new problem I can't seem to figure out with python is when I capture a line from the file and try to send it to another function I get the error "AttributeError: 'list' object has no attribute 'commandType' "
This is a bit of the code I'm using (python 2.7.6 on windows):
with open('add.asm') as fp:
for line in fp:
#do some stuff/checks
and I have a function named commandType that takes a parameter and checks what kind of command it is, but as soon as this function is called I get the error. I assumed that my line variable would just be a string, but maybe not?