Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] What's wrong with my parser ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas FRANCOIS <nicolas.francois@f...>
Subject: [Caml-list] What's wrong with my parser ?
I define a polynom parser like this :

  let rec parse =
    let parse_puissance = parser
      | [< ''^'; e = parse_int >] -> e
      | [< >] -> 1
    in
    let parse_x = parser
      | [< ''X'; e = parse_puissance >] -> e
      | [< >] -> 0
    in
    let parse_coeff = parser
      | [< n = R.parse >] -> n
      | [< >] -> R.one
    in
    let parse_monome = parser
      | [< n = R.parse; e = parse_x >] ->
	  monome n e
      | [< e = parse_x >] ->
	  monome R.one e
    in
      parser
	| [< ''+'; m = parse_monome; p = parse >] ->
	    m ++ p
	| [< ''-'; m = parse_monome; p = parse >] ->
	    (opp m) ++ p
	| [< m = parse_monome; p = parse >] ->
	    m ++ p
	| [< >] -> zero

parse_int and the R.parse functions work OK, and I'll add all the
"_=parse_space" after. But :

# let p1 = P.parse (Stream.of_string "1+X");;
Stack overflow during evaluation (looping recursion?).

What's the problem ?

\bye

-- 

                   Nicolas FRANCOIS
            http://nicolas.francois.free.fr
 A TRUE Klingon programmer does NOT comment his code
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners