<?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/2883b78ed3d95e9729ba61b17cb910fc"
  from="Nicolas FRANCOIS &lt;nicolas.francois@f...&gt;"
  author="Nicolas FRANCOIS"
  date="2002-07-13T11:19:24"
  subject="Re: [Caml-list] What&apos;s wrong with my parser ?"
  prev="2002/07/2ac9d58aa16c8368308e1957e6724b77"
  next="2002/07/e279811039f13ecb6fc02cdc51f40b4f"
  prev-in-thread="2002/07/4646ea3840468a1a992752add8269c3d"
  prev-thread="2002/07/4e07fd5ea13c7b76f164f1ee5265fa6c"
  next-thread="2002/07/b0c7298c9c0bead77bcf8ed319d71bf4"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] What&apos;s wrong with my parser ?">
<msg 
  url="2002/07/1fdaa5e902b0c73415d567249ed998ad"
  from="Nicolas FRANCOIS &lt;nicolas.francois@f...&gt;"
  author="Nicolas FRANCOIS"
  date="2002-07-12T02:33:12"
  subject="[Caml-list] What&apos;s wrong with my parser ?">
<msg 
  url="2002/07/7185ceed122bb848370dcb84ee239d6e"
  from="John Prevost &lt;j.prevost@c...&gt;"
  author="John Prevost"
  date="2002-07-12T02:42:17"
  subject="Re: [Caml-list] What&apos;s wrong with my parser ?">
</msg>
<msg 
  url="2002/07/895c189fc1924ba0778af55006e0dbc8"
  from="John Prevost &lt;j.prevost@c...&gt;"
  author="John Prevost"
  date="2002-07-12T02:52:48"
  subject="Re: [Caml-list] What&apos;s wrong with my parser ?">
<msg 
  url="2002/07/4646ea3840468a1a992752add8269c3d"
  from="Daniel de Rauglaudre &lt;daniel.de_rauglaudre@i...&gt;"
  author="Daniel de Rauglaudre"
  date="2002-07-12T07:14:24"
  subject="Re: [Caml-list] What&apos;s wrong with my parser ?">
</msg>
</msg>
<msg 
  url="2002/07/2883b78ed3d95e9729ba61b17cb910fc"
  from="Nicolas FRANCOIS &lt;nicolas.francois@f...&gt;"
  author="Nicolas FRANCOIS"
  date="2002-07-13T11:19:24"
  subject="Re: [Caml-list] What&apos;s wrong with my parser ?">
</msg>
</msg>
</thread>

<contents>
OK, this is my new polynom parser, it seems to work OK, thanks to your
explanations.

  let rec parse s =
    let parse_puissance = parser
      | [&lt; ''^'; e = parse_int &gt;] -&gt; e
      | [&lt; &gt;] -&gt; 1
    in
    let parse_x = parser
      | [&lt; ''X'; e = parse_puissance &gt;] -&gt; e
      | [&lt; &gt;] -&gt; 0
    in
    let parse_coeff = parser
      | [&lt; n = R.parse &gt;] -&gt; n
      | [&lt; &gt;] -&gt; R.one
    in
    let parse_monome = parser
      | [&lt; n = parse_coeff; e = parse_x &gt;] -&gt;
	  monome n e
      | [&lt; e = parse_x &gt;] -&gt;
	  monome R.one e
    in
    let rec parse_suite = parser
      | [&lt; ''+'; m = parse_monome; p = parse_suite &gt;] -&gt;
	  m ++ p
      | [&lt; ''-'; m = parse_monome; p = parse_suite &gt;] -&gt;
	  (opp m) ++ p
      | [&lt; &gt;] -&gt; zero
    in
      match s with parser
	| [&lt; m = parse_monome &gt;] -&gt;
	    match parse_suite s with
	      | p -&gt; 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

</contents>

</message>

