def analyze_term(self, overlookSet): downOverlookSet = overlookSet[:] V_term = VN.create(const.TERM) factor = self.analyze_factor(overlookSet) V_term.append(factor) while self.pointer.isStarOperator(): star = self.pointer self.getsym() factor = self.analyze_factor(overlookSet) V_term.append(star).append(factor) self.emit(Instruction.create(star)) # 此处结束后没有检查!!!直接返回 return self.checkEmpty(V_term)
def analyze_condition(self, overlookSet = [const.R_BRACE]): downOverlookSet = overlookSet[:] V_condition = VN.create(const.CONDITION) expression = self.analyze_expression(overlookSet) V_condition.append(expression) if self.pointer.isRelationOperator(): relationOperator = self.pointer V_condition.append(relationOperator) self.getsym() V_condition.append(self.analyze_expression(overlookSet)) # 结束后将逻辑运算符入栈 self.emit(Instruction.create(relationOperator)) # 这里结束后没有检查,直接返回 return self.checkEmpty(V_condition)
def analyze_expression(self, overlookSet): downOverlookSet = overlookSet[:] V_expression = VN.create(const.EXPRESSION) plus = False # 如果开头就有符号,那么肯定是 -x 或者 +x ,默认操作数为0 if self.pointer.isPlusOperator(): plus = self.pointer V_expression.append(plus) self.getsym() # 操作数 0 入栈 self.emit(Instruction(Instruction.LOC, '0', False)) term = self.analyze_term(overlookSet) # 如果有操作符,那么生成加或减指令 self.emit(Instruction.create(plus)) V_expression.append(term) while self.pointer.isPlusOperator(): plus = self.pointer self.getsym() term = self.analyze_term(overlookSet) V_expression.append(plus).append(term) self.emit(Instruction.create(plus)) # 此处结束后没有检查!!!直接返回 return self.checkEmpty(V_expression)