Example #1
0
    def eval(self):
        tempLeft = self.left.eval()
        tempRight = self.right.eval()
        
        if(not isinstance(tempLeft,int)):
            raise sbml_lexer.SyntaxError()
        if(not isinstance(tempRight,tuple)):
            raise sbml_lexer.SyntaxError()
        
        count = 0
        for item in tempRight:
            count = count + 1
        if ((count)<tempLeft):
            raise sbml_lexer.SemanticError()

        count2 = 1
        for item in tempRight:
            if count2==tempLeft:
                return item
            count2 = count2 + 1
    def eval(self):
        tempLeft = self.left.eval()

        tempRight = self.right

        #if in stack
        if (len(stack) > 0):
            if (type(tempRight) != list):
                if (tempRight in stack[len(stack) - 1]["names"]):
                    tempRight = stack[len(stack) - 1]["names"][tempRight]
            else:
                if (tempRight in stack[len(stack) - 1]["names"].values()):
                    tempRight = stack[len(stack) - 1]["names"][tempRight]
        #if in names
        if (type(tempRight) != list):
            if (tempRight in names):
                tempRight = names[tempRight]
            else:
                tempRight = self.right.eval()
        else:
            if (tempRight in names.values()):
                tempRight = names[tempRight]
            else:
                tempRight = self.right.eval()

        if (not isinstance(tempLeft, int)):
            raise sbml_lexer.SyntaxError()
        if (not isinstance(tempRight, tuple)):
            raise sbml_lexer.SyntaxError()

        count = 0
        for item in tempRight:
            count = count + 1
        if ((count) < tempLeft):
            raise sbml_lexer.SemanticError()

        count2 = 1
        for item in tempRight:
            if count2 == tempLeft:
                return item
            count2 = count2 + 1
def p_error(p):
    raise sbml_lexer.SyntaxError(Exception)