Evaluate the function in the statement and return the result. :return: The result of the function
(self, category)
| 1413 | self.__relexpr() |
| 1414 | |
| 1415 | def __evaluate_function(self, category): |
| 1416 | """Evaluate the function in the statement |
| 1417 | and return the result. |
| 1418 | |
| 1419 | :return: The result of the function |
| 1420 | |
| 1421 | """ |
| 1422 | |
| 1423 | self.__advance() # Advance past function name |
| 1424 | |
| 1425 | # Process arguments according to function |
| 1426 | if category == Token.RND: |
| 1427 | return random.random() |
| 1428 | """ |
| 1429 | if category == Token.PI: |
| 1430 | return math.pi |
| 1431 | |
| 1432 | if category == Token.RNDINT: |
| 1433 | self.__consume(Token.LEFTPAREN) |
| 1434 | |
| 1435 | self.__expr() |
| 1436 | lo = self.__operand_stack.pop() |
| 1437 | |
| 1438 | self.__consume(Token.COMMA) |
| 1439 | |
| 1440 | self.__expr() |
| 1441 | hi = self.__operand_stack.pop() |
| 1442 | |
| 1443 | self.__consume(Token.RIGHTPAREN) |
| 1444 | |
| 1445 | try: |
| 1446 | return random.randint(lo, hi) |
| 1447 | |
| 1448 | except ValueError: |
| 1449 | raise ValueError("Invalid value supplied to RNDINT in line " + |
| 1450 | str(self.__line_number)) |
| 1451 | """ |
| 1452 | if category == Token.MAX: |
| 1453 | self.__consume(Token.LEFTPAREN) |
| 1454 | |
| 1455 | self.__expr() |
| 1456 | value_list = [self.__operand_stack.pop()] |
| 1457 | |
| 1458 | while self.__token.category == Token.COMMA: |
| 1459 | self.__advance() # Advance past comma |
| 1460 | self.__expr() |
| 1461 | value_list.append(self.__operand_stack.pop()) |
| 1462 | |
| 1463 | self.__consume(Token.RIGHTPAREN) |
| 1464 | |
| 1465 | try: |
| 1466 | return max(*value_list) |
| 1467 | |
| 1468 | except TypeError: |
| 1469 | raise TypeError("Invalid type supplied to MAX in line " + |
| 1470 | str(self.__line_number)) |
| 1471 | |
| 1472 | if category == Token.MIN: |