1

I want to write a truth table evaluator for a given formula like in this site. http://jamie-wong.com/experiments/truthtabler/SLR1/ Operators are:

-  (negation)   
&  (and)        
|  (or)       
>  (implication)     
=  (equivalence)

So far I made this

-(-(a& b) > ( -((a|-s)| c )| d)) 

given this formula my output is

    abdsR
    TTTT
    TTTF
    TTFT
    TTFF
    TFTT
    TFTF
    TFFT
    TFFF
    FTTT
    FTTF
    FTFT 
    FTFF
    FFTT
    FFTF
    FFFT
    FFFF

I am having difficulties with the evaluating part. I created an array which in I stored indises of parenthesis if it helps,namely 7-3, 17-12, 20-11, 23-9, 24-1 I also checked the code in http://www.stenmorten.com/English/llc/source/turth_tables_ass4.c ,however I didn't get it.

  • The output table needs to have the `R` column filled in. Also, you might want to explain how the `implication` operator is supposed to work in a truth table. – user3386109 May 14 '14 at 18:08
  • 1
    @user3386109 implication (A > B) is equivalent to (¬A | B). – ecatmur May 14 '14 at 18:09
  • YesI know,but I couldn't find the R value.implication operator returns false if the first operand true the second operand false 1>0=0 otherwise =1 – user3637754 May 14 '14 at 18:11

1 Answers1

0

Writing an operator precedence parser to evaluate infix notation expressions is not an easy task. However, the shunting yard algorithm is a good place to start.

user3386109
  • 34,287
  • 7
  • 49
  • 68