From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA07792; Sat, 13 Jul 2002 13:19:24 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA09328 for ; Sat, 13 Jul 2002 13:19:23 +0200 (MET DST) Received: from postfix1-2.free.fr (postfix1-2.free.fr [213.228.0.130]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6DBJMj12683 for ; Sat, 13 Jul 2002 13:19:22 +0200 (MET DST) Received: from lfs (strasbourg-4-a7-62-147-196-115.dial.proxad.net [62.147.196.115]) by postfix1-2.free.fr (Postfix) with SMTP id C3FE8AB3EE; Sat, 13 Jul 2002 13:19:21 +0200 (CEST) Date: Sat, 13 Jul 2002 13:27:34 +0200 From: Nicolas FRANCOIS (AKA El Bofo) To: Nicolas FRANCOIS (AKA El Bofo) Cc: caml-list@inria.fr Subject: Re: [Caml-list] What's wrong with my parser ? Message-Id: <20020713132734.1239c695.nicolas.francois@free.fr> In-Reply-To: <20020712044121.3f253c69.nicolas.francois@free.fr> References: <20020712044121.3f253c69.nicolas.francois@free.fr> X-Mailer: Sylpheed version 0.7.6 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk OK, this is my new polynom parser, it seems to work OK, thanks to your explanations. let rec parse s = 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 = parse_coeff; e = parse_x >] -> monome n e | [< e = parse_x >] -> monome R.one e in let rec parse_suite = parser | [< ''+'; m = parse_monome; p = parse_suite >] -> m ++ p | [< ''-'; m = parse_monome; p = parse_suite >] -> (opp m) ++ p | [< >] -> zero in match s with parser | [< m = parse_monome >] -> match parse_suite s with | p -> m ++ p and the results : # print (P.parse (Stream.of_string "-1+3X+4X^2"));; [3: -1, 3, 4]- : unit = () # print (P.parse (Stream.of_string ""));; [1: 1]- : unit = () Oups !! What do you think about this ? \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