List<SyntaxElement> syntax = operator.getSyntax();
for (int i = 0, n = syntax.size(); i < n; ++i) {
SyntaxElement syntaxEl = syntax.get(i);
if (syntaxEl instanceof Operand) {
Operand operand = (Operand) syntaxEl;
// If left (right) associative, first (last) operand doesn't need protection if it's an
// operator of equal precedence to this one. (Note: Actually, the middle operand of our only
// ternary operator doesn't need protection either, but we do it anyway for readability.)
if (i == (isLeftAssociative ? 0 : n-1)) {
sourceSb.append(getOperandProtectedForLowerPrec(operand.getIndex()));
} else {
sourceSb.append(getOperandProtectedForLowerOrEqualPrec(operand.getIndex()));
}
} else if (syntaxEl instanceof Token) {
sourceSb.append(((Token) syntaxEl).getValue());