Unable to handle a String contains textual Operator
A java infix evaluator based on "Shunting Yard" algorithm.
Brought to you by:
fathzer
I am following the guide to create a evaluator with textual operators:
http://javaluator.sourceforge.net/en/doc/tutorial.php?chapter=textualOperators
It works fine following the guide.
But if the value in the map variableToValue contains the String "AND", the evaluator returns unexpected result. See the test code below:
public static void main(String[] args) {
Map<String,String> variableToValue = new HashMap<String, String>();
variableToValue.put("type", "PORT AND A");
AbstractEvaluator<Boolean> evaluator = new TextualOperatorsEvaluator();
System.out.println ("type='PORT AND A' AND true -> "+evaluator.evaluate("type='PORT AND A' AND true", variableToValue));
}
It prints:
type='PORT AND A' AND true -> false
Anonymous
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Is there any way to escape the Operator?
Hi,
The problem is with the protected Iterator<string> tokenize(String expression).
It should cut the expression into tokens following your own grammar.
The example in the tutorial states the tokens are separated by blank character, but it is not the case in the example you have.
So you'll have to write a customized tokenize method that would return the following tokens in your example:
type=PORT AND A
AND
* true
If you need quote and escaped quote, you should handle these customizations yourself, sorry.
Best regards,
Jean-Marc Astesana</string>
Last edit: Fathzer 2017-12-29
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Hi,
Thank you for your message. I finally resolve it by replacing the value that contains the operator with a String, and put the value in the map with the replaced String as the key. And then during evaluating the operands, I get the value from the map and use the value as the operand.
Regards,
Wenyuan