Parser for conditions with logical operators

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • André Hänsel

    #1

    Parser for conditions with logical operators

    Hi,

    before I rack my brain about something others have thought about, here
    my question:

    Is there any description how to write a parser that evaluates
    expressions with logical operators like "(condition 1 OR condition2 AND
    (condition3 OR condition4))" in the right way?

    Best regards,
    André

  • Chung Leong

    #2
    Re: Parser for conditions with logical operators


    André Hänsel wrote:[color=blue]
    > Hi,
    >
    > before I rack my brain about something others have thought about, here
    > my question:
    >
    > Is there any description how to write a parser that evaluates
    > expressions with logical operators like "(condition 1 OR condition2 AND
    > (condition3 OR condition4))" in the right way?
    >
    > Best regards,
    > André[/color]

    Check out this article at Wikipedia for an brief intro on
    bottom-up-parsing: http://en.wikipedia.org/wiki/Bottom-up_parsing

    Comment

    • fletch

      #3
      Re: Parser for conditions with logical operators

      Are you doing a template engine?

      We parse <$TEST.TestName .otherparams> and write a cache file which will
      contain this instead of the tag:

      if($oForObj->Test_TestName( $otherparam1,$o therparam2)){

      <$TEST.ELSE> is replaced as '} else {'
      and <$/TEST> as '}'

      $oForObj is set to be the object that displays the template and would
      therefore be expected to have the required method.

      All the logic then goes into that method, and you can get as
      complicated as you like.

      I suppose you could do something similar with switch, but we haven't
      yet.

      Comment

      Working...