A quick search of CPAN didn't turn up anything that looks like it deals with bitwise operators for symbolic algebraic manipulation, but for the simple example you give the following works:
use strict;
use warnings;
use Math::Algebra::Symbols;
my $file = <<FILE;
e = a & b;
f = e | c;
d = ~f;
FILE
open my $fIn, '<', \$file or die "Can't open file: $!\n";
my %subst;
my $last;
while (<$fIn>) {
chomp;
s/;$//;
my ($lhs, $rhs) = split /\s*=\s*/, $_, 2;
$rhs =~ s/(\w+)/exists $subst{$1} ? "($subst{$1})" : $1/ge;
$subst{$lhs} = $rhs;
$last = "$lhs = $rhs";
}
print $last;
Prints:
d = ~((a & b) | c)
True laziness is hard work
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.