Loading ...
Sorry, an error occurred while loading the content.

Re: "ocaml_beginners"::[] No [< >] parsers in Ocaml 3.04-toplevel

Expand Messages
  • Remi VANICAT
    ... mmm, don t know, but camlp4 do it automagicly, so why bother ? moi@debian:~$ camlp4o pr_o.cmo -impl /dev/stdin
    Message 1 of 4 , May 31, 2002
    • 0 Attachment
      Oliver Bandel <oliver@...-berlin.de> writes:

      > Hello,
      >
      > On Fri, 31 May 2002, Remi VANICAT wrote:
      >
      >> Oliver Bandel <oliver@...-berlin.de> writes:
      >>
      >> > Hello,
      >> >
      >> >
      >> > in the ocaml-toplevel of Ocaml-distribution 3.04 there is no
      >> > possibility of using streams with [< >]-notation.
      >> > The Stream-module is available, but not the other parsers.
      >> >
      >> > What is the difference between [< >] and Stream-module?
      >> >
      >> > Is it possible to convert Example-code with [< >] into
      >> > Code, using Stream-module (and vice versa)?
      >>
      >> yes, it's possible, it is what ocaml do (more or less).
      >
      > How to convert example code from e.g. a book
      > to a Ocaml-code by hand?

      mmm, don't know, but camlp4 do it automagicly, so why bother ?
      moi@debian:~$ camlp4o pr_o.cmo -impl /dev/stdin <<EOF
      > let f = parser
      > [< ''b'; x = g; ''c' >] -> 0
      > | [< y = h; ''d' >] -> 1;;
      > EOF

      let f (strm__ : _ Stream.t) =
      match Stream.peek strm__ with
      Some 'b' ->
      Stream.junk strm__;
      let x =
      try g strm__ with
      Stream.Failure -> raise (Stream.Error "")
      in
      begin match Stream.peek strm__ with
      Some 'c' -> Stream.junk strm__; 0
      | _ -> raise (Stream.Error "")
      end
      | _ ->
      let y = h strm__ in
      match Stream.peek strm__ with
      Some 'd' -> Stream.junk strm__; 1
      | _ -> raise (Stream.Error "")
      ;;

      by the way, this enable you do understood well what stream parser
      really do.

      >
      > Are there some simple rules, to do it?
      >
      >
      >>
      >> >
      >> > What are advantages and disadvantages of the two stream-versions?
      >> >
      >> > Can I use a "#load"-statement from within the toplevel to use
      >> > the [< >]-streams?
      >> >
      >> > What's about compiling? Do I have to use some extra commands
      >> > when compiling, to use the [< >]-streams?
      >> >
      >>
      >> from the documentation :
      >>
      >> 7.1 Streams and stream parsers
      >>
      >> Streams and stream parsers are no longer part of the Objective Caml
      >> language, but available through a CamlP4 syntax extension. See the
      >> CamlP4 reference manual for more information. Objective Caml programs
      >> that use streams and stream parsers can be compiled with the -pp
      >> camlp4o option to ocamlc and ocamlopt.
      >
      > OK, thatmeans that there is no easy way to learn to work
      > with that parsers via the toplevel?

      No, this mean that every thing is explain in the camlp4 manual.

      To be simple :

      #load "camlp4o.cma"

      do the trick

      --
      RĂ©mi Vanicat
      vanicat@labri.u-bordeaux.fr
      http://dept-info.labri.u-bordeaux.fr/~vanicat
    Your message has been successfully submitted and would be delivered to recipients shortly.