|
From: Tim H. <tim...@un...> - 2008-04-07 22:13:31
|
Hello,
because of a recent discussion on comp.graphics.apps.gnuplot I realized
that the parsing of if ... else ... is somewhat "unusual". If the
condition fails, gnuplot will jump to the next else (as documented). I
don't consider this to be a good solution, because this causes troubles
in nested if else statements.
A short summary on the possible nestings (more detailed in the newsgroup):
1) if if - OK
2) if else if else - OK
3) if if else else - syntax error if the first condition fails (2nd else)
4) if if else - syntactically correct; depending on the condition else
belongs to the first or second if!
Looking at the code, I think it should be easy to switch from this
evaluation to a stack-like interpretation which allows above nestings
and is furthermore the "natural" way of blocking in programming
languages. It involves only counting if else pairs and resuming
execution at the right level instead of simply the next else. I will
have a try with this in some days.
The only thing left for a perfect if would then be some blocking to make
if (if ...) else possible. But I leave this for the moment, firstly
because it appears to be more involved to insert additional tokens () or
maybe {}, and secondly because you can archive the same logic by if else
if ... and negating the first condition.
Comments are welcome.
Regards,
Tim
|