Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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) 

a* 

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

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

let rec recseq a =
 seq
   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. 

sources: 

http://www.msu.edu/~shawjef3/combparslazy3.ml
http://www.msu.edu/~shawjef3/lazylist3.ml 

I would greatly appreciate any help! 

Jeff