I have written a decimal floating point unit for LaTeX3 (pure macros... that was tough). In particular, I have to decide how x < y < z should be parsed. I see three options:
Treat
<as a left-associative binary operator, sox < y < zwould be equivalent to(x < y) < z. This is whatCdoes:-1 < 0 < 1becomes(-1 < 0) < 1, thus1 < 1, which is0.Treat
<as a right-associative binary operator, sox<y<zwould be equivalent tox < (y < z). I see no advantage to that option.When encountering
<, read ahead for more comparison operators, and treatx < y < zas equivalent to(x < y) && (y < z), whereywould be evaluated only once. This is what most non-programmers would expect. And quite a few LaTeX users are non-programmers.
At the moment I am using the first option, but it does not seem very natural. I think that I can implement the second case whithout too much overhead. Should I?
Since that question is subjective, let me ask an objective question: what mainstream languages pick option 3? I'm interested in the details of what happens with mixed things like a < b > c == d < e != f. I'm also interested in other choices if they exist.