Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The parser for reading ILOC instruction files.
- import sys
- from util import Instruction
- class ILOCParser(object):
- """
- A parser for ILOC instruction files.
- """
- def __init__(self, file):
- self.inputFile = open(file)
- def parse(self):
- instructionList = []
- for line in self.inputFile:
- if line[-1] == "\n":
- line = line[:-1]
- if "//" in line:
- line = line[:line.index("//")] # remove comments
- line = line.strip() # strip whitespace at beginning and end
- if line == "": # line has no instructions
- continue
- line = line.replace(",", " ") # remove commas
- line = line.replace("=>", " ") # remove arrows
- line = line.split()
- instructionList.append(Instruction(line[0], line[1:]))
- return instructionList
Add Comment
Please, Sign In to add comment