English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
index of substring
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-01-27 (17:20)
From: Radu Grigore <radugrigore@g...>
Subject: Re: [Caml-list] index of substring
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.