String evaluateExpression ( String expr ) throws ConfigEvaluatorException { ConfigExpressionScanner scanner = new ConfigExpressionScanner ( expr ) ; // Expression = Arithmetic | FilterCall // Arithmetic = Operand [( "+" | "-" | "*" | "/") Operand]* // Operand = VarName | Long | FunctionCall // VarName = <Java identifier plus "." after start> // Long = <[0-9]+ handled by Long.parseLong> // FunctionCall = FunctionName "(" VarName ")" // FunctionName = "count" // FilterCall = "servicePidOrFilter(" VarName ")" // Parse the first operand (or function name). if ( ! parseOperand ( expr , scanner , true ) ) { return null ; } if ( resultExpr != null ) { return scanner . end ( ) ? resultExpr : null ; } subtotal = value ; while ( ! scanner . end ( ) ) { // Parse operator. ConfigExpressionScanner . NumericOperator op = scanner . scanNumericOperator ( ) ; if ( op == null ) { return null ; } if ( ! parseOperand ( expr , scanner , false ) || ( resultExpr != null ) ) { return null ; } subtotal = op . evaluate ( subtotal , value ) ; } return String . valueOf ( subtotal ) ; }
Evaluate a variable expression .