<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/2aa3ddb9e3c1b0ff7e317fbfff81adfc"
  from="Ryan Tarpine &lt;rtarpine@h...&gt;"
  author="Ryan Tarpine"
  date="2002-07-13T19:45:11"
  subject="Re: [Caml-list] What&apos;s wrong with my parser ?"
  prev="2002/07/e043a80e5aa561a30b0f953db3992b9f"
  next="2002/07/ac9e2089becac45a6611e9f1e9a29ae0"
  prev-thread="2002/07/5a07099df93b470f2f48a69d7d4bf4a2"
  next-thread="2002/07/9e01a26fdd4fa3e55e3d06ab91e39a95"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Re: [Caml-list] What&apos;s wrong with my parser ?">
<msg 
  url="2002/07/2aa3ddb9e3c1b0ff7e317fbfff81adfc"
  from="Ryan Tarpine &lt;rtarpine@h...&gt;"
  author="Ryan Tarpine"
  date="2002-07-13T19:45:11"
  subject="Re: [Caml-list] What&apos;s wrong with my parser ?">
</msg>
</thread>

<contents>
&gt;From: Nicolas FRANCOIS (AKA El Bofo) &lt;nicolas.francois@free.fr&gt;
&gt;To: Nicolas FRANCOIS (AKA El Bofo) &lt;nicolas.francois@free.fr&gt;
&gt;CC: caml-list@inria.fr
&gt;Subject: Re: [Caml-list] What's wrong with my parser ?
&gt;Date: Sat, 13 Jul 2002 13:27:34 +0200
&gt;
&gt;OK, this is my new polynom parser, it seems to work OK, thanks to your
&gt;explanations.
&gt;
&gt;   let rec parse s =
&gt;&lt;snip&gt;
&gt;     let parse_coeff = parser
&gt;       | [&lt; n = R.parse &gt;] -&gt; n
&gt;       | [&lt; &gt;] -&gt; R.one
&gt;     in
&gt;     let parse_monome = parser
&gt;       | [&lt; n = parse_coeff; e = parse_x &gt;] -&gt;
&gt;	  monome n e
&gt;       | [&lt; e = parse_x &gt;] -&gt;
&gt;	  monome R.one e
&gt;&lt;snip&gt;
&gt;     in
&gt;       match s with parser
&gt;	| [&lt; m = parse_monome &gt;] -&gt;
&gt;	    match parse_suite s with
&gt;	      | p -&gt; m ++ p
&gt;
&gt;&lt;snip&gt;
&gt;# print (P.parse (Stream.of_string ""));;
&gt;[1: 1]- : unit = ()
&gt;

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

</contents>

</message>

