I have added a new feature to the Felix parser to make this work:
////////////////////////////////////////
#import <flx.flxh>
syntax csyn {
statement := typedef "int" sname; =># """`(ast_nop ,_sr "int")""";
statement := typedef "long" sname; =># """`(ast_nop ,_sr "long")""";
}
open syntax csyn;
typedef int fred;
typedef long fred;
//typedef complex fred;
println "Done";
////////////////////////////////////////////////
In case you didn't spot it: if you write a work in quotes such
as "int" or "long" above, it will match the identifier with
the same spelling.
This is very similar to using a keyword EXCEPT it isn't a
keyword. The identifier is ONLY matched in the context of
the candidate production.
Note: if you try something like:
statement := "int" sname ; =># ...
then
int x;
will also be parsed as
call int x;
[that is, as a call of procedure 'int' on argument 'x']
Dypgen will then call a merge function which by default
choses the latest definition, our new one.
And in case you didn't spot the purpose of this .. I am going
to add a C style typedef to the grammar, similarly C style
other stuff (eg function definitions).
In most cases, either:
(a) there's no ambiguity between C and Felix, or,
(b) the parse is ambiguous, but the result is equivalent, or,
(c) as above with int x .. we prefer the C form, because there
is another way to do it in Felix (eg use call keyword).
to get this stuff to work I MAY have to change some of
the Felix syntax.. be warned .. some stuff looking like
C now with a different meaning might silently change to
have the C meaning.
A workaround may be to require
extern "C"
around C stuff ..
Another feature to be added is the logical extension of this:
allow a dynamically modifiable list of such things, in particular
names of C types. Not sure on the syntax, or whether this is
a good idea or not :)
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language