Evaluates a numerical expression and leaves its value on top of the operand stack.
(self)
| 992 | self.__operand_stack.append(leftoperand % rightoperand) |
| 993 | |
| 994 | def __factor(self): |
| 995 | """Evaluates a numerical expression |
| 996 | and leaves its value on top of the |
| 997 | operand stack. |
| 998 | |
| 999 | """ |
| 1000 | if self.__token.category == Token.PLUS: |
| 1001 | self.__advance() |
| 1002 | self.__factor() |
| 1003 | |
| 1004 | elif self.__token.category == Token.MINUS: |
| 1005 | self.__sign = -self.__sign |
| 1006 | self.__advance() |
| 1007 | self.__factor() |
| 1008 | |
| 1009 | elif self.__token.category == Token.UNSIGNEDINT: |
| 1010 | self.__operand_stack.append(self.__sign*int(self.__token.lexeme)) |
| 1011 | self.__advance() |
| 1012 | |
| 1013 | elif self.__token.category == Token.UNSIGNEDFLOAT: |
| 1014 | self.__operand_stack.append(self.__sign*float(self.__token.lexeme)) |
| 1015 | self.__advance() |
| 1016 | |
| 1017 | elif self.__token.category == Token.STRING: |
| 1018 | self.__operand_stack.append(self.__token.lexeme) |
| 1019 | self.__advance() |
| 1020 | |
| 1021 | elif self.__token.category == Token.NAME and \ |
| 1022 | self.__token.category not in Token.functions: |
| 1023 | # Check if this is a simple or array variable |
| 1024 | if (self.__token.lexeme + '_array') in self.__symbol_table: |
| 1025 | # Capture the current lexeme |
| 1026 | arrayname = self.__token.lexeme + '_array' |
| 1027 | |
| 1028 | # Array must be processed |
| 1029 | # Capture the index variables |
| 1030 | self.__advance() # Advance past the array name |
| 1031 | |
| 1032 | try: |
| 1033 | self.__consume(Token.LEFTPAREN) |
| 1034 | except RuntimeError: |
| 1035 | raise RuntimeError('Array used without index in line ' + |
| 1036 | str(self.__line_number)) |
| 1037 | |
| 1038 | indexvars = [] |
| 1039 | if not self.__tokenindex >= len(self.__tokenlist): |
| 1040 | self.__expr() |
| 1041 | indexvars.append(self.__operand_stack.pop()) |
| 1042 | |
| 1043 | while self.__token.category == Token.COMMA: |
| 1044 | self.__advance() # Advance past comma |
| 1045 | self.__expr() |
| 1046 | indexvars.append(self.__operand_stack.pop()) |
| 1047 | |
| 1048 | BASICarray = self.__symbol_table[arrayname] |
| 1049 | arrayval = self.__get_array_val(BASICarray, indexvars) |
| 1050 | |
| 1051 | if arrayval != None: |
no test coverage detected