Skip to content

Commit

Permalink
merge 2 commits/fix in Arbogen.ml
Browse files Browse the repository at this point in the history
  • Loading branch information
MarwanG committed Jul 8, 2014
2 parents 078763e + 6641532 commit 6822b4e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 131 deletions.
6 changes: 4 additions & 2 deletions src/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ ArboLib.cmo : Util.cmo Tree.cmo OracleSimple.cmo Grammar.cmo Gen.cmo \
CombSys.cmo
ArboLib.cmx : Util.cmx Tree.cmx OracleSimple.cmx Grammar.cmx Gen.cmx \
CombSys.cmx
Arbogen.cmo : Tree.cmo Options.cmo Grammar.cmo Gen.cmo
Arbogen.cmx : Tree.cmx Options.cmx Grammar.cmx Gen.cmx
Arbogen.cmo : Tree.cmo ParseUtil.cmo Options.cmo Gen.cmo
Arbogen.cmx : Tree.cmx ParseUtil.cmx Options.cmx Gen.cmx
Ast.cmo : Grammar.cmo
Ast.cmx : Grammar.cmx
CombSys.cmo : Util.cmo Grammar.cmo
Expand All @@ -21,6 +21,8 @@ Options.cmo :
Options.cmx :
OracleSimple.cmo : Util.cmo CombSys.cmo
OracleSimple.cmx : Util.cmx CombSys.cmx
ParseUtil.cmo : Parser.cmi Lexer.cmo
ParseUtil.cmx : Parser.cmx Lexer.cmx
Parser.cmo : Ast.cmo Parser.cmi
Parser.cmx : Ast.cmx Parser.cmi
Test.cmo : WeightedGrammar.cmo Util.cmo Parser.cmi OracleSimple.cmo \
Expand Down
15 changes: 3 additions & 12 deletions src/Arbogen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Arg.parse [
|_ -> eprintf "Error: wrong option value must be strictly arb,dot,xml or all\n...aborting\n";
exit 1;
),
"<n>: set the type of output generated at the end");
"<n>: set the type [arb|dot|xml|all] of output generated at the end");
("-file",Arg.String(fun x->
global_options.fileName <- x;
),
Expand All @@ -151,7 +151,7 @@ Arg.parse [
"<x>: sets the value of zstart");
]
(fun arg ->
if (String.compare global_options.grammar_file "")=0
if (String.compare global_options.grammar_file "") == 0
then global_options.grammar_file <- arg
else (eprintf "Error: grammar file already set, argument '%s' rejected\n%!" arg ; exit 0))
usage;
Expand All @@ -166,18 +166,11 @@ then (eprintf "Error: grammar file not specified\n... arborting.\n%!"; exit 0) ;
if (global_options.verbosity) > 0
then printf "Loading grammar file: %s\n%!" global_options.grammar_file

let grammar =
GParser.parse_from_file global_options.grammar_file ;;
let (_,grammar) = ParseUtil.parse_from_file global_options.grammar_file ;;

if (global_options.verbosity) > 0
then printf "==> Grammar file loaded\n%!" ;;

if (global_options.verbosity) > 2
then begin
printf "==> Grammar completion:\n%!" ;
printf "%s%!" (Grammar.string_of_grammar (Grammar.completion grammar))
end ;;

if (global_options.verbosity) > 0
then printf "Generating tree\n%!" ;;

Expand All @@ -193,8 +186,6 @@ let result =
global_options.epsilon1_factor
global_options.epsilon2
global_options.epsilon2_factor
global_options.with_prefix
global_options.idprefix
global_options.max_try
global_options.ratio_rejected
global_options.max_refine
Expand Down
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
#
# The Caml sources (including camlyacc and camllex source files)

SOURCES = Parser.mly Lexer.mll Options.ml Util.ml Grammar.ml Ast.ml WeightedGrammar.ml CombSys.ml OracleSimple.ml Tree.ml Gen.ml Test.ml
SOURCES = Parser.mly Lexer.mll Options.ml Util.ml Grammar.ml Ast.ml WeightedGrammar.ml CombSys.ml OracleSimple.ml Tree.ml Gen.ml Options.ml Arbogen.ml

