I have a program in C that solves the circuit satisfiability with MPI. The circuit can contain AND,OR and NOT gates.
In my program the circuit is “hard coded” as it follows:
( v[0] || v[1] ) && ( !v[1] || !v[3] ) && ( v[2] || v[3] )
with mapping: || = OR, && = AND, ! = NOT
v[0], v[1], etc is an array of 0 and 1
At some point, i evaluate the circuit like this:
value = ( v[0] || v[1] ) && ( !v[1] || !v[3] ) && ( v[2] || v[3] );
I want to test multiple circuits which are read from a text file.
Now, my question is: How can i convert from string to logical expression in C?
Basically, i want something like value = ‘string from file here’.
Any suggestions?
Ok. I’ve modified
Shunting-Yardalgo for working with boolean expressions.Here’s code for evaluating boolean expressions:
Just put
&/|symbols in logical expresion instead of double&&/||.