def __unary(self, num): if num == 37: x = Not(self.cache[0], self.cache[1]) elif num == 38: x = Unary(Token(Tag.MINUS), self.cache[1]) else: x = self.cache[0] self.__value_stack.append(x)
def offset(self, a): _type = a.type self.match("[") i = self._bool() self.match("]") _type = _type.of w = Constant(_type.width) t1 = Arith(Token("*"), i, w) loc = t1 while self.look.tag == "[": self.match("[") i = self._bool() self.match("]") _type = _type.of w = Constant(_type.width) t1 = Arith(Token("*"), i, w) t2 = Arith(Token("+"), loc, t1) loc = t2 return Access(a, loc, _type)
def __offset(self, a): # 处理数组 if isinstance(a, Access): # 多维数组 _type = a.type.of w = Constant(_type.width) i = self.cache[2] t1 = Arith(Token(Tag.MULTIPLICATIONOPERATOR), i, w) t2 = Arith(Token(Tag.ADDITIONOPERATOR), a.index, t1) access = Access(a.array, t2, _type) # # 判断越界(编译时无法实现) # if self.cache[2].value >= a.type.size: # self.__error(a.toString()+' out of range') else: _type = a.type.of w = Constant(_type.width) i = self.cache[2] t1 = Arith(Token(Tag.MULTIPLICATIONOPERATOR), i, w) access = Access(a, t1, _type) # # 判断越界(编译时无法实现) # if self.cache[2].value >= a.type.size: # self.__error(a.toString()+' out of range') return access
def __arith_com_2(self): if self.__cache == '+': return Token(Tag.ADDITIONOPERATOR) elif self.__cache == '-': return Token(Tag.SUBTRACTIONOPERATOR) elif self.__cache == '*': return Token(Tag.MULTIPLICATIONOPERATOR) elif self.__cache == '/': return Token(Tag.DIVISIONOPERATOR) elif self.__cache == '!': return Token(Tag.LOGICNOT) elif self.__cache == '<': return Token(Tag.LESS) elif self.__cache == '=': return Token(Tag.ASSIGNMENTOPERATOR) else: return Token(Tag.GREATER)
def __fail(self): return Token(Tag.ERROR)
def __end(self): return Token(Tag.END)
def __delimit(self): res = self.delimiter.index(self.__ch) self.__ch = self.__nextchar() return Token(Tag(res + self.delimiter_num))