On 28 Jan 2005 03:55:36 +1100, skaller <skaller@users.sourceforge.net> wrote:
> Well it doesn't handle (* or *) in strings ..
Making things complicated just for fun isn't actually fun.
The fact is that a finite automaton by itself cannot detect matching
delimiters. Finite implies that the automaton can't count (at least
countable sets) and matching requires counting. Sure, there are lots
of nuances here: what does countable mean when you use 32b for
integers,... but that's splitting the hair. The basic idea remains
even after you look at these additional details.
So if you want to detect matching delimiters you need a counter. You
can either use an explicit one or use the stack as Jean-Christophe
Filliatre did.
> In particular the recursion only works 'by luck of
> the implementation' that allows sharing of a lexbuf
> between two lexer functions
What do you mean "by luck"? The documentation clearly passes the
lexbuf from one lexer to the other a few times. If the spec says it's
possible then in what way is it "luck"?
> -- who knows how
> the lexer handles fallbacks?
IMO adding a
_ -> failwith "some error message"
whenever the programmer fails to provide an explicit "else" branch is
just fine. In fact I would prefer a "compile" error to be emitted by
ocamllex (or at least a warning) when such a clause is missing from
one lexer.
--
regards,
radu
http://rgrig.idilis.ro/