List Info

Thread: "ocaml_beginners"::[] simple examples of stream parsers




"ocaml_beginners"::[] simple examples of stream parsers
country flaguser name
United States
2007-08-20 15:16:13

I am trying to learn about stream parsers (with or without Camlp4).
Some simple examples would really help, but the documentation is
sparse. Can someone please suggest implementations for the following
functions. (Stream parsers may not be the best way to implement these,
but I think they will help get started with stream parsers).

val parse_int : char Stream.t -> int

val parse_line : char Stream.t -> string
(* return the characters up to but not including the end of line
marker, where the marker is either a newline 'n', or a 'r'
immediately followed by 'n'. *)

The following would be useful to process a file line by line.
type line = string
val channelToLineStream : in_channel -> line Stream.t

Eventually, I would like a module that allows me to flexibly process
files with rows of data, but without loading the file in memory since
they will be very large. Thanks for any help!

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] simple examples of stream parsers
country flaguser name
France
2007-08-20 13:39:56

On Mon, 20 Aug 2007 20:16:13 -0000
&quot;Ashish Agarwal&quot; < agarwal1975%40gmail.com">agarwal1975gmail.com> wrote:

> I am trying to learn about stream parsers (with or without Camlp4).
> Some simple examples would really help, but the documentation is
> sparse.
http://pauillac.inria.fr/~cheno/CamlPrimer.pdf
P82, paragraph 16 ... in french however.

Regards.

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] simple examples of stream parsers
country flaguser name
United Kingdom
2007-08-20 16:03:23

On Monday 20 August 2007 21:16:13 Ashish Agarwal wrote:
&gt; I am trying to learn about stream parsers (with or without Camlp4).
> Some simple examples would really help, but the documentation is
> sparse. Can someone please suggest implementations for the following
> functions. (Stream parsers may not be the best way to implement these,
&gt; but I think they will help get started with stream parsers).
>
&gt; val parse_int : char Stream.t -> int
>
> val parse_line : char Stream.t -> string
&gt; (* return the characters up to but not including the end of line
>; marker, where the marker is either a newline 'n', or a 'r'
> immediately followed by 'n'. *)
>
> The following would be useful to process a file line by line.
&gt; type line = string
&gt; val channelToLineStream : in_channel -> line Stream.t
>
>; Eventually, I would like a module that allows me to flexibly process
> files with rows of data, but without loading the file in memory since
&gt; they will be very large. Thanks for any help!

You may be interested in our examples:

http://www.ffconsultancy.com/ocaml/benefits/parsing.html
http://www.ffconsultancy.com/ocaml/benefits/interpreter.html

Various techniques to lexing and parsing will be described in detail in the
next few OCaml Journal articles. You may also wish to look at ocamllex,
ocamlyacc, menhir, dpygen, camlp4 and parser combinators.

I also posted several related examples recently on the main caml-list and the
newsgroup comp.lang.functional.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )