Fellow Monks of great Perlness -

I'm in the middle of reducing some SPICE-superset models to run on normal SPICE3, and I've chosen to do it by a series of find-and-replace operations, i.e., at the string level. When I first was given the assignment, I thought I was going to build a symbol-table driven model, but the raw string processing version is coming along quite well.

Given that data representation is so central to all we do, how do we choose whether to parse and build recursive models or to s/construct/simplified/g?

In my case, besides simple variable substitution, the definitions have some of the grotiest inconsistent if/then/else and embedded conditionals I've ever seen. It's based on neolithic FORTRAN, but the superset parser seems to accept a lot of things that would offend both Backus and Naur greatly. I found that it was much easier to code regex / eval pairs to identify these cases line by line than it would have been to store all the data in a tree after identifying them. Below is the code that handles the && and || clauses of the conditionals.
sub testcondition { my $work = trim($_[0]); if ($work =~ /^\((.+)\)$/) { $work = trim($1); } if ($work =~ /^(.+)\|\|(.+)$/) { my($or1,$or2) = ($1,$2); if ((testcondition($or1) eq 'T') || (testcondition($or2) eq 'T')) { return 'T'; } } elsif ($work =~ /^(.+)\&\&(.+)$/) { my ($and1, $and2) = ($1, $2); if ((testcondition($and1) eq 'T') && (testcondition($and2) eq 'T') +) { return 'T'; } } elsif ($work =~ /^(.*[^=<>])[=<>]+)([^=<>].*)$/) #updated { my ($r1, $r2, $r3) = ($1, $2, $3); if (isanumber($r1) && isanumber($r3)) { if (eval("$r1 $r2 $r3")) { return 'T'; } else { return 'F'; } } } return '?'; }
UPDATED: added not-operator 'stops' to conditional breakup match

In reply to To model or not to model by samizdat

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.