From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 338027F75C for ; Sat, 27 Sep 2014 09:21:18 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of Christophe.Raffalli@univ-savoie.fr) identity=pra; client-ip=62.4.25.188; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="raffalli@univ-savoie.fr"; x-sender="Christophe.Raffalli@univ-savoie.fr"; x-conformance=sidf_compatible Received-SPF: SoftFail (mail3-smtp-sop.national.inria.fr: domain of raffalli@univ-savoie.fr is inclined to not designate 62.4.25.188 as permitted sender) identity=mailfrom; client-ip=62.4.25.188; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="raffalli@univ-savoie.fr"; x-sender="raffalli@univ-savoie.fr"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@raffalli.eu) identity=helo; client-ip=62.4.25.188; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="raffalli@univ-savoie.fr"; x-sender="postmaster@raffalli.eu"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgEFAGZkJlQ+BBm8/2dsb2JhbABfgw5TykSIVhYBe4QxLFERNAVJiFUJmVKlV5NTgR0Flh2HCAGBYpN6g2VqgkoBAQE X-IPAS-Result: AgEFAGZkJlQ+BBm8/2dsb2JhbABfgw5TykSIVhYBe4QxLFERNAVJiFUJmVKlV5NTgR0Flh2HCAGBYpN6g2VqgkoBAQE X-IronPort-AV: E=Sophos;i="5.04,608,1406584800"; d="asc'?scan'208";a="81082938" Received: from raffalli.eu ([62.4.25.188]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 27 Sep 2014 09:21:17 +0200 Received: from localhost (bin73-1-78-240-16-62.fbx.proxad.net [78.240.16.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by raffalli.eu (Postfix) with ESMTPSA id CDCB17A00B50 for ; Sat, 27 Sep 2014 09:21:12 +0200 (CEST) Date: Sat, 27 Sep 2014 09:21:12 +0200 From: Christophe Raffalli To: Caml list Message-ID: <20140927072112.GA3574@delli7.univ-savoie.fr> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sm4nu43k4a2Rpi4c" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Validation-by: christophe.raffalli@univ-savoie.fr Subject: [Caml-list] Alpha release of DeCaP (combinator library + extensible OCaml parser) --sm4nu43k4a2Rpi4c Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Dear Caml-list, We are proud to announce the release of a new parser combinator library cal= led DeCaP. It has been used to implement a new extensible parser for OCaml call= ed pa_ocaml, together with a syntax extension for writing parsers using a form= at similar to Backus-Naur Form (BNF). Through this syntax extension, parsers a= re compiled down to calls of DeCaP combinators. In this way, we manage to obta= in a user-friendly syntax for writing parsers, while preserving the advantages= of functional combinators. To give you an idea, we give bellow the example of a small calculator. ## calc_prio.ml ###########################################################= ### open Decap type calc_prio =3D Sum | Prod | Atom let expr, set_expr =3D grammar_family "expr"=20 let float_num =3D let float_re =3D "[0-9]+\\([.][0-9]+\\)?\\([eE][-+]?[0-9]+\\)?" in parser | f:RE(float_re) -> float_of_string f let prod_sym =3D parser | CHR('*') -> ( *. ) | CHR('/') -> ( /. ) let sum_sym =3D parser | CHR('+') -> ( +. ) | CHR('-') -> ( -. ) let _ =3D set_expr (fun prio -> parser | f:float_num when prio =3D Atom -> f | CHR('(') e:(expr Sum) CHR(')') when prio =3D Atom -> e | CHR('-') e:(expr Atom) when prio =3D Atom -> -. e | CHR('+') e:(expr Atom) when prio =3D Atom -> e | e:(expr Atom) l:{fn:prod_sym e':(expr Atom)}* when prio =3D Prod -> List.fold_left (fun acc (fn, e') -> fn acc e') e l | e:(expr Prod) l:{fn:sum_sym e':(expr Prod)}* when prio =3D Sum -> List.fold_left (fun acc (fn, e') -> fn acc e') e l) (* The main loop *) let _ =3D let blank =3D blank_regexp (Str.regexp "[ \t]*") in try while true do Printf.printf ">> %!"; let l =3D input_line stdin in let r =3D handle_exception (parse_string (expr Sum) blank) l in Printf.printf "%f\n%!" r done with End_of_file -> () ###########################################################################= ### The tools to write syntax extensions are similar to those of Camlp4 (quotat= ion and anti-quotation) but are not complete yet (quotation patterns are missin= g). The corresponding part of the documentation is also unfinished. On the side of performances, pa_ocaml is on average five times slower than = the original OCaml parser (implemented using Ocamlyacc) and two times faster th= an Camlp4. The web-page of the project can be found here: http://lama.univ-savoie.fr/decap/ As DeCaP and pa_ocaml are still under development, we would greatly appreciate feedback. We are particularly interested in bug in the OCaml parser. At the moment, the grammar is supposed to be complete from OCaml 3.12.1 to 4.01.0 while some of the extension of 4.02.0 are missing. Our target is to produce identical parse trees compare to those of the original ocamlyacc parser. On our test files, this is achieved up to positions and we are working on positions currently. Bug report on mantis: http://lama.univ-savoie.fr/mantis Rodolphe Lepigre & Christophe Raffalli LAMA, UMR 5127 CNRS - Universit=E9 Savoie Mont Blanc --sm4nu43k4a2Rpi4c Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlQmZWgACgkQi9jr/RgYAS5XSACeM/4zBeDxKz7kmUbbtgryGGFt xIwAn2ZB0r391O+wSD1GYTQrCDBfGnT1 =BMpN -----END PGP SIGNATURE----- --sm4nu43k4a2Rpi4c--