diff --git a/core/KaSa_rep/frontend/prepreprocess.ml b/core/KaSa_rep/frontend/prepreprocess.ml index 8ffd8fbe6..02664127b 100644 --- a/core/KaSa_rep/frontend/prepreprocess.ml +++ b/core/KaSa_rep/frontend/prepreprocess.ml @@ -1008,4 +1008,5 @@ let translate_compil parameters error Ast.tokens = compil.Ast.tokens; Ast.volumes = compil.Ast.volumes; Ast.guard_param_values = compil.Ast.guard_param_values; + Ast.conflicts = compil.Ast.conflicts; } ) diff --git a/core/grammar/ast.ml b/core/grammar/ast.ml index 5a7bad24f..9aeb9ea7e 100644 --- a/core/grammar/ast.ml +++ b/core/grammar/ast.ml @@ -166,6 +166,7 @@ type ('agent, 'agent_id, 'pattern, 'mixture, 'id, 'rule) instruction = * string LKappa.guard option * 'rule Loc.annoted) | GUARD_PARAM of (string Loc.annoted * bool) + | CONFLICT of (string Loc.annoted * string Loc.annoted * string Loc.annoted) type ('pattern, 'mixture, 'id, 'rule) command = | RUN of ('pattern, 'id) Alg_expr.bool Loc.annoted @@ -192,6 +193,8 @@ type ('agent, 'agent_sig, 'pattern, 'mixture, 'id, 'rule) compil = { volumes: (string * float * string) list; guard_param_values: (string Loc.annoted * bool) list; (** The guard parameters that have a defined value (true or false).*) + conflicts: (string Loc.annoted * string Loc.annoted * string Loc.annoted) list; + (** A conflict (A, s1, s2) states that there might be a conflict between the two sites s1, s2 of the agent A.*) } type parsing_compil = (agent, agent_sig, mixture, mixture, string, rule) compil @@ -234,6 +237,7 @@ let empty_compil = tokens = []; volumes = []; guard_param_values = []; + conflicts = []; } (* @@ -1122,7 +1126,7 @@ let print_perturbation f ((alarm, cond, modif, rep), _) = rep let print_parsing_compil_kappa f c = - Format.fprintf f "@[%a@,@,%a@,%a@,@,%a@,@,%a@,%a@,@,%a@,@,%a@,%a@,@]@." + Format.fprintf f "@[%a@,@,%a@,%a@,@,%a@,@,%a@,%a@,@,%a@,@,%a@,%a@,%a@,@]@." (Pp.list Pp.space print_configuration) c.configurations (Pp.list Pp.space (fun f a -> @@ -1153,6 +1157,9 @@ let print_parsing_compil_kappa f c = (Pp.list Pp.space (fun f ((s, _), b) -> Format.fprintf f "%%guard_param: %s -> %b" s b)) c.guard_param_values + (Pp.list Pp.space (fun f ((a, _), (s1, _), (s2, _)) -> + Format.fprintf f "%%conflict: %s %s %s" a s1 s2)) + c.conflicts let arrow_notation_to_yojson filenames f_mix f_var r = JsonUtil.smart_assoc @@ -1738,6 +1745,13 @@ let compil_to_json c = (Loc.string_annoted_to_json ~filenames) JsonUtil.of_bool) c.guard_param_values ); + ( "conflicts", + JsonUtil.of_list + (JsonUtil.of_triple + (Loc.string_annoted_to_json ~filenames) + (Loc.string_annoted_to_json ~filenames) + (Loc.string_annoted_to_json ~filenames)) + c.conflicts ); ] let compil_of_json = function @@ -1843,6 +1857,17 @@ let compil_of_json = function (JsonUtil.exn_msg_cant_import_from_json "AST guard_param_values boolean value"))) (List.assoc "guard_param_values" l); + conflicts = + JsonUtil.to_list + ~error_msg: + (JsonUtil.exn_msg_cant_import_from_json "AST conflicts sig") + (JsonUtil.to_triple + ~error_msg: + (JsonUtil.exn_msg_cant_import_from_json "AST conflicts sig") + (Loc.string_annoted_of_json ~filenames) + (Loc.string_annoted_of_json ~filenames) + (Loc.string_annoted_of_json ~filenames)) + (List.assoc "conflicts" l); } with Not_found -> raise (Yojson.Basic.Util.Type_error ("Incorrect AST", x))) diff --git a/core/grammar/ast.mli b/core/grammar/ast.mli index f55055d77..b12172499 100644 --- a/core/grammar/ast.mli +++ b/core/grammar/ast.mli @@ -145,6 +145,7 @@ type ('agent, 'agent_sig, 'pattern, 'mixture, 'id, 'rule) instruction = * string LKappa.guard option * 'rule Loc.annoted) | GUARD_PARAM of (string Loc.annoted * bool) + | CONFLICT of (string Loc.annoted * string Loc.annoted * string Loc.annoted) type ('pattern, 'mixture, 'id, 'rule) command = | RUN of ('pattern, 'id) Alg_expr.bool Loc.annoted @@ -169,6 +170,7 @@ type ('agent, 'agent_sig, 'pattern, 'mixture, 'id, 'rule) compil = { tokens: string Loc.annoted list; volumes: (string * float * string) list; guard_param_values: (string Loc.annoted * bool) list; + conflicts: (string Loc.annoted * string Loc.annoted * string Loc.annoted) list; } type parsing_compil = (agent, agent_sig, mixture, mixture, string, rule) compil diff --git a/core/grammar/cst.ml b/core/grammar/cst.ml index 4f9d931c3..0501999bf 100644 --- a/core/grammar/cst.ml +++ b/core/grammar/cst.ml @@ -40,5 +40,7 @@ let append_to_ast_compil rev_instr compil = { r with Ast.guard_param_values = (params_sig, b) :: r.Ast.guard_param_values; - }) + } + | Ast.CONFLICT (agent, site1, site2) -> + { r with Ast.conflicts = (agent, site1, site2) :: r.Ast.conflicts }) compil (List.rev rev_instr) diff --git a/core/grammar/kappaParser.mly b/core/grammar/kappaParser.mly index f5a33b5e0..f6d33bed4 100644 --- a/core/grammar/kappaParser.mly +++ b/core/grammar/kappaParser.mly @@ -100,6 +100,9 @@ start_rule: | Ast.GUARD_PARAM (param_name,b) -> {r with Ast.guard_param_values = (param_name,b)::r.Ast.guard_param_values} + | Ast.CONFLICT (a,s1,s2) -> + {r with + Ast.conflicts = (a,s1,s2)::r.Ast.conflicts} } | error {raise (ExceptionDefn.Syntax_Error (add_pos "Syntax error"))} diff --git a/core/grammar/klexer4.mll b/core/grammar/klexer4.mll index 7d0ee64f4..b47c941d2 100644 --- a/core/grammar/klexer4.mll +++ b/core/grammar/klexer4.mll @@ -91,6 +91,7 @@ rule token = parse | "def" -> CONFIG | "token" -> TOKEN | "guard_param" -> GUARD_PARAM + | "conflict" -> CONFLICT | _ as s -> raise (ExceptionDefn.Syntax_Error ("Unknown directive: "^s, Loc.of_pos (Lexing.lexeme_start_p lexbuf) diff --git a/core/grammar/kparser4.mly b/core/grammar/kparser4.mly index 8d72a2b34..228805957 100644 --- a/core/grammar/kparser4.mly +++ b/core/grammar/kparser4.mly @@ -27,7 +27,7 @@ %token SHARP UNDERSCORE PIPE RAR LRAR LAR EMAX TMAX CPUTIME TIME EVENT NULL_EVENT %token COLON NEWLINE BACKSLASH SIGNATURE TOKEN INIT OBS PLOT PERT CONFIG APPLY %token DELETE INTRO SNAPSHOT STOP FLUX TRACK ASSIGN PRINTF PLOTENTRY SPECIES_OF -%token DO REPEAT ALARM RUN LET GUARD_PARAM SHARP_OP_BRA IF +%token DO REPEAT ALARM RUN LET GUARD_PARAM SHARP_OP_BRA IF CONFLICT %token INT %token FLOAT %token ID LABEL STRING @@ -828,6 +828,7 @@ an algebraic expression is expected")) } | CONFIG annoted STRING annoted value_list { add (Ast.CONFIG (($3,rhs_pos 3),$5)) } | GUARD_PARAM annoted ID annoted boolean annoted { add (Ast.GUARD_PARAM (($3,rhs_pos 3), $5)) } + | CONFLICT annoted ID annoted ID annoted ID annoted { add (Ast.CONFLICT (($3,rhs_pos 3), ($5,rhs_pos 5), ($7,rhs_pos 7))) } ; model_body: diff --git a/core/grammar/lKappa_compiler.ml b/core/grammar/lKappa_compiler.ml index 0aca67018..9715c79a9 100644 --- a/core/grammar/lKappa_compiler.ml +++ b/core/grammar/lKappa_compiler.ml @@ -2766,5 +2766,6 @@ let compil_of_ast ~warning ~debug_mode ~syntax_version ~var_overwrite ast_compil signatures = ast_compil.signatures; configurations = ast_compil.configurations; guard_param_values = ast_compil.guard_param_values; + conflicts = ast_compil.conflicts; }; }