I'm trying to find a data-structure to help me model this scenario...
I have a set of expressions that have two types: 1. Expressions that have a calculations that should be executed and return a true or false outcome 2. Expressions that print out information and have no return value The expressions have a sequential order that depends on the outcome of their calculation.
The expressions are stored in the database and at runtime will be loaded into a data structure which will need to retain the order of the expressions and the decisions that should be followed depending on an expression's outcome.
Let me illustrate this with a simple example where there are 4 expressions and the first two are rules that when carried out have a true or false return value but the final 2 are just informational so after being executed the flow would continue to the next expression.
Expression 1: "5+5=10" If True then go to Expression 2 If False then go to Expression 4
Expression 2: "6+1=7" If True then go to Expression 4 If False then go to Expression 3
Expression 3: "print hello"
Expression 4: "print goodbye"
My immediate thought is that the data structure could be some sort of linked list that would need to have not only a next() method to point to the next expression but also true() and false() methods to point to the appropriate nodes in the case that the expression has a return value.
Is there any established way to model this type of relationship?