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
lazy evaluation of combinator parsers
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-03-24 (01:28)
From: Jeffrey Loren Shaw <shawjef3@m...>
Subject: lazy evaluation of combinator parsers
Hello fellow Camlers, 

I'm trying to write a combinator parser in ocaml that uses lazy evaluation. 
My goal is that it won't get stuck on infinite loops. So for instance I want 
to be able to parse something like (in regex syntax) 


let alt p1 p2 xs = append (p1 xs) (p2 xs) 

(* regex ? *)
let opt a = alt a epsilon 

let rec recseq a =
   (recseq a) 

(* regex * *)
let rec star a =
 recseq (opt a) 

However, "star (symbol 'a')" causes a stack overflow. I'm not sure why, 
since my seq and alt functions are lazy. seq depends on fold_right, map and 
append, and alt depends on append. fold_right, map and append are all lazy. 
The definitions of alt and seq contain no Lazy.forces. 



I would greatly appreciate any help!