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: skaller <skaller@u...>
Subject: Re: [Caml-list] lazy evaluation of combinator parsers
On Fri, 2007-03-23 at 21:28 -0400, Jeffrey Loren Shaw wrote:

> 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. 

Arguments are evaluated right to left eagerly, so

let rec recseq a = seq a (recseq a) 

is instantly an infinite loop. seq is not called here,
it's second argument diverges.



-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net