On Thu, 2007-07-19 at 03:49 +1000, skaller wrote: > Just some notes here that providing C syntax with Felix leads > to some interesting ambiguities such as: > > int f(long q) { return x; } > > being interpreted as > > call (int f) (long q) { return x; }; > > i.e. as a call, because all the terms here are valid expressions > in Felix. OTOH 'int' isn't a keyword. Even worse: > > int f(long q) { return x; } > f 1L; > > becomes: > > call (int f) (long q) { return x; } f 1L;
I've now adjusted it so this works: #import <flx.flxh> open syntax csyntax; int f(int x) { return x; }; println (f 10); Note that you must put the ';' at the end of the C function definition, to terminate the statement, and avoid the problem above. The rule for parsing is: if there is an ambiguity parsing a nonterminal, eg, statement, then the newest production is always used. This applies to all nonterminals. The rule is more subtle than you think, and not entirely the best. Note it does NOT help if you leave out the semicolon, because then we have the SAME production: statements := statements statement ambiguous because int f(int x) { return x; } // WITHOUT SEMICOLON println (f 10); can be parsed as you might think: two statements .. OR it can be parsed as a single call statement. If that happens the parser will bug out. Unfortunately that may mean some intended interpretations cannot be parsed at all. In the above case you can disambiguate either by the ';' or, if you really mean to do a procedure call you can write: call int f(int x) { return x; } println (f 10); with the keyword 'call'. I have no idea if this handles all possible ambiguities: remember the ambiguities are resolved for ALL nonterminals, not just statements. Note that at the moment csyntax must be explicitly opened. That may change .. in fact I will probably change it to see if the regression tests continue to work. Note a consequence: whilst we support 'expression statements' like C, we cannot parse C 'as is' because Felix thinks { .. } is a valid expression, and so C function definitions will not be considered terminated. I think gcc extension uses {( )} or something for that .. ;( -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language