Hi.
I'm trying to make a simple Arduino calculator using only the serial monitor as the display and keyboard as input.
I have already made a code where i can calculate two numbers with one operator(+ , -, *, /), but i want to expand on that and try to make use of the String fuction to read the equation from the keyboard, and add the use of parentheses. The problem is that i don't know how to begin with the parentheses.
I was thinking of using the indexOf function to find the different operators, but this only finds the first or the last. Is there a function to find multiple operators in one string?
All help is appreciated!
P.S: The code as is can with a small adjustment only calculate to numbers and one operator.
This link gives a simplified idea of what's involved in parsing arithmetic expressions (in the examples, the numbers can only be single digits).
The section marked "Parsing an Infix Expression with Parentheses" handles parenthesized expressions in the form we are normally used to.
The section marked "Code for Calculating with the Postfix Algorithm" handles very simplified Reverse-Polish Notation expressions.
Whether you use parenthesized infix or RPN, you have to implement a stack. It is easier to require the input to be in RPN form because your code doesn't have to "know" about operator precedence. But, of course, if you use RPN, you would be limiting the number of people who can use your project to those who are reasonably "fluent" in RPN