How to perform Expression Evaluation in C++
-
Write a simple expression evaluator that takes a string like the following as input: 1+2*(3+4). -Only integers need to be supported -The following operators should be supported: +, -, *. -Expressions within parenthesis should be evaluated first. -Then the resulting expressions should be evaluated from left to right (no operator precedence) -Example: 4+(4-(2*3)+1)+4 = 7 The code should be written in such a way to support additional operators. Assume the existence of a function tokenise, which could take a string and return an array of strings, for instance tokenise(‘1+(2*3)+4’) would return [‘1’,’+’,’(‘,’2’,’*’,’3’,’)’,’+’,’4’] and the functions isNumber and asNumber which would return a Boolean and integer respectively on a single string input.
-
Write a simple expression evaluator that takes a string like the following as input: 1+2*(3+4). -Only integers need to be supported -The following operators should be supported: +, -, *. -Expressions within parenthesis should be evaluated first. -Then the resulting expressions should be evaluated from left to right (no operator precedence) -Example: 4+(4-(2*3)+1)+4 = 7 The code should be written in such a way to support additional operators. Assume the existence of a function tokenise, which could take a string and return an array of strings, for instance tokenise(‘1+(2*3)+4’) would return [‘1’,’+’,’(‘,’2’,’*’,’3’,’)’,’+’,’4’] and the functions isNumber and asNumber which would return a Boolean and integer respectively on a single string input.
Your homework should serve the purpose that you learn something. And that something isn't supposed to be how to get other people to doing your homework for you. Your assignments will get more difficult over time - so if you don't start doing them yourself now you'll never be able to. So sit down, think about it and try something. If you then encounter a specific problem, feel free to ask - that's the idea of these forums. Also, there are a lot of articles here on CodeProject about expression evaluation. Take a look at those if you struggle to find a starting point.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
Write a simple expression evaluator that takes a string like the following as input: 1+2*(3+4). -Only integers need to be supported -The following operators should be supported: +, -, *. -Expressions within parenthesis should be evaluated first. -Then the resulting expressions should be evaluated from left to right (no operator precedence) -Example: 4+(4-(2*3)+1)+4 = 7 The code should be written in such a way to support additional operators. Assume the existence of a function tokenise, which could take a string and return an array of strings, for instance tokenise(‘1+(2*3)+4’) would return [‘1’,’+’,’(‘,’2’,’*’,’3’,’)’,’+’,’4’] and the functions isNumber and asNumber which would return a Boolean and integer respectively on a single string input.
-
Write a simple expression evaluator that takes a string like the following as input: 1+2*(3+4). -Only integers need to be supported -The following operators should be supported: +, -, *. -Expressions within parenthesis should be evaluated first. -Then the resulting expressions should be evaluated from left to right (no operator precedence) -Example: 4+(4-(2*3)+1)+4 = 7 The code should be written in such a way to support additional operators. Assume the existence of a function tokenise, which could take a string and return an array of strings, for instance tokenise(‘1+(2*3)+4’) would return [‘1’,’+’,’(‘,’2’,’*’,’3’,’)’,’+’,’4’] and the functions isNumber and asNumber which would return a Boolean and integer respectively on a single string input.
Big list of resource for you. There is good stuff there! ;) language agnostic - Learning to write a compiler - Stack Overflow[^]
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!