lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sun, 2005-01-30 at 23:10, Gunnar Zötl wrote:
> s> This post is VERY useful to me: a heap of issues are raised
> s> and some possible solutions indicated. Thanks!!
> and both Ricis and your posting was quite helpful to me, so thanks
> from me, too. Eventhough yours was a bit pessimistic. It is quite
> clear to me that it will only be possible to sensibly handle macros
> within a few points of the parser, but that's good enough for me. 

Ahem .. well since waffling all over the place I thought
I'd actually look at the core parser function... :)

It would seem there are a couple of places
where one could easily insert parsing hooks.

The difficulty would be that the parser is all 'private'
and not Lua aware. The parsing functions are 'static'
(have internal linkage) and such things as the
operator precedence tables are just plain old C data structures.

To fix this, the parse would have to be 'exported' into
the CAPI, and get some of its data from Lua tables, rather
than C. This would slow down the parsing a bit but I doubt
this is a problem. More difficult, it would use some Lua
memory. And the code would be slightly more complex,
eg C code fetching an operator precedence would be


in C, but the C for a Lua table lookup would be a bit longer.

On the other hand .. some of the bytecode interpreter
is non-modular and a bit ugly. See for example the
code for addition -- have a go at floats, otherwise
try first argument meta-table, if not try second one .. 
messy! (And also theoretically flawed :)

It would actually be cleaner to get rid of operators
from the core completely. Functions are good enough.
Just call the 'add' function listed in the table
for operator '+'. Or operator '*' ... or any operator.

> As for "the whole thing": Dylan shows quite well that it can be done
> even for an algol-like syntax. I would not want to even come close to
> that kind of complexity for lua, though.

Contrarily, generalising Lua to allow such stuff should
probably *simplify* the core, for example as above.

BTW: Felix does this. The parser translates

	a + b


	apply(add, (a,b))

The Felix language core doesn't know what an operator is.
It knows how to apply a function though, and that is enough.

In Felix this doesn't impact run time performance,
in Lua eliminating +-*/ opcodes and using a function
call instead might.. but it would be much easier to
extend .. YMMV here.

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language