#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on May 9, 2012 12:10:43 GMT -8
Here's a question I can't seem to figure out.
How would one go about breaking down the structure of nested conditional statements into an array (for storage and handeling between lower-level code)?
For example, you could break down a single condition easily: if x == y then… => ['x', '==', 'y']
But what about: if x == y and z > 0, or if (x == y and z > 0) or x == z.
This gives us up to three comparisons: [['x', '==', 'y'], ['z', '>', '0'], ['x', '==', 'z']
But no way to add the Boolean logic parts.
|
|
inherit
24252
0
Aug 1, 2023 15:01:24 GMT -8
coolcoolcool
When the world says, "Give up," Hope whispers, "Try it one more time."
2,148
May 2004
coolcoolcool
|
Post by coolcoolcool on May 10, 2012 18:25:32 GMT -8
What kind of low level code? Application could change how the problem is tackled.
I've never had a reason to break down boolean logic into an array before.
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on May 10, 2012 18:40:16 GMT -8
Not low-level, simply lower-level. I am attempting to build an interface where statements are put into an application that will process them, without having to create a syntax for strings to then parse. Essentially I want a way to put the above statements into a function as a parmeter that the function can evaluate.
|
|
inherit
24252
0
Aug 1, 2023 15:01:24 GMT -8
coolcoolcool
When the world says, "Give up," Hope whispers, "Try it one more time."
2,148
May 2004
coolcoolcool
|
Post by coolcoolcool on May 10, 2012 18:52:54 GMT -8
Seems counter intuitive to me, but I'm probably not understanding what you're doing.
Why not use a stack and a custom postfix notation that allows for ands, negates, and ors? That's a pretty common problem and there's pseudo code for it already tailor made all over the internet.
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on May 10, 2012 18:58:53 GMT -8
Seems counter intuitive to me, but I'm probably not understanding what you're doing. Why not use a stack and a custom postfix notation that allows for ands, negates, and ors? That's a pretty common problem and there's pseudo code for it already tailor made all over the internet. I'm thinking I may use a custom pseudo-code for it, but I was trying to create something that did not require passing strings to the function.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on May 11, 2012 10:20:11 GMT -8
Why not: [['x', '==', 'y'], '&&', ['z', '>', '0'], '&&', ['x', '==', 'z']]
If the item is an array ([x, ==, z]), then evaluate it as a comparison; if it's a string (&& or ||), then evaluate it as an operator.
Really, though, I don't see the benefit to this. It brings problems with things like (($x == 0 || $y == 1) && $z == 2)
You should just send the entire string to evaluate.
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on May 11, 2012 10:22:57 GMT -8
Why not: [['x', '==', 'y'], '&&', ['z', '>', '0'], '&&', ['x', '==', 'z']] If the item is an array ([x, ==, z]), then evaluate it as a comparison; if it's a string (&& or ||), then evaluate it as an operator. Really, though, I don't see the benefit to this. It brings problems with things like (($x == 0 || $y == 1) && $z == 2) You should just send the entire string to evaluate. You would nest by replacing one of the comparisons with an array similar to that one?
|
|
inherit
24252
0
Aug 1, 2023 15:01:24 GMT -8
coolcoolcool
When the world says, "Give up," Hope whispers, "Try it one more time."
2,148
May 2004
coolcoolcool
|
Post by coolcoolcool on May 11, 2012 13:55:12 GMT -8
I'm still saying a single array of postfix operators and values would be best.
|
|