we have two-dimensional array of ints:
int[][] XYZ = new int[][]{
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 2, 3, 4, 5, 6, 7, 8 },
{ 8, 7, 6, 5, 4, 3, 2, 1 },
{ 2, 2, 2, 2, 2, 2, 2, 2 },
{ 1, 2, 3, 4, 5, 6, 7, 8 }
};
and a String:
String zapytanie = "((XYZ[i][0]==3 && XYZ[i][1]==4) || (XYZ[i][1]==3 || XYZ[i][2]==7))"
Query is generated dynamiccly and passed to String.
what i want to do is parse this String in for without adding external tools/components.
for(int i=0;i<XYZ.length;i++)
{
//todo parse here this expression
}
we want to find all rows that match query in the String and return them.
My problem is i do not know how to parse String into Query. Like removing this " " from String zapytanie and execute it.
I'm pretty sure i can not use eval, but still new thing to learn so i tried it :)
first imported
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
Second
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
for(int i=0;i<XYZ.length;i++)
{
engine.eval(zapytanie);
}
error: ReferenceError: "XYZ" is not defined.
Any idea how to fix that error, and can you tell me other methods to do the task without using javascript here?
I made a post-order tree from my query, but i was wondering is there a faster way, then using this tree:
a is XYZ[i][0], b is XYZ[i][1] and so on.
from zapytanie = ((a=3 and b=4) or (b=3 or c=7))
https://i.stack.imgur.com/IwGVT.png
And i do not know how to use this tree smart way