From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p6TFEoSv024991 for ; Fri, 29 Jul 2011 17:14:50 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhgEAAnOMk5Vcza+kWdsb2JhbAA2BS1TGAErIiIjLwEFI4JRpQ8UAQEBAQkLCwcUBBoHiH4Cn0+fSIViXwSjXQ X-IronPort-AV: E=Sophos;i="4.67,287,1309730400"; d="scan'208,217";a="104232394" Received: from cluster-j.mailcontrol.com ([85.115.54.190]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Jul 2011 17:14:44 +0200 Received: from emea-outbound.3ds.com (emea-outbound.3ds.com [91.103.40.254]) by rly33j.srv.mailcontrol.com (MailControl) with ESMTP id p6TFBKXP009151 for ; Fri, 29 Jul 2011 16:14:29 +0100 Received: from EU-DCC-MBX01.dsone.3ds.com ([169.254.1.53]) by EU-DCC-HUB02.dsone.3ds.com ([10.22.115.32]) with mapi id 14.01.0289.008; Fri, 29 Jul 2011 17:13:42 +0200 From: WEIL Daniel To: "caml-list@inria.fr" Thread-Topic: menhir and ocamlbuild :some small issues and correction proposal Thread-Index: AcxOAhk7I1e3Gj6YQNOswf1qvrGEgQ== Date: Fri, 29 Jul 2011 15:13:41 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-cr-hashedpuzzle: AMpb AmNt A/Pq BiYk Bps6 D7kg EDi3 ER10 Ehed EwXG FgpF FqwJ FyHH F3O3 GKC5 Jbo8;1;YwBhAG0AbAAtAGwAaQBzAHQAQABpAG4AcgBpAGEALgBmAHIA;Sosha1_v1;7;{3DCBFD30-8166-4C86-A4B2-C39AD38247EE};ZABhAG4AaQBlAGwALgB3AGUAaQBsAEAAMwBkAHMALgBjAG8AbQA=;Fri, 29 Jul 2011 15:13:40 GMT;bQBlAG4AaABpAHIAIABhAG4AZAAgAG8AYwBhAG0AbABiAHUAaQBsAGQAIAA6AHMAbwBtAGUAIABzAG0AYQBsAGwAIABpAHMAcwB1AGUAcwAgAGEAbgBkACAAYwBvAHIAcgBlAGMAdABpAG8AbgAgAHAAcgBvAHAAbwBzAGEAbAA= x-cr-puzzleid: {3DCBFD30-8166-4C86-A4B2-C39AD38247EE} x-originating-ip: [192.168.94.130] Content-Type: multipart/alternative; boundary="_000_BB79AD1BA99F364E9AAB6645B73029AD3677A92AEUDCCMBX01dsone_" MIME-Version: 1.0 X-Scanned-By: MailControl A-12-00-01 (www.mailcontrol.com) on 10.74.0.143 Subject: [Caml-list] menhir and ocamlbuild :some small issues and correction proposal --_000_BB79AD1BA99F364E9AAB6645B73029AD3677A92AEUDCCMBX01dsone_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, I'm using ocamlbuild and menhir to compile my project. I was faced with som= e small issues and decided to try some small patches on the menhir source c= ode, which I explain below. 1) Error found with --infer options have bad location When ocamlbuild invoke menhir to file which is in a sub-directory, ie launc= h the command "menhir --infer MyDir/MyParser.mly", if I have a type error i= n my parser, I get the message File "MyParser.mly", line 32, characters 41-42: ... Instead of File "MyDir/MyParser.mly", line 32, characters 41-42: ... I understand this is because in the generated file MyDir/MyParser.ml, the #= line directives are written # 239 " MyParser.mly " instead of # 239 "MyDir/MyParser.mly " So I try to make a little change in menhir's source files. In file error.ml= , I commented out the "Filename.basename" : let set_filename name =3D basename :=3D Some ((* Filename.basename *)name); filemark :=3D Mark.fresh() and idem in back.ml : let write program =3D let module P =3D Printer.Make (struct let filename =3D Settings.base ^ ".ml" let f =3D open_out filename let locate_stretches =3D if Settings.infer then (* Typechecking should not fail at this stage. Omit #line directives.= *) None else Some ((* Filename.basename *) filename) let raw_stretch_action =3D false end) in P.program program This is correct the issue but I do not know if it is the good correction. A= t least, this seems the way ocamlyacc works. 2) Ocamlbuild, menhir and the -table option Ocamlbuild fails is menhir is used with "-table" option because it does'nt = link with the MenhirLib library (--table option is required when grammar be= comes large). So I changed the two menhir's makefiles to generate .cma and = .cmxa and create the following ocamlbuild's plugin: open Ocamlbuild_plugin;; open Command;; let menhirLibDir () =3D Command.execute( Cmd (Sh "menhir --suggest-comp-flags --table > tmp.txt")= ); let path =3D match string_list_of_file ( "tmp.txt") with | [_;path] -> path | _ -> assert false in rm_f "tmp.txt"; path ;; dispatch begin function | After_rules -> let menhirLibDir =3D menhirLibDir () in ocaml_lib ~extern:true ~dir:menhirLibDir ~tag_name:"use_menhir_table" "me= nhirLib"; flag [ "ocaml" ; "menhir";"use_menhir_table" ] (S[A "--table"]); | _ -> () end;; and with the following _tags flag, it compiles: <**/*.ml>: use_menhir_table <**/*.mly>: explain, use_menhir_table true: use_menhir <**/*.{byte,native}>: use_menhir_table Maybe could this changes be integrated in the official myocamlbuild source = files ? 3) Menhir (like ocamlyacc) only raise a warning when it finds a shift= /reduce or reduce/reduce conflict. I propose to add an option "--conflict-is-error" which make menhir fail if = it finds conflicts. Changes are very small in menhir source code. I have ad= ded the option in Setting.ml and change the "report statistic" code from let () =3D if !shift_reduce =3D 1 then Error.warning "one state has shift/reduce conflicts." else if !shift_reduce > 1 then Error.warning (Printf.sprintf "%d states have shift/reduce conflicts." = !shift_reduce); if !reduce_reduce =3D 1 then Error.warning "one state has reduce/reduce conflicts." else if !reduce_reduce > 1 then Error.warning (Printf.sprintf "%d states have reduce/reduce conflicts."= !reduce_reduce) to let () =3D let print =3D if !Settings.conflict_is_error then (fun s -> Error.signalN= [] ("Error: "^s)) else Error.warning in if !shift_reduce =3D 1 then print "one state has shift/reduce conflicts." else if !shift_reduce > 1 then print (Printf.sprintf "%d states have shift/reduce conflicts." !shift_r= educe); if !reduce_reduce =3D 1 then print "one state has reduce/reduce conflicts." else if !reduce_reduce > 1 then print (Printf.sprintf "%d states have reduce/reduce conflicts." !reduce= _reduce) Could these patches be integrated in Menhir next release ? Daniel Weil PS : as the menhir-list doesn't seems to work, I'm using the caml-list. This email and any attachments are intended solely for the use of the indiv= idual or entity to whom it is addressed and may be confidential and/or priv= ileged. If you are not one of the named recipients or have received this email in e= rror, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this em= ail and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsi= bility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer --_000_BB79AD1BA99F364E9AAB6645B73029AD3677A92AEUDCCMBX01dsone_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hello,

 

 

I’m using ocamlbuild and = menhir to compile my project. I was faced with some small issues and decide= d to try some small patches on the menhir source code, which I explain belo= w.

 

1)      Error found with --infer o= ptions have bad location

Wh= en ocamlbuild invoke menhir to file which is in a sub-directory, ie launch = the command "menhir --infer MyDir/MyParser.mly", if I have a type= error in my parser, I get the message

&n= bsp;

Fi= le "MyParser.mly", line 32, characters 41-42: ...

&n= bsp;

In= stead of

&n= bsp;

Fi= le "MyDir/MyParser.mly", line 32, characters 41-42: ...

&n= bsp;

I = understand this is because in the generated file MyDir/MyParser.ml, the #li= ne directives are written

&n= bsp;            = ;   # 239 " MyParser.mly "

in= stead of

&n= bsp;            = ;   # 239 "MyDir/MyParser.mly "

&n= bsp;

So I try to make a little chang= e in menhir’s source files. In file error.ml, I commented out the = 220;Filename.basename” :

let set_filen= ame name =3D

  basena= me :=3D Some ((* Filename.basename  *)name);

  filema= rk :=3D Mark.fresh()

 

and idem in back.ml :

let write pro= gram =3D

  let mo= dule P =3D Printer.Make (struct

  &= nbsp; let filename =3D Settings.base ^ ".ml"

  &= nbsp; let f =3D open_out filename

  &= nbsp; let locate_stretches =3D

  &= nbsp;   if Settings.infer then

  &= nbsp;   (* Typechecking should not fail at this stage. Omit #line= directives. *)

  &= nbsp;   None

  &= nbsp;   else

  &= nbsp;   Some ((* Filename.basename *) filename)

  &= nbsp; let raw_stretch_action =3D false

  end) i= n

  P.prog= ram program

 

This is correct the issue but I do not know if it is the good co= rrection. At least, this seems the way ocamlyacc works.

 

2)      Ocamlbuild, men= hir and the –table option

Ocamlbuild fails is menhir is used with “—tab= le” option because it does’nt link with the MenhirLib library (= --table option is required when grammar becomes large). So I changed the two menhir’= ;s makefiles to generate .cma and .cmxa and create the following ocamlbuild= ’s plugin:

open Ocamlbui= ld_plugin;;

open Command;= ;

 =

let menhirLib= Dir () =3D

  C= ommand.execute( Cmd (Sh "menhir --suggest-comp-flags --table > tmp.= txt"));

  let pa= th =3D match string_list_of_file ( "tmp.txt") with

  &= nbsp; | [_;path] -> path

  &= nbsp; | _ -> assert false in

  rm_f &= quot;tmp.txt";

  path

;;

 =

dispatch begi= n function

| After_rules= ->

  let me= nhirLibDir =3D menhirLibDir () in

  ocaml_= lib ~extern:true ~dir:menhirLibDir ~tag_name:"use_menhir_table" &= quot;menhirLib";

  f= lag [ "ocaml" ; "menhir";"use_menhir_table" ]= (S[A "--table"]);

| _ -> ()<= /span>

end;;<= /p>

 

and with the following _tags fl= ag, it compiles:

<**/*.ml&g= t;: use_menhir_table

<**/*.mly&= gt;: explain, use_menhir_table

true: use_men= hir

<**/*.{byt= e,native}>: use_menhir_table

 =

Maybe could this changes be int= egrated in the official myocamlbuild source files ?

 

 

3)      Menhir (like ocamlyacc) on= ly raise a warning when it finds  a shift/reduce or reduce/reduce conf= lict.

I propose to add an opti= on “--conflict-is-error” which make menhir fail if it finds con= flicts. Changes are very small in menhir source code. I have added the opti= on in Setting.ml and change the “report statistic” code from

 

let () =3D

  if !sh= ift_reduce =3D 1 then

  &= nbsp; Error.warning "one state has shift/reduce conflicts."<= /span>

  else i= f !shift_reduce > 1 then

  &= nbsp; Error.warning (Printf.sprintf "%d states have shift/reduce confl= icts." !shift_reduce);

  if !re= duce_reduce =3D 1 then

  &= nbsp; Error.warning "one state has reduce/reduce conflicts."

  else i= f !reduce_reduce > 1 then

  &= nbsp; Error.warning (Printf.sprintf "%d states have reduce/reduce conf= licts." !reduce_reduce)

 

to

 

let () =3D

  let pr= int =3D if !Settings.conflict_is_error then (fun s -> Error.signalN [] (= "Error: "^s)) else Error.warning in

  i= f !shift_reduce =3D 1 then

  &= nbsp; print "one state has shift/reduce conflicts."

  else i= f !shift_reduce > 1 then

  &= nbsp; print (Printf.sprintf "%d states have shift/reduce conflicts.&qu= ot; !shift_reduce);

  if !re= duce_reduce =3D 1 then

  &= nbsp; print "one state has reduce/reduce conflicts."

  else i= f !reduce_reduce > 1 then

  &= nbsp; print (Printf.sprintf "%d states have reduce/reduce conflicts.&q= uot; !reduce_reduce)

 

 

Could these patches be integrat= ed in Menhir next release ?

 

Daniel Weil

 

PS : as the menhir-list doesn&#= 8217;t seems to work, I’m using the caml-list.

 

 

 

This email and any attachments are intended solely for the use of the indiv= idual or entity to whom it is addressed and may be confidential and/or priv= ileged.

If you are not one of the named recipients or have received this email in e= rror,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this em= ail and all attachments,

(iii) Dassault Systemes does not accept or assume any liability or responsi= bility for any use of or reliance on this email.

For other languages, go to http://www.3ds.com/terms/email-disclaimer

--_000_BB79AD1BA99F364E9AAB6645B73029AD3677A92AEUDCCMBX01dsone_--