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 VAA15516; Sat, 13 Jul 2002 21:45:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA15519 for ; Sat, 13 Jul 2002 21:45:10 +0200 (MET DST) Received: from hotmail.com (f217.law8.hotmail.com [216.33.241.217]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6DJidf06202 for ; Sat, 13 Jul 2002 21:44:41 +0200 (MET DST) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sat, 13 Jul 2002 12:44:38 -0700 Received: from 68.82.51.136 by lw8fd.law8.hotmail.msn.com with HTTP; Sat, 13 Jul 2002 19:44:38 GMT X-Originating-IP: [68.82.51.136] From: "Ryan Tarpine" To: nicolas.francois@free.fr Cc: caml-list@inria.fr Subject: Re: [Caml-list] What's wrong with my parser ? Date: Sat, 13 Jul 2002 15:44:38 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 13 Jul 2002 19:44:38.0608 (UTC) FILETIME=[B9451D00:01C22AA5] Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >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 ? >Date: Sat, 13 Jul 2002 13:27:34 +0200 > >OK, this is my new polynom parser, it seems to work OK, thanks to your >explanations. > > let rec parse s = > > 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 > match s with parser > | [< m = parse_monome >] -> > match parse_suite s with > | p -> m ++ p > > ># print (P.parse (Stream.of_string ""));; >[1: 1]- : unit = () > Parsing the empty string calls parse_monome, which calls parse_coeff, which returns R.one. My take at this is that you need 2 versions of parse_x: one that requires an X to be there, and one that can parse an X but doesn't need it. If there is no leading coefficient (the second option to parse_monome), the X *must* be there. If the coeffecient is there (the first option), then the X doesn't have to be. The empty string, which has no coefficient, should fail parse_monome because it doesn't have an X either. If passed the string "X" or "2", though, parse_monome should succeed. Ryan Tarpine, rtarpine@hotmail.com "To err is human, to compute divine. Trust your computer but not its programmer." - Morris Kingston _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com ------------------- 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