Normally, AND would take precedence, but there's also an argument for building up as you go. (I've seen C compilers do that, so that PEMDAS becomes PE-order-of-appearance - only because E is a formally-defined function and not a built-in operator - and code that uses it has parentheses *everywhere*!) I haven't used enough complex logic in here to figure out which it is for us. We don't have parentheses, so it's limited either way.Thank you. How about if I need to add a condition with an AND? So if it's in those specified time ranges AND it's on a certain scene. I'm not sure about the precedence, but applying what I know by AND usually taking precedence over OR, this would mean I'd need an AND for each time range, is that correct? And thus, so I don't need to create multiple ANDs, i just group all the time ranges in one macro like you said, then AND in another macro?
The build-up-as-you-go version requires less to keep track of under the hood, and is equivalent to having a big pile of open parens up front, and each expression closes one.
If you really don't want parentheses, you can look at Reverse Polish Notation. It has all the capabilities, without that requirement, but it does have a different requirement of loading each operand by itself, without an operator, and specifying each operator without operands. Each operand goes onto a stack, and each operator takes the last two items (sometimes one) off of the stack and puts its result back onto the stack. If you're not used to it, that gets confusing in a hurry!
For example,
A B + C * D E / -
in RPN is equivalent to ((A + B) * C) - (D / E)
in the way that most of us are used to.A bunch of the same associative operation could be
A B + C + D + E +
or A B C D E + + + +
or any combination in between, though the first is probably easiest to read, and keeps the stack size down.This is also easier under the hood than parentheses, because there's never a need to save your place in the expression and come back to it.
For error handling:
- An operator that sees insufficient operands on the stack, could do nothing (don't even pop/push), and throw a warning.
- When the expression is finished, take the top of the stack as the answer. If the stack is empty, call it false. If there are additional items, throw a warning, but only use the top one. Regardless, clear the stack before the next scan.
Last edited: