Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
lexer, parser
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-06-14 (15:46)
From: Christian Lindig <lindig@i...>
Subject: Re: lexer, parser
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