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:
------------------------------------------ // Each of these are invalid: 1 // Missing ';' ; // Unexpected ';' foo = 1 // Missing ';' foo = 1;; // Unexpected ';' // AIUI, Each of these lines are syntactically separate from // each other (but not because they're on separate lines), // and work as expected. {} {}; 1; {1;} {1;}; bar(); {bar();} {bar();}; if(foo==1) {} if(foo==1) {}; if(foo==1) 1; if(foo==1) {1;} if(foo==1) {1;}; if(foo==1) bar(); if(foo==1) {bar();} if(foo==1) {bar();}; if(foo==1) {} else whatever; if(foo==1) {}; else whatever; if(foo==1) 1; else whatever; if(foo==1) {1;} else whatever; if(foo==1) {1;}; else whatever; if(foo==1) bar(); else whatever; if(foo==1) {bar();} else whatever; if(foo==1) {bar();}; else whatever; if(foo==1) 1 else whatever; if(foo==1) bar() else whatever; // else binds to nearest if if(foo==1) if(foo==2) whatever else whatever; if(foo==1) if(foo==2) whatever; else whatever; if(foo==1) if(foo==2) whatever else whatever else whatever; if(foo==1) if(foo==2) whatever; else whatever; else whatever; // assignments foo = {} foo = {}; // Etc... foo = if(foo==1) {} foo = if(foo==1) {}; // Etc... foo = if(foo==1) {} else whatever; foo = if(foo==1) {}; else whatever; // Etc... foo = if(foo==1) if(foo==2) whatever else whatever; foo = if(foo==1) if(foo==2) whatever; else whatever; foo = if(foo==1) if(foo==2) whatever else whatever else whatever; foo = if(foo==1) if(foo==2) whatever; else whatever; else whatever; ------------------------------------------ So, anyone know if a grammar that handles this would need to be context-sensitive? Or am I just *really* bad at this? ;)