Boolean expression evaluation routine required

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #46
    Originally posted by Railgunner
    ...This would be a cool routine in inself if it worked. Might be useful for making sense of complex statements by translating them into a more easy to read format.
    That sounds like a worthy goal. I've seen some mighty complex IF statements at times. (Probably guilty of writing some pretty nasty ones, too.)

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #47
      @Railgunner: if you want to minimize boolean expressions, as in e.g.
      (A and B) or ((not A) and B) ---> B have a look at the Quine McCluskey
      simplification algorithm.

      kind regards,

      Jos

      Comment

      • luke14free
        New Member
        • Apr 2007
        • 79

        #48
        seriously i didn't undersstand why is my code wrong...:(
        could you repeat it to me?
        how ever couldn't you do something like that

        IF (A=2 AND (B=3 OR C=4)) OR C=4

        now lets split the condition(suppo se that we have taken out the if yes so we just have (A=2 AND (B=3 OR C=4)) OR C=4 with the separator '(' and ')' and take out them(just the initual and fianl onem so we get A=2 AND (B=3 OR C=4)-->we take what is in the first ()
        now lets do a while that say: continue this procedure until there are no other panens inside our code.in our case we get B=3 OR C=4...lets pass this condition and suppose that you get TRUE

        so some it up...(A=2 AND (B=3 OR C=4)) OR C=4-->A=2 AND (B=3 OR C=4)-->B=3 OR C=4-->TRUE

        now rewind... we know that the most internal condition is TRUE lets take out the condition and put TRUE in his place...we get
        (A=2 AND TRUE) OR C=4

        our while cicle sees another parens so(suppose that A is 2):
        (A=2 AND TRUE) OR C=4-->A=2 AND TRUE-->TRUE

        and so you have:

        TRUE OR C=4

        you exit from the while because there are no longer parens...

        the you just need to pass the C=4 to an IF cicle..
        suppose that returns TRUE

        TRUE OR TRUE

        pass into another IF

        TRUE

        so thats the routine that i am going to build...do you think that would be finally right?

        best regards

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #49
          Originally posted by luke14free
          Hmm, only one thing, if you get something like this
          a=2

          if 'a = 2' is True etcetra...

          then you take the string condition that is 'a = 2'...you can split it and you get:
          'a','=','2'...f or the = there is no problem, you can do a series of if cases and you say if sing= '=' elif sign='<'... and so on.
          for the number is very easy because you get the int value from a string..
          but now you have to get back from a letter or a word (that in our case is 'a') to a var that is really different from a (without quotes!)
          so your expression becames:

          the word 'a' is equal to 2

          and you'll get false... because we aren't talking about the var!

          however thanks for the explanation!

          This is only a problem if you don't account for it in the language. You would need to create a data structure for holding your variable assignments: a hash table should do quite well for mapping variable names to their values. The function which does the processing on a node wouldn't be a direct mapping of strings to logical operators, rather the booleanop() from my pseudo-code was merely a high level abstraction of the process.

          Comment

          • luke14free
            New Member
            • Apr 2007
            • 79

            #50
            Originally posted by Motoma
            This is only a problem if you don't account for it in the language. You would need to create a data structure for holding your variable assignments: a hash table should do quite well for mapping variable names to their values. The function which does the processing on a node wouldn't be a direct mapping of strings to logical operators, rather the booleanop() from my pseudo-code was merely a high level abstraction of the process.
            and you think that this would be done in basic for just 500$? eheh,,,i am not helping railgunner for moneys...but its a quite difficult to do it...i could try to do it in another language such as c python or perl...but in basic is just for people who dont need to reach those levels...correc t me if i am wrong, but i think its quite impossible...we should find another solution,isnt it motoba?
            however i am valutating the possibility to create a code for hash datas...:)
            one question for railgunner: do you sleep an night or you just code?eheh :P

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #51
              No, I don't; in fact, a few posts ago I mentioned that it would be a difficult task to coerce someone into building this system in a rudimentary language such as BASIC or COBOL for such a low price.

              Originally posted by luke14free
              and you think that this would be done in basic for just 500$?

              Comment

              • Railgunner
                New Member
                • Apr 2007
                • 18

                #52
                Originally posted by luke14free
                and you think that this would be done in basic for just 500$? eheh,,,i am not helping railgunner for moneys...but its a quite difficult to do it...i could try to do it in another language such as c python or perl...but in basic is just for people who dont need to reach those levels...correc t me if i am wrong, but i think its quite impossible...we should find another solution,isnt it motoba?
                however i am valutating the possibility to create a code for hash datas...:)
                one question for railgunner: do you sleep an night or you just code?eheh :P
                Well, i've managed to write an interpreter than can execute IF/ELSE-IF logic
                (minus the parens) in what amounts to COBOL so anythings possible:)

                I really didn't expect someone to write the routine from scratch for $500. I was hoping that someone might know where to find an example of such a routine in VB and the reward was for finding it:)

                I did actually find the source for a basic interpreter here. The author said he wrote it in a "an hour or two". I hope he's not telling the truth because that would make me feel really dumb.

                Vi bidrar till snabbare omställning och stärkt konkurrenskraft för företagen, samhället och Sverige.


                I've been looking at it but it's written in C. I guess I could learn C but I was really
                hoping I wouldn't have to.

                Comment

                • luke14free
                  New Member
                  • Apr 2007
                  • 79

                  #53
                  Originally posted by Railgunner
                  I've been looking at it but it's written in C. I guess I could learn C but I was really
                  hoping I wouldn't have to.
                  So dont learn it...!
                  i ve found an old basic compiler/compiler written in basic! i am working to get the source code!! and you'll have what you needed!
                  just wait 2/3 days and i'll give you what you needed
                  do you prefer all the sources or just the one for the if/else use?

                  Comment

                  • luke14free
                    New Member
                    • Apr 2007
                    • 79

                    #54
                    Never mean what I wrote
                    you code is here!
                    thanks to matoma who has gave me the various explainations.. .the code posted is a complex Tree Function...see my post here for more details...

                    Comment

                    Working...