Merge branch 'smtv2-dont-fail-on-untyped-prover-vars' into 'master'
[why3.git] / examples_in_progress / bigInt / parse.ml
blobacc779474c1b7dd4d18c9a00a536293c1b40126d
2 open BigInt__N
4 exception SyntaxError
6 let times10 a =
7 let a2 = add a a in
8 let a4 = add a2 a2 in
9 let a5 = add a4 a in
10 add a5 a5
12 let parse_dec s idx =
13 let a = ref (from_small_int 0) in
14 let i = ref idx in
15 try
16 while !i < String.length s do
17 match String.get s !i with
18 | '0'..'9' as c ->
19 let d = Char.code c - Char.code '0' in
20 a := add (times10 !a) (from_small_int d);
21 i := succ !i
22 | _ ->
23 raise Exit
24 done;
25 raise Exit
26 with Exit ->
27 if !i = idx then raise SyntaxError else !a,!i
29 let parse_sep_star s idx =
30 let i = ref idx in
31 try
32 while !i < String.length s do
33 match String.get s !i with
34 | ' ' | '\t' | '\n' | '\r' -> i := succ !i
35 | _ -> raise Exit
36 done;
37 raise Exit
38 with Exit -> !i
40 open Format
42 let pr fmt a =
43 let a = a.digits in
44 let l = Array.length a in
45 fprintf fmt "%d" a.(l-1);
46 for i=l-2 downto 0 do
47 fprintf fmt "%04d" a.(i);
48 done