how to convert logic operation stored as a string to bool ?

J

Jakub Bednarczuk

Hi everybody

I am trying to find the solution for the problem stated in the topic,
but so far without any result.
Let's see the problem.

I have set of conditions and the description (logical sentence) how
should be these conditions connected with each other. See how does it
look in xml

<root>
<conditions>
<condition term = '1'/>
<condition term = '2'/>
</conditions>
<logicOperation>(#1 and #2)</logicOperation>
</root>

I store the conditions results in bool array. How can I get the
logicOperation result having (#1 and #2) as a string ?

I already converted the given logicOperation into the form (true &&
false). However it is still string, and the during the converting to
bool sample is impossible.

I have the idea to loop thru all "true" and "false" strings and
converting them to bool. The problem is how to store logicOperation
during transformation. I mean: How to store (true && false) where true
is of bool type and false is of string type? I think it is impossible.

Maybe someone of you have the tricky idea how to do it ?

Thanks in advance
Jakub
 
B

Bruce Wood

Jakub said:
Hi everybody

I am trying to find the solution for the problem stated in the topic,
but so far without any result.
Let's see the problem.

I have set of conditions and the description (logical sentence) how
should be these conditions connected with each other. See how does it
look in xml

<root>
<conditions>
<condition term = '1'/>
<condition term = '2'/>
</conditions>
<logicOperation>(#1 and #2)</logicOperation>
</root>

I store the conditions results in bool array. How can I get the
logicOperation result having (#1 and #2) as a string ?

I already converted the given logicOperation into the form (true &&
false). However it is still string, and the during the converting to
bool sample is impossible.

I have the idea to loop thru all "true" and "false" strings and
converting them to bool. The problem is how to store logicOperation
during transformation. I mean: How to store (true && false) where true
is of bool type and false is of string type? I think it is impossible.

Maybe someone of you have the tricky idea how to do it ?

There is no tricky way in C# that I know of. You have to write your own
little parser and expression evaluation class. Fortunately, it's not
that difficult....
 
B

Ben Voigt

Bruce Wood said:
There is no tricky way in C# that I know of. You have to write your own
little parser and expression evaluation class. Fortunately, it's not
that difficult....
If the xml schema is changed to represent an AST, then parsing strings won't
be necessary either.

something like:

<root>
<nodes>
<condition term="1"/>
<condition term="2"/>
<condition term="3"/>
<expression term="out1" logicOperation="and">
<input term="1"/>
<input term="2"/>
</expression>
<expression term="tmp1" logicOperation="or">
<input term="1"/>
<input term="2"/>
</expression>
<expression term="out2" logicOperation="and">
<input term="3"/>
<input term="tmp1"/>
</expression>
</nodes>
</root>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top