[OT] Haxe "if" context-sensitive? (Q for Grammar Experts)

Nick Sabalausky a at a.a
Mon Aug 31 03:59:49 PDT 2009


"Nick Sabalausky" <a at a.a> wrote in message 
news:h7fl1o$f8u$1 at digitalmars.com...
> I've been trying to make a grammar for the Haxe langauge, and I've been 
> having a hell of a time emulating it's expression-based if/if-else (as 
> opposed to statement-based as in D). I'm sure a big part of it is my 
> inexperience with writing grammars, but I've also been starting to wonder 
> if it's impossible to do context-free. For those unfamiliar, here's how 
> the relevant parts in Haxe work:
>
> ------------------------------------------
....
> ------------------------------------------
>
> So, anyone know if a grammar that handles this would need to be 
> context-sensitive? Or am I just *really* bad at this? ;)
>

I guess the key I'm looking for is this:

// With "if" being an expr, not a stmt:
foo = if(blah) bar = 1;
foo = if(blah) bar = 1; else bar = 2;

If I make assignment bind tighter than the "if expressions", then I can't 
support "foo = if...", I can only support "foo = (if...)"

But if I make the "if expressions" bind tighter than assignment, then I 
can't seem to solve the dangling-else conflict without introducing other 
ambiguities.

Anyway, I'm not really looking to get an exact solution, just wondering if 
there's something about it that causes it to be impossible for a 
context-free grammar.





More information about the Digitalmars-d mailing list