Today I have a question that I had on my mind for years now.
Consider you have the following evaluation in Java:
new EvaluationListener(){
public boolean evaluate(boolean[] b){
return b[0] || b[1];
}
}
I am using this code in my program for evaluating terms of different boolean values of b[0] and b[1], but that doesn't matter at all here.
At the moment I am writing the evaluations into the source code, let the program run and watch the result in the command line.
Now I am wondering how I could implement the evaluation into command line. I would like to be able to enter an evaluation term into the command line, read it with BufferedReader etc. instead of writing it into the source code.
Is there any way to do so? I thought it would be possible by using some sort of variable aliases like $b0$. But how can I pass logical OR and AND and NOT to the program?
Thanks for your answer
Here's an example of expression evaluation with Java's script API:
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("ECMAScript");
scriptEngine.put("b1", true);
scriptEngine.put("b2", false);
System.out.println(scriptEngine.eval("b1 || b2"));
System.out.println(scriptEngine.eval("b1 && b2"));
When run, this code prints:
true
false