Re: lexer, parser

From: Christian Lindig (
Date: Mon Jun 14 1999 - 09:15:43 MET DST

Date: Mon, 14 Jun 1999 09:15:43 +0200
From: Christian Lindig <>
To: John Skaller <>,
Subject: Re: lexer, parser
In-Reply-To: <>; from John Skaller on Thu, Jun 03, 1999 at 09:55:54PM +1000

Quoting John Skaller (
> I need to maintain state, but the component also need
> to be re-entrant.

Quoting Jean-Marc EBER (
> You should certainly be in contact with Christian Lindig, who has
> done interesting work on OCamlLex.


Like Jean-Marc Eber pointed out have I suggested two extension for
OCamlLex that makes maintaining state easier:

A patched version of OCamlLex allows for additional parameters to

    rule scan x y = parse

Parameters like x and y make it easier to accumulate results across
many calls of the same or different rules in a lexer. They help to
avoid global variables which make a scanner no longer re-entrant.

Using the patched version of OCamlLex is fairly uncritical because
only the generated code if different from the original version.

Maintaining state across different invocations of a lexer requires
some more effort:

I have proposed a new Lexing module with a new `lexbuf' type. The
lexbuf type is used by scanners to maintain state but currently does
not hold user provided state. The proposed module permits to store
user state in lexbuf as well.

Unfortunately is it not possible to simply exchange the new module for
the old. The whole OCaml system must be recompiled with the new
module. However, all old code compiles with the new system.

I still would like to see both proposals added to the OCaml system
since both are backward compatible at the source code level.

-- Christian

 Christian Lindig       Technische Universitaet Braunschweig, Germany

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:23 MET