lua-users home
lua-l archive

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


Peter Hill wrote:
> 
> Peter Hill.
> > Ok, I've now written a lex-in-lua module (though not yet exhaustively
> > debugged it). Would you care to look at it and offer some commentary?
> 
> Björn De Meyer:
> > Yes, certainly. If it's less than 10 to 20 Kb, I think it won't harm for
> > you to post it here for all to see. The more eyballs, the merrier. If it's
> > larger, then just mail it to my home address, or maybe put it on the wiki.
> 
> Ok, I guess the list is fairly lightly loaded at the moment, so here it is.
> I don't really think there is much variation available in writing the
> lexical analyser, except for the naming of the functions and the decision as
> to how to handle the look-ahead character (global var, passed parameter as I
> chose, or 'unget').
> 
> Have a look and tell me what you think.
> 
> I'll probably have a tinker with a parser next.
> 
> *cheers*
> Peter Hill.

Hmmm... it looks pretty good. Some small comments:

1) The functions longstring() and skiplong() could be folded
into one function as theyir functionality is almost completelty
identical (it is done like this in C Lua). The same goes for 
scan.dstring() and  scan.sstring(z,c). Again, their functionality 
is similar, so one flexible function for both would perhaps be 
more economic.

2) The lexer needs to keep the line count somehow. This is needed 
for signaling errors (also towards the parser. I think therefore,
it would be more convenient of the the lexer would be a stateful 
object that remembers it's own linecount and lookahead character. 
Then you'd have lexer::get(), lexer::lineno(), lexer::lookahead(),
etc. 

3) The error reporting is a bit rudimentary. For that, I think 
you could use a user-redefinable error function lexer:error() 
that defaults to the lua standard error() function. Or such.

4) In Lua, line ends are linefeeds, not carriage return-line 
feeds. It's considerably harder to have all three the possible
line endings, namely only cr, cr lf and lf. Because of the 
historic background, in Lua it's only lf.

All in all, it looks well written. I'll test it a bit more toroughly 
later on. I'm looking forward to your lua-in-lua parser. 


-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
bjorn.demeyer@pandora.be