package com.judong.chuanyiserver.util;

import com.mpobjects.bdparsii.eval.Expression;
import com.mpobjects.bdparsii.eval.Parser;
import com.mpobjects.bdparsii.eval.Scope;
import com.mpobjects.bdparsii.eval.Variable;
import com.mpobjects.bdparsii.tokenizer.ParseException;

import java.math.BigDecimal;

public class MathUtil {

    /**
     * 四则混合运算
     */
    public static BigDecimal quadricOperation(String parameter, String MathString, Long value) throws ParseException {
        Scope scope = new Scope();
//        Variable a = scope.getVariable("BBC");
//        Expression expr = Parser.parse("-2*(BBC+25)+2/7+18*2^2", scope);
        Variable a = scope.getVariable(parameter);
        Expression expr = Parser.parse(MathString, scope);
        a.setValue(value);
        return expr.evaluate();
    }
}
