Guest User

Untitled

a guest
May 27th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. # The parser for reading ILOC instruction files.
  2. import sys
  3. from util import Instruction
  4.  
  5. class ILOCParser(object):
  6. """
  7. A parser for ILOC instruction files.
  8. """
  9. def __init__(self, file):
  10. self.inputFile = open(file)
  11.  
  12. def parse(self):
  13. instructionList = []
  14. for line in self.inputFile:
  15. if line[-1] == "\n":
  16. line = line[:-1]
  17. if "//" in line:
  18. line = line[:line.index("//")] # remove comments
  19. line = line.strip() # strip whitespace at beginning and end
  20. if line == "": # line has no instructions
  21. continue
  22. line = line.replace(",", " ") # remove commas
  23. line = line.replace("=>", " ") # remove arrows
  24. line = line.split()
  25. instructionList.append(Instruction(line[0], line[1:]))
  26. return instructionList
Add Comment
Please, Sign In to add comment