ocaml

How to use functions in Value.Eval_expr, Value.Eval_op etc modules of Frama-c Value plugin

北城以北 提交于 2019-12-23 10:04:11
问题 I am trying to create a frama-c plugin. This plugin depends upon Frama-c Value plugin. I want to obtain and print value set of all the lvalue(s) in a C source code. In order to do that I want to use functions available in Value.Eval_exprs, Value.Eval_op etc. like Eval_exprs.lval_to_precise_loc . Unfortunately I am unable to figure out a way to use these function in my plugin. I tried to follow steps mentioned in section 4.10.1 (Registration through a .mli file) of Frama-c Plugin Development

How applying a function to a variant?

妖精的绣舞 提交于 2019-12-23 09:57:34
问题 Let this types = type intC = int;; type boolC = bool; type stringC = string;; type component = A of intC | B of boolC | C of stringC;; If I want to apply a function on the type a of a component A, do I need systematically to deconstruct the component ? for exemple do i have to do : let add comp = match comp with | A i -> Some (i + 2) (*only A interests me, I return i + 2*) | _ -> None (*otherwise I return nothing*) and then for any function on a component A ? Is there any mean to avoid thy

Setting the prompt in an OCaml custom toplevel

匆匆过客 提交于 2019-12-23 09:34:59
问题 In an OCaml custom toplevel, is there a way to programatically set the prompt from # to something else? I would like to be able to change it in response to the user's last one of my custom functions (kinda like in bash how you can set PS1 ). I can't even find a #directive to change it. Thanks! 回答1: In toplevel/toploop.ml: let prompt = if !Clflags.noprompt then "" else if !first_line then "# " else if Lexer.in_comment () then "* " else " " in But wait! The computed prompt is passed to !read

OCaml forward declaration

偶尔善良 提交于 2019-12-23 09:30:05
问题 Is there a way to do a C-style forward declaration in OCaml? My problem is that I have two variants which mutually refer to each other: type path_formula = [ `Next of state_formula | `Until of (state_formula * state_formula) | `UntilB of (state_formula * int * state_formula) ] type state_formula = [ `True | `False | `Not of state_formula | `And of (state_formula * state_formula) | `Or of (state_formula * state_formula) | `Imply of (state_formula * state_formula) | `Label of string | `Prob` of

last element in list using ocaml List.fold_left

好久不见. 提交于 2019-12-23 09:17:12
问题 I can find the last element of a list by the following code. let last (xs:'a list) : 'a = let rec aux xs prev = match xs with | [] -> prev | x::ys -> aux ys x in match xs with | [] -> failwith "no element" | x::xs -> aux xs x How do I find the last element of the same list using the List.fold_left function in OCaml? Thanks in advance! 回答1: fold_left accesses the list from the head to the tail, thus the function passed to fold_left should just replace the accumulator with the current element

How to return the index of a for loop in OCaml?

霸气de小男生 提交于 2019-12-23 08:38:39
问题 let find_free_next heap start = for i = start to ((Array.length heap)-1) do match heap.(i) with Hdr (Free (h), g) -> i done How can i return the index of a loop as an integer once the match has been found? 回答1: If you want to stick to the imperative style, you can use an exception to exit the loop: exception Found of int let find_free_next heap start = try for i = start to Array.length heap - 1 do match heap.(i) with | Hdr (Free (h), g) -> raise (Found i) | _ -> () (* If it is not what you

How to read a character in OCaml without a return key?

自古美人都是妖i 提交于 2019-12-23 07:59:35
问题 I'm looking for something like input_char stdin but without waiting for a return key. I would not to depend on a big dependency like lambda-term. 回答1: Handling input in full lines is easy. Handling it a character at a time is a little bit system dependent. If you're on a Unix-like system you should be able to do this using the Unix module: let get1char () = let termio = Unix.tcgetattr Unix.stdin in let () = Unix.tcsetattr Unix.stdin Unix.TCSADRAIN { termio with Unix.c_icanon = false } in let

Converting hash table to list of pairs (key,value) in OCaml

試著忘記壹切 提交于 2019-12-23 07:33:36
问题 Is there a way of converting a hash table into a list of (key,pair) values in OCaml? I'm aware that, given a hash table ht we can do BatList.of_enum (BatHashtbl.enum ht) using the batteries library. This would convert the table to an enumeration and then convert the enum to a list. But I'm looking for a solution that doesn't use the Batteries Library. In the standard OCaml Hashtbl Module there doesn't seem to be a way of extracting the pairs as a list or a way of combining its functions to

Converting hash table to list of pairs (key,value) in OCaml

穿精又带淫゛_ 提交于 2019-12-23 07:32:31
问题 Is there a way of converting a hash table into a list of (key,pair) values in OCaml? I'm aware that, given a hash table ht we can do BatList.of_enum (BatHashtbl.enum ht) using the batteries library. This would convert the table to an enumeration and then convert the enum to a list. But I'm looking for a solution that doesn't use the Batteries Library. In the standard OCaml Hashtbl Module there doesn't seem to be a way of extracting the pairs as a list or a way of combining its functions to

Regular Expressions in OCaml

旧巷老猫 提交于 2019-12-23 06:48:17
问题 I want to use regexps in OCaml and it seems that Str module provides these functionalities. So I tried with a simple program: open Str let regx = regexp "." but it gives me the following error File "lol.ml", line 1, characters 0-1: Error: Error while linking lol.cmo: Reference to undefined global `Str' As if module is not present but if I remove open Str it says that regexp is an unbound value. I don't get what kind of issue it is, Str should be a standard module (according to http://caml