# The executable file to generate

EXEC = test
EXEC = arbogen

########################## Advanced user's variables #####################
#
Expand Down
9 changes: 9 additions & 0 deletions src/ParseUtil.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let parse_from_channel chan =
let lexbuf = Lexing.from_channel chan in
let res = Parser.start Lexer.token lexbuf in
close_in chan;
res

let parse_from_file filename =
let chan = open_in filename in
parse_from_channel chan
115 changes: 0 additions & 115 deletions src/Util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,44 +56,6 @@ let npop n q =

(* Array utilities *)

let array_unop (op:'a -> 'b) (init:'b) (a:'a array) : 'b array =
let rec aux i len b =
if i<len
then begin
b.(i) <- (op a.(i)) ;
aux (i+1) len b
end
in
let n = Array.length a
in
let b = Array.make n init
in
aux 0 n b;
b

let array_binop (op:'a -> 'b -> 'c) (init:'c) (a:'a array) (b:'b array) : 'c array =
let rec aux i len c =
if i<len
then begin
c.(i) <- (op a.(i) b.(i)) ;
aux (i+1) len c
end
in
let n = Array.length a
in
let c = Array.make n init
in
aux 0 n c;
c

let string_of_array (tostr:'a -> string) (a : 'a array) : string =
"[" ^ (Array.fold_left (fun str e -> str ^ (tostr e) ^ ",") "" a) ^ "]"



(* modifié pour float on utilise > non >.*)
let array_max (a:float array) = Array.fold_left (fun (max:float) (e:float) -> if e > max then e else max) min_float a

let array_fold_left_2 (f:'a -> 'b -> 'c -> 'a) (init:'a) (b:'b array) (c:'c array) : 'a =
let rec aux i len acc =
if i=len
Expand All @@ -102,19 +64,6 @@ let array_fold_left_2 (f:'a -> 'b -> 'c -> 'a) (init:'a) (b:'b array) (c:'c arra
in
aux 0 (Array.length b) init

let array_fold_it (f:int -> 'a -> 'b -> 'b) (tab:'a array) (unt:'b) : 'b =
let rec aux i max acc =
if i=max then acc
else aux (i+1) max (f i tab.(i) acc)
in
aux 0 ((Array.length tab)-1) unt ;;




let array_clone (a:'a array) (b:'a array) : unit =
Array.blit a 0 b 0 (Array.length a)

(* string set *)

module StringSet = Set.Make (String) ;;
Expand All @@ -123,67 +72,3 @@ module StringSet = Set.Make (String) ;;

module StringMap = Map.Make (String) ;;

let compareStrArr (s:string) (a:string array) : bool =
let l = Array.length a in
let theend = l - 1 in
let r = ref false in
for i = 0 to theend do
if String.compare s a.(i) = 0 then
r := true
done;
!r

let findIndexstr (st:string array) (s:string) : int =
let l = Array.length st in
let theend = l - 1 in
let r = ref 100 in
for i = 0 to theend do
if String.compare s st.(i) = 0 then
r := i
done;
!r


let interval (i1:int) (i2:int) (x:int) : bool =
if (x >= i1) && (x <= i2)
then
true
else
false

let sumTab (t : int array) : int =
let l = Array.length t in
let e = l - 1 in
let r = ref 0 in
for i = 0 to e do
r := !r + t.(i)
done;
!r


(* 0 signifie rien, 1 signifie < à l'interval,-1 signifie > à l'interval *)
let ifAtLeast8Smallerin10OthersBigger (p1:int) (p2:int) (tab:int array) : bool =
let restab = Array.make 10 0 in
for i = 0 to 9 do
if tab.(i) < p1 then
restab.(i) <- 1
else
if tab.(i) > p2 then
restab.(i) <- -1
else
restab.(i) <- 0
done;
let thesumTab = sumTab restab in
if thesumTab >= 6 then
true
else
false









0 comments on commit 6822b4e

Please sign in to comment.