Originally posted by Railgunner
Boolean expression evaluation routine required
Collapse
X
-
@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,
JosComment
-
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 regardsComment
-
Originally posted by luke14freeHmm, 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
-
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?Originally posted by MotomaThis 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.
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 :PComment
-
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 luke14freeand you think that this would be done in basic for just 500$?Comment
-
Well, i've managed to write an interpreter than can execute IF/ELSE-IF logicOriginally posted by luke14freeand 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
(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
-
So dont learn it...!Originally posted by RailgunnerI'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.
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
-
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
Comment