aboutsummaryrefslogtreecommitdiffstats
path: root/src/lfsc/type.ml
blob: f089abe29e5d29095b5ad8f83444bba23a3918be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(**************************************************************************)
(*                                                                        *)
(*     SMTCoq                                                             *)
(*     Copyright (C) 2011 - 2021                                          *)
(*                                                                        *)
(*     See file "AUTHORS" for the list of authors                         *)
(*                                                                        *)
(*   This file is distributed under the terms of the CeCILL-C licence     *)
(*                                                                        *)
(**************************************************************************)


(** Type of S-expressions *)
type t = Atom of string | List of t list


let rec print fmt = function
  | Atom s -> Format.pp_print_string fmt s
  | List l ->
    Format.fprintf fmt "(";
    List.iter (Format.fprintf fmt "%a " print) l;
    Format.fprintf fmt ")"

let rec print_list fmt = function
  | [] -> ()
  | s :: r ->
    Format.fprintf fmt "%a@." print s;
    print_list fmt r

let rec size = function
  | Atom _ -> 1
  | List l -> List.fold_left (fun acc s -> size s + acc) 0 l

let rec size_list = function
  | [] -> 0
  | s :: r -> size s + size_list r