lua-users home
lua-l archive

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


On Mon, 2005-01-17 at 22:18, Luiz Henrique de Figueiredo wrote:
> > Well not perfect :) The problem is that to add the sugar,
> > you have to parse the input stream according to your 
> > extended grammar
> 
> There's no way around that, of course. Sugar requires local parsing.

Yes, true by definition :)

> > apply rewriting rules to the subtrees
> > corresponding to reductions, and then rewrite the resultant
> > modified trees out again as token streams.
> 
> Lua's parser does not use trees. 

However the user desugaring parser may have to, depending
on rewriting rules.

> And I think that it is simpler to let
> it raise errors, instead of doing syntax checking for sugar.

Not sure I follow. In the Ocaml package there is a processor
called 'camlp4'. It actually allows you to introduce new
grammar directly into the Ocaml grammar.

It uses a system of quotations and anti-quotations for
easy cases to allow you to rewrite terms in your extended
grammar back to the standard grammar. This processing
occurs *in* the parser, so that you're manipulating
parse/syntax trees directly, not text or token streams.

Felix also has a lame version of this, I have a 
syntax macro processor that manipulates AST terms
directly.

I'm not suggesting this should be done for Lua,
just commenting that this is a way to avoid having
to parse the whole language just to add some sugar.

Extensible parsers are not so easy to write,
and even when written not so easy to use.

> Not quite true: Luckily, the lexer does not raise errors on single-char
> tokens that it does not understand and so you can use those for your own
> purposes, but you're still only allowed to generate good tokens.

Ok. However it isn't clear how two 'extensions' using this
will cooperate..

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net