How about this (example used is "(A AND B) OR (C OR D NOT E) OR Q"):

  1. Break the statement into smaller ones on the joiner -- AND, OR, NOT -- which are not inside parent expression. That will yield: { OR <-- { (A AND B) , (C OR D NOT E) } , OR <-- { Q } }.
  2. Go thru to each of the component of the broken down tokens, to search for the joiner as above, giving: { AND <-- { A, B } , OR <-- { C , D , NOT E } }.
  3. Do the above for all other sub components, till all are exhausted.
  4. Ending up w/...
    { OR <-- { AND <-- { A , B } , OR <-- { C , D , NOT <-- { E } } } , OR <-- { Q } }
  5. Last step would be add the appropriate signs (or nothing at all) based on parent joiner, which can be easily done in a loop.

Well, that is what currently comes to mind, bugs expected.

Updated (Jun 24 2003) the parsed expressions as after adding "OR Q" in the example, forgot to correctly update the hierarchy.


In reply to Re: converting a boolean syntax by parv
in thread converting a boolean syntax by glwtta

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.