Myself and a few others have been tasked with creating a Truth Table Generator for our first year project. We have a vast majority of the work done, save for a few things, most important of which being the function that actually converts statements (Ex: p V q) into boolean truth values.
Is it possible to convert a string statement with proper c++ argument syntax, such as "(p || !q)" (p and q being pre-defined variables with respective values) directly into a condition?
We've considered the route of many conditional statements based on what we can find via string analysis and operating on the variables based on findings, but I was wondering if there was a much more efficient way to actually code this. The code is designed to take pretty much any input for a truth table statement, convert it into proper c++ syntax, and separate the statement into components. That being said, there are quite a few options to account for if we were to do this via finding certain elements and operating on them with if-then or switch statements. If there is a more efficient route, I am open to suggestions and welcome any criticism of our process.
As a visual demonstration, this is what we were thinking of:
bool p=1, q=0;
string test= "(!p || q)"; // would supposedly return 0 if analyzed as a conditional statement
cout << endl << "Truth Table Generator Test" << endl;
cout << "p = " << p << endl << "q = " << q << endl;
cout << test << " = " << truthVal(test) // Used to signify the conversion from string to condition
Supposed output:
Truth Table Generator Test
p = 1
q = 0
(!p || q) = 0