Having multiple lists of integers, like e.g.:
var p1 = new[] { 3, 9, 5, 8, 9 };
var p2 = new[] { 12, 1, 18, 27, 103, 99, 4 };
var p3 = new[] { 23, 930, 15 };
// ...
I want to concatenate them with logical AND and OR operations, like e.g.:
var result = p1 AND p2 OR p3 ...
AND should have higher precedence than OR. The result is again a list.
Definitions:
a OR bshould take integers that are present in either listaor inb, resulting in a list.a AND bshould take only integers that are present both in listaand inb, resulting in a list.
What makes this complicated to solve for me is that the number of lists (and their content) is defined by the user during runtime, as well as the operators on how to concatenate the lists.
I.e. the user might define 5 lists and concatenate them like p1 OR p2 AND p3 AND p4 OR p5 or the user might define 2 lists and concatenate them like p1 AND p2. Or he might as well define 20 list and concatenate them with an arbitrary combination of AND and OR, too.
Solution attempt
My first approach was to get some C# formula parser and introduce my own operator (like AND and OR, or at least overload * as AND and + as OR).
Unfortunately, I couldn't find one; the closest I came across was Mages by Florian Rappl, which seems to not support overloading of operators.
Now, I'm out of ideas. I fear that I possibly have to define my own grammar and have to write a lexer or something other complicated (to me).
My question
I am looking for ideas on how to solve this. Maybe there are completely other ways beside my formular parser idea.