I'm assuming all the functions are logically valid, and using eval:
use strict; use warnings; my (@truth, $c1, $c2, $line, $logic, $v, $c, $cref); my $max = 4; ## Max number of vars $truth[0] = '0 1'; for (1..($max-1)) { ($c1 = $truth[$_-1]) =~ s/(\d+)/0$1/g; ($c2 = $truth[$_-1]) =~ s/(\d+)/1$1/g; $truth[$_] = "$c1 $c2"; } for (0..($max-1)) { my @comb = split(/ /, $truth[$_]); $truth[$_] = \@comb; } for (<DATA>) { my %vars; chomp($line = $_); @_ = $line =~ /(\w+)/g; $v = ''; $c = 0; for (sort @_) { ## Sort and retrieve if ($_ ne $v) { ## unique var names $vars{$v = $_} = $c++; } } print $line . "\n"; print join(' ', sort {$vars{$a} <=> $vars{$b}} keys %vars) . "\n"; $cref = $truth[scalar(keys %vars) - 1]; for (@$cref) { $logic = $line; ## Replace var names with $logic =~ s/(\w+)/substr($_, $vars{$1}, 1)/eg; print $_ . ' ' . eval($logic) . "\n"; } ## logic values and evaluate print "\n"; } __DATA__ ((S0*B)|((!S0)*A)) ((A*B)^C)

In reply to Re: parser for evaluating arbitrarily complex boolean function in a string by TedPride
in thread parser for evaluating arbitrarily complex boolean function in a string by jce

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.