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
[Caml-list] Pattern match floats
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-11-05 (08:27)
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] Pattern match floats

George  Russell writes:
 > I am working through the OReilly book and have got as far as working on 
 > the little basic interpreter. I Am adding support for float type 
 > variables, and am trying to modify the lexer. 
 > I would like to be able to match ('0'..'9')*'.'('0'..'9')* i.e. one or 
 > more digits, a period, followed bt one or more digits.
 > I can't see how to do this in OCaml patter matching? Any ideas?

In ocamllex, such a regular expression is written

   ['0'-'9']* '.' ['0'-'9']*    { your action, probably using 
                                  (float_of_string (lexeme lexbuf) }

Another remark: you  write "one or more digits" but  you are using the
star operation i.e. "zero, one or more digits".

Hope this helps,
Jean-Christophe Filliatre (

Bug reports:  FAQ:
To unsubscribe, mail  Archives: