A question about ParseC library

Daan Leijen daanleijen@xs4all.nl
Sat, 12 Jul 2003 10:23:17 +0200


Hi Yu Di,

> Hi, I want to have a parser like:
> 
> p = 
>       do 
>         eof
>         return something
>   <|> do
>         patternA
>         update_parser_state
>         p
>   <|> do
>         patternB
>         update_parser_state_in_another_way
>         p
>   <|> do
>         anyToken
>         p
> 
> [snip]
>
> I did it in the above recursive fashion, but when I
> ran it, it caused a stack overflow error. So what is
> the best way to do this kind of parsing? 

It seems to me that this program should *not* cause a stack
overflow unless something more is happening in patternX or
update_parser_state_X  than I can see.  Maybe you can
send the entire source (or at least the relevant parts)?

Normally, a stack overlow only occurs when you write a 
non-accumulating function, in your case something like:

 p = do ...
        x <- p
        return (.. x... )
 
The (<|>) combinators are carefully structured to prevent
holding on to input and will not cause the stack overflow
(unless you are using "try" in devious ways :-)

Hope this helps,
All the best,
  Daan.


> Thanks!
> 
> Di, Yu
> 7.11
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> _______________________________________________
> Libraries mailing list
> Libraries@haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
> 
>