How to handle order of operations in a calculator app

I am currently working on a calculator app for my first independent project. Still need to smooth out some edges (my class for math operations only works with doubles), but my main issue is that my app can only process one expression at a time. What’s the best way to handle the order of operations when parsing user input? Do I need to create a mini lexical analyzer to tokenize the expressions?

Use change event in javascript and use eval function to calculate. however be careful with eval function.

or

you can use infix to postfix algorithm to calculate (recommended)

My first project was also a calculator and I probably did it the worst way possible, I didn’t want to use eval and I had never heard of infix/postfix at the time so I used a lot of regular expressions to turn everything into addition and subtraction and then solve it in order, example pseudocode:

user input is 2 + 2 * 5 - 1
start while loop to replace multiplication with its result
regex finds 2
* 5 in the string, result is 10
turn the operation string into 2 + 10 - 1
while loop breaks because there is no longer a multiplication sign in the string
start solving in order, following the pattern [number, operator, number]
operation string is now 12 - 1
solve it again
result is 11

This doesn’t feel very efficient though and it’s a bit of a mess so I think it’s better to follow @thisisbatman0901 advice and learn infix to postfix algorithm

I’m doing this project in Java, but I’ll definitely look into the infix to postfix algorithm. It’ll probably be easier than trying to use a recursive parser, which is one thing I considered. Grammar rules and lexical analyzers are a pretty weak point of mine and not something I’m very interested in anyway.