[OT] Haxe "if" context-sensitive? (Q for Grammar Experts)
Nick Sabalausky
a at a.a
Mon Aug 31 18:38:25 PDT 2009
"Tim M" <tim.matthews7 at gmail.com> wrote in message
news:h7hrf2$vj5$1 at digitalmars.com...
>
> Although I don't really understand your problem or how it relates to the D
> lang.
It doesn't really relate to D. Hence "[OT]" off-topic ;) But there seem to
be a number of people here that are good with language theory (or at least
better than me), so I thought I'd try here (in addition to other more
directly relevant communities).
> D and other C like languages do have if expressions too but they're just
> not called if expressions. They're called ternary expressions due to the
> way they have 3 blocks around single characters rather than the word 'if'
> but the concept is pretty much the same.
>
> condition ? trueCode : falseCode
Yea. And I've been starting to see why they do it that way. There's a number
of things about it that make it much easier to implement. Ex. easy for the
parser to distinguish from a statement, no dangling-else issue since the
"else" part is never optional (And in my limited experience, the
dangling-else ambiguity seems to be a *lot* easier to fix (at least without
requiring extra syntax) when the if is restricted to being a
statement-only), etc. One of the approaches I tried (and the one that seems
to be giving me the most luck) is to treat the if-expression as much as
possible like a ?: ternary operator.
More information about the Digitalmars-d
mailing list