Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi monks, I am working in a project in helping colleges to do logic check from batch of Excel files. Staffs will write a sort of simple syntax (still designing) within a INI file; basically the so called syntax(expression) are some and or eq etc. operators with {[()]}. , which will return a true or false.

The first problem come to me is how do I resolve those brackets, so I can determine the logic's precedence. Now I have this :

$expr = '(A&(B&C)|((C&D)|\((A EQ 1)))'; # 01234567890123456789012345678 my (@open, @close); my @charArr = split //, $expr; foreach my $pos ( 0..$#charArr ) { push @open, $pos if ( $charArr[$pos] =~ /\(/ && $charArr[$pos-1] n +e "\\" ) ; push @close, $pos if ( $charArr[$pos] =~ /\)/ && $charArr[$pos-1] +ne "\\" ) ; } die "Imbalance Pair" unless @open == @close; print "@open$/@close$/$/"; my @preced; foreach my $firstClose ( @close ) { my @temp = (); while ( @open ) { my $lastOpen = pop @open; if ( $lastOpen < $firstClose ) { push @preced, "$lastOpen - $firstClose"; @open = (@open, @temp); last } else { unshift @temp, $lastOpen; } } } print $_.$/ foreach @preced; __END__ prints: 0 3 9 10 18 7 14 25 26 27 3 - 7 10 - 14 18 - 25 9 - 26 0 - 27

The @preced carries the string positions of each open-end brackets, and their precedence order. However, it looks like a stupid algorithm, which sound unsafe and not efficient.

My questions :

1. What is the terminology of this sort of issues ? I like to look up more, but I don't know what is it called

2. Is there any module actually suits for this kind of case? What I have only a start up, implementing each block is another issue, if more operators are needed later, like >= == != boolean, string compare etc. situations. I can't foresee what's gonna happen.

Any clues for me ? Thanks in advance.


In reply to Need a start point for resolving {[()]} by exilepanda

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (10)
    As of 2015-07-31 19:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (280 votes), past polls