def test_two(self):
        expression = '((42) + 21 - (96 * 32) / 4998673)'

        actual = stringify_tokens(tokenize_expression(expression))
        expected = '((42)+21-(96*32)/4998673)'

        self.assertEqual(actual, expected)
    def test_one(self):
        expression = '1 + 2'

        actual = stringify_tokens(tokenize_expression(expression))
        expected = '1+2'

        self.assertEqual(actual, expected)
Example #3
0
def parse_infix_to_postfix(infix_expression):
    tokens = tokenize_expression(infix_expression)
    return stringify_tokens(infix_to_postfix(tokens), delim=' ')
Example #4
0
def parse_and_eval(infix_expression):
    return eval_postfix(infix_to_postfix(tokenize_expression(infix_expression)))
Example #5
0
# pylint: disable=import-error
from expression_tokenizer import tokenize_expression, stringify_tokens, Token
from notation_conversion import infix_to_postfix
from postfix_evaluation import eval_postfix

expression = input('Enter an arithmetic expression: ')

infix_tokens = tokenize_expression(expression)
postfix_tokens = infix_to_postfix(infix_tokens)
result = eval_postfix(postfix_tokens).value

print(result)