Esempio n. 1
0
 def _firstParse(self):
     for line in self._f:
         # remove the newline char '\n'
         line = line.strip()
         # check if there is parseable code in line
         if not fh.isCommentOrEmpty(line):
             line = fh.removeInlineComments(line)
             # update the clean code string
             self._code += line
Esempio n. 2
0
 def parse(self, asmLogicFunc):
     for line in self._f:
         # remove the newline char '\n'
         line = line.strip()
         # remove whitespaces from lines
         line = fh.removeSpaces(line)
         # check if there is parseable code in line
         if not fh.isCommentOrEmpty(line):
             # apply assembly logic to it
             asmLogicFunc(line)
     # reset the file cursor to the start of file
     self._f.seek(0)
Esempio n. 3
0
 def parse(self):
     for line in self._f:
         # remove the newline char '\n'
         line = line.strip()
         # check if there is parseable code in line
         if not fh.isCommentOrEmpty(line):
             line = fh.removeInlineComments(line)
             # split commands from the line
             commands = line.split(" ")
             # get the type of command
             cmdtype = cf.commandType(commands[0])
             # if it's a push or pop command handle it
             if cmdtype == PUSH or cmdtype == POP:
                 self._handlePushPop(commands, cmdtype)
             # else if it's a arithmetic command handle it
             elif cmdtype == ARITHMETIC:
                 self._handleArithmetic(commands)
Esempio n. 4
0
 def parse(self):
     for line in self._f:
         # remove the newline char '\n'
         line = line.strip()
         # check if there is parseable code in line
         if not fh.isCommentOrEmpty(line):
             writeStr = ""
             # remove in-line comments from each line
             line = fh.removeInlineComments(line)
             # split commands from the line
             commands = line.split(" ")
             # get the type of command
             cmdtype = self._cf.commandType(commands[0])
             # if it's a push or pop command handle it
             if cmdtype == PUSH or cmdtype == POP:
                 writeStr = self._handlePushPop(commands, cmdtype)
             # else if it's a arithmetic command handle it
             elif cmdtype == ARITHMETIC:
                 writeStr = self._handleArithmetic(commands)
             # else if it's a label command handle it
             elif cmdtype == LABEL:
                 writeStr = self._cf.writeLabelAsm(commands[1])
             # else if it's a goto command handle it
             elif cmdtype == GOTO:
                 writeStr = self._cf.writeGotoAsm(commands[1])
             # else if it's a if-goto command handle it
             elif cmdtype == IF:
                 writeStr = self._cf.writeIfGotoAsm(commands[1])
             # else if it's a call command handle it
             elif cmdtype == CALL:
                 writeStr = self._cf.writeCallAsm(commands[1], int(commands[2]))
             # else if it's a return command handle it
             elif cmdtype == RETURN:
                 writeStr = self._cf.writeReturnAsm()
             # else if it's a function command handle it
             elif cmdtype == FUNCTION:
                 writeStr = self._cf.writeFunctionAsm(commands[1], int(commands[2]))
             # add it to the code list
             self._codeList.append(writeStr)
             print(line)
             print(self._codeList)