# Programming a Truth Table

• 09-26-2002
Nitelite
Programming a Truth Table
I am trying to create a program that prompts the user to input 2 Equations, do a truth table, then compare them. Most of it is within my ability, but what I am struggling with is the parsing of the inputted equations. For example:

F1 = !A * !B + A * B + !A * B F2 = !A + B

For something like this, I just made a char pointer that scans through the string looking for multiplication, doing that first, then the addition. My problem is parsing and getting the order of operations down for something like this:

F1 = !A * B (!C * !A * C) + B (A + !A * C)
F2 = !((A + !B*!C + C) * ( B * C + !A + A * !B * !C))

So how would you parse something with parenthensis. Not necessarily asking for help with code, more theory in breaking this down into proper operational order.

Thanks guys
• 09-26-2002
Cshot
Simple. Everytime you encounter an open parantheses '(' simply keep track of where you are parsing. Then when you encounter a closed parantheses ')', calculate your logic up to the previous '(' and treat the problem as you would in your 1st example.
• 09-26-2002
quzah
Recursion. Any time you see an opening parenthesis, make a recursive call. Any time you see a closing parenthesis, make a return call. Otherwise, loop using standard mathmatics.

Damnit! Stop beating me to the reply! :D[/edit]

Quzah.