import lexical_analyzer

class Parser():
        
    def __init__(self):
        self.lexemes = []
        self.lookahead = None
    
    def nextLexeme(self):
        if self.lexemes:
            self.lookahead = self.lexemes.pop(0)
            #print(self.lookahead[1])
            
    def assert_next(self, expected_value, error_message):
        if self.lookahead[0] == expected_value:
            self.nextLexeme()
        else:
            print(error_message + ' before ' + self.lookahead[1])
    
    def assert_delimiter(self):
        self.assert_next('SEMICOLON_KEYWORD', 'expected semicolon')
            
    def check_next(self, expected_values):
        if len(expected_values) == 1:
            return self.lookahead[0] == expected_values[0]
        for value in expected_values:
            if self.lookahead[0] == value:
                return True
        return False

    def parse(self, lexemes):
        self.lexemes = lexemes