in reply to Re: Generate a truth table from input string
in thread Generate a truth table from input string
Parsing is quite possibly not required. Assuming that the variables can be assumed to contain a true value why not just leverage perl.
$str =~ s/\*/&&/g; $str =~ s/\+/||/g; # $str =~ s/'/!/g; $str =~ s/(\w+)'/!$1/g; $str =~ s/\(([^\)]+)\)'/!($1)/g; $str =~ s/\w+/1/g; my $truth = eval $str;
If the a/b/A/B vars have associated values all that is required is to substitute them in. Perl does the parsing and calculates the truth.
Modified to deal with ' postfix syntax
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Generate a truth table from input string
by ikegami (Patriarch) on May 13, 2008 at 16:43 UTC | |
by tachyon-II (Chaplain) on May 13, 2008 at 18:40 UTC | |
by ikegami (Patriarch) on May 13, 2008 at 18:43 UTC | |
by tachyon-II (Chaplain) on May 14, 2008 at 00:30 UTC | |
by Anonymous Monk on Oct 28, 2017 at 11:46 UTC | |
|