Question

Rule
+-C1
+-C2
+-G1
| +-C3
| +-C4

((C1) && (C2) && (C3 OR C4))

These operators are associated with a group. It could also be as follows. This structure is not fixed. Based on the number of groups and condtions in each rule.

Rule
+-G1
| +-C3
| +-C4
+-C2

G* are groups which contains Conditions C* We are trying to implement our validations/ rules in the database. We are tying to group our conditions based on AND, OR

Could this be considered a tree structure. Starting at the top, how do I traverse to the last group. I know this is very vague But this is what I have currently in mind Once I get to the last group, I would evaluate all the conditions in a group.

Thank you

Was it helpful?

Solution

What you show is a tree, known as an abstract syntax tree. The internal nodes represent your operators, and the leaves represent the conditions. If I understand the question, you are asking how evaluate the expression represented by the tree. To do that, you perform a depth-first search. Whenever the search visits an internal node, you evaluate the operator stored at that node using the values of the children as arguments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top