How can I build a Truth Table Generator?

Posted by KingNestor on Stack Overflow See other posts from Stack Overflow or by KingNestor
Published on 2009-07-05T21:40:44Z Indexed on 2010/05/14 20:24 UTC
Read the original article Hit count: 306

I'm looking to write a Truth Table Generator as a personal project.

There are several web-based online ones here and here.

alt text
(Example screenshot of an existing Truth Table Generator)

I have the following questions:

  • How should I go about parsing expressions like: ((P => Q) & (Q => R)) => (P => R)
  • Should I use a parser generator like ANTLr or YACC, or use straight regular expressions?
  • Once I have the expression parsed, how should I go about generating the truth table? Each section of the expression needs to be divided up into its smallest components and re-built from the left side of the table to the right. How would I evaluate something like that?

Can anyone provide me with tips concerning the parsing of these arbitrary expressions and eventually evaluating the parsed expression?

© Stack Overflow or respective owner

Related posts about truthtable

Related posts about c#