At the same time, faced with a similar problem, I decided to switch to a generalized solution like "switch ... case ... break ... default" along with a set of arm-style commands with conditional execution. A user interpreter using the nesting stack was used to analyze these "programs." This solution completely eliminates identifiers or tags. All my XML elements or “instructions” support the attribute “condition”, which, if it is absent or if it evaluates to true, the instruction of the element is executed. If the "exit" attribute is true and the condition is also true, then the next group of elements / instructions at the same nesting level will neither be evaluated nor executed, and execution will continue with the subsequent element / instruction at the parent level. If there is no "exit" or it evaluates to false, the program proceeds to the next element / instruction. For example, you can write this type of program (it will be useful to provide a noop instruction), and the mechanism / instruction for assigning values and / or expressions for "variables" will be very convenient):
<ins-1> <ins-11 condition="expr-a" exit="true"> <ins-111 /> ... </ins11> <ins-12 condition="expr-b" exit="true" /> <ins-13 condition="expr-c" /> <ins-14> ... </ins14> </ins-1> <ins-2> ... </ins-2>
If expr-a is true, then the execution sequence will be:
ins-1 ins-11 ins-111 ins-2
if expr-a is false and expr-b is true, then this will be:
ins-1 ins-12 ins-2
If both expressions expr-a and expr-b are false, we get:
ins-1 ins-13 (only if expr-c evaluates to true) ins-14 ins-2
PS. I used "exit" instead of "break" because I used "break" to implement "breakpoints". Such programs are very difficult to debug without any breakpointing / tracing mechanism.
PS2. Since I had similar conditions for the date, as your example, along with other types of conditions, I also implemented two special attributes: "from" and "to", which should also be evaluated as true if they were present as a "condition" , and which used special fast logic for checking the date and time.
Costas
source share