On Mon, 2007-11-26 at 17:45 +1100, skaller wrote: > On Sun, 2007-11-25 at 18:24 -0800, Erick Tryzelaar wrote: > > We could probably remove the ability to do 1i. > > > > What about just having a scoped syntax extension that allows you to > > write "1.0 + 1.0i" in the complex module that isn't automatically > > opened? For quaternions, you could add another that added support for > > 1.0j and 1.0k.
> Just to make it clear: lexing is done first in a pass on a file, > before any syntax analysis is done. That's why new tokens must > be introduced with #preprocessor directives, and are scoped to > the logical file (i.e. the physical file + #imports). Just to add a note: new tokens can be created only in fixed categories. Identifiers can be made 'user keywords', which is a single token distinct from the usual NAME -- Dypgen can detect the attribute dynamically. In addition, plain identifiers can be checked without making them a user token. This speeds up parsing by reducing the potential for ambiguity. Sequences of special $%^&* characters and identifiers can also be made into tokens. For the special characters the lexing really IS interpreted by the lexer using a mini-lexer which is dynamic. [It looks in a table for the longest match, removes that from the input, then looks again for the next match, until the input string is exhausted .. the table is managed by #infix etc directives] Dypgen can detect the attribute of the single user symbol here. But still, none of this allows new NUMERIC or STRING kinds to be introduced. So the only way to handle 1.0i dependent on whether 'complex' feature is enabled would be to pre-program it in one of two ways and chose between them with some kind of preprocessor switch. The point being the lexer would have to have builtin capability to handle it anyhow. Another method may be to simply consider i,j,k as constants in a module of a special type. Then code like 1.0 i might work, given an const i : sqrt_minus_1 = "throw up"; fun apply (a:double, b:sqrt_minus_1) => fcomplex (0.0,a); This is a neat trick. Note that 'i' is not a legal value in itself in this formulation. Note also this 'trick' is not so much a hack as you might think! In fact there is a deep theory of field extensions developed by the famous group theorist Galois, which basically corresponds to this trick of taking a structure and 'adding' an abstract symbol. Interestingly we have here a variable of the type, yet it has no values! (Any attempt at evaluation would lead to throwing up when compiling the C++ .. :) -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language