MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / __term

Method __term

PyBasic/basicparser.py:967–992  ·  view source on GitHub ↗

Parses a numerical expression consisting of two factors being multiplied together, leaving the result on the operand stack.

(self)

Source from the content-addressed store, hash-verified

965 self.__operand_stack.append(leftoperand - rightoperand)
966
967 def __term(self):
968 """Parses a numerical expression consisting
969 of two factors being multiplied together,
970 leaving the result on the operand stack.
971
972 """
973 self.__sign = 1 # Initialise sign to keep track of unary
974 # minuses
975 self.__factor() # Leaves value of term on top of stack
976
977 while self.__token.category in [Token.TIMES, Token.DIVIDE, Token.MODULO]:
978 savedcategory = self.__token.category
979 self.__advance()
980 self.__sign = 1 # Initialise sign
981 self.__factor() # Leaves value of term on top of stack
982 rightoperand = self.__operand_stack.pop()
983 leftoperand = self.__operand_stack.pop()
984
985 if savedcategory == Token.TIMES:
986 self.__operand_stack.append(leftoperand * rightoperand)
987
988 elif savedcategory == Token.DIVIDE:
989 self.__operand_stack.append(leftoperand / rightoperand)
990
991 else:
992 self.__operand_stack.append(leftoperand % rightoperand)
993
994 def __factor(self):
995 """Evaluates a numerical expression

Callers 1

__exprMethod · 0.95

Calls 2

__factorMethod · 0.95
__advanceMethod · 0.95

Tested by

no test coverage detected