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 < z
would be equivalent to(x < y) < z
. This is whatC
does:-1 < 0 < 1
becomes(-1 < 0) < 1
, thus1 < 1
, which is0
.Treat
<
as a right-associative binary operator, sox<y<z
would be equivalent tox < (y < z)
. I see no advantage to that option.When encountering
<
, read ahead for more comparison operators, and treatx < y < z
as equivalent to(x < y) && (y < z)
, wherey
would 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.