from Lex import Lex, ARITHMETIC_COMMANDS, PUSH_OR_POP_COMMANDS

class Parser:
    def __init__(self, src_file_name):
        self._line_index = 0


        self._line_index = 0
        self._lines = []

        f = open(src_file_name)
        # First assesment of the Assembler
        for line in f.readlines():
            strip_line = line.lstrip()
            # Skipping none relevant
            if len(strip_line) == 0 or strip_line[0:2] == '//':
                continue
            #l = strip_line.replace(' ', '') # Removing whitespace
            l = strip_line.replace('\n', '')  # Removing new line
            l = l.replace('\t', '') # Removing tabs
            l = l.split('/')[0] # Removing comments

            self._lines.append(l)

    def current_command(self):
        curr_line = self._lines[self._line_index]
        return curr_line.split(" ")[0]

    def advance(self):
        self._line_index+=1

    def has_more_command(self):
        return len(self._lines) > self._line_index

    def command_type(self):
        command = self.current_command()
        if command in PUSH_OR_POP_COMMANDS:
            return Lex.C_PUSH_OR_POP
        if command in ARITHMETIC_COMMANDS:
            return Lex.C_ARITMETIC

        raise Exception("Command Type not found in line = {}".format(curr_line))


    def arg1(self):
        curr_line = self._lines[self._line_index]
        return curr_line.split(" ")[1]

    def arg2(self):
        curr_line = self._lines[self._line_index]
        return curr_line.split(" ")[2]

from Lex import Lex, ARITHMETIC_COMMANDS, PUSH_OR_POP_COMMANDS

class Parser:
    def __init__(self, src_file_name):
        self._line_index = 0


        self._line_index = 0
        self._lines = []

        f = open(src_file_name)
        # First assesment of the Assembler
        for line in f.readlines():
            strip_line = line.lstrip()
            # Skipping none relevant
            if len(strip_line) == 0 or strip_line[0:2] == '//':
                continue
            #l = strip_line.replace(' ', '') # Removing whitespace
            l = strip_line.replace('\n', '')  # Removing new line
            l = l.replace('\t', '') # Removing tabs
            l = l.split('/')[0] # Removing comments

            self._lines.append(l)

    def current_command(self):
        curr_line = self._lines[self._line_index]
        return curr_line.split(" ")[0]

    def advance(self):
        self._line_index+=1

    def has_more_command(self):
        return len(self._lines) > self._line_index

    def command_type(self):
        command = self.current_command()
        if command in PUSH_OR_POP_COMMANDS:
            return Lex.C_PUSH_OR_POP
        if command in ARITHMETIC_COMMANDS:
            return Lex.C_ARITMETIC

        raise Exception("Command Type not found in line = {}".format(curr_line))


    def arg1(self):
        curr_line = self._lines[self._line_index]
        return curr_line.split(" ")[1]

    def arg2(self):
        curr_line = self._lines[self._line_index]
        return curr_line.split(" ")[2]

# First assesment of the Assembler # Skipping none relevant #l = strip_line.replace(' ', '') # Removing whitespace # Removing new line # Removing tabs # Removing comments