Equation (expression) parser with precedence?

前端 未结 23 1789
遇见更好的自我
遇见更好的自我 2020-11-22 11:44

I\'ve developed an equation parser using a simple stack algorithm that will handle binary (+, -, |, &, *, /, etc) operators, unary (!) operators, and parenthesis.

<
23条回答
  •  -上瘾入骨i
    2020-11-22 12:40

    Here is a simple case recursive solution written in Java. Note it does not handle negative numbers but you can do add that if you want to:

    public class ExpressionParser {
    
    public double eval(String exp){
        int bracketCounter = 0;
        int operatorIndex = -1;
    
        for(int i=0; i

    }

提交回复
热议问题