Skip to content

Commit 5e3c789

Browse files
author
Ioana
committed
new files
1 parent e106f06 commit 5e3c789

File tree

12 files changed

+304
-0
lines changed

12 files changed

+304
-0
lines changed

ast.ml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
type ('a) link =
2+
| LNK_VALUE of int
3+
| FREE
4+
| LNK_ANY
5+
| LNK_SOME
6+
| LNK_TYPE of 'a (* port *)
7+
* 'a (*agent_type*)
8+
9+
type internal = string list
10+
11+
type port = {port_nme:string;
12+
port_int:internal;
13+
port_lnk:string link list;}
14+
15+
type agent = (string * port list)
16+
17+
type mixture = agent list
18+
19+
type rule = {
20+
lhs: mixture ;
21+
bidirectional:bool ;
22+
rhs: mixture ;
23+
}
24+
type t = INIT of mixture
25+
| OBS of string*mixture
26+
| RULE of string*rule
27+
28+
let print_link = function
29+
| LNK_VALUE i -> Format.printf "!%d" i
30+
| FREE -> ()
31+
| LNK_ANY -> Format.printf "!_"
32+
| LNK_SOME -> Format.printf "!_"
33+
| LNK_TYPE (i,a) -> Format.printf "!%s.%s" i a
34+
35+
let print_port p =
36+
Format.printf "%s~[" p.port_nme;
37+
List.iter (fun intern -> Format.printf "%s " intern;) p.port_int;
38+
Format.printf "]";
39+
List.iter (fun p -> print_link p) p.port_lnk
40+
41+
let print_agent (name,plist) =
42+
Format.printf "%s(" name;
43+
List.iter (fun p -> print_port p) plist;
44+
Format.printf ") "
45+
46+
let print_rule r =
47+
List.iter (fun a -> print_agent a) r.lhs;
48+
if (r.bidirectional) then Format.printf " <-> "
49+
else Format.printf " -> ";
50+
List.iter (fun a -> print_agent a) r.rhs
51+
52+
let print = function
53+
| INIT mix -> Format.printf "\n init "; List.iter (fun a -> print_agent a) mix
54+
| OBS (name,mix) -> Format.printf "\n obs '%s' " name;
55+
List.iter (fun a -> print_agent a) mix
56+
| RULE (name,r) -> Format.printf "\n rule '%s' " name; print_rule r;

ast.mli

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
type ('a) link =
2+
| LNK_VALUE of int
3+
| FREE
4+
| LNK_ANY
5+
| LNK_SOME
6+
| LNK_TYPE of 'a (* port *)
7+
* 'a (*agent_type*)
8+
9+
type internal = string list
10+
11+
type port = {port_nme:string;
12+
port_int:internal;
13+
port_lnk:string link list;}
14+
15+
type agent = (string * port list)
16+
17+
type mixture = agent list
18+
19+
type rule = {
20+
lhs: mixture ;
21+
bidirectional:bool ;
22+
rhs: mixture ;
23+
}
24+
type t = INIT of mixture
25+
| OBS of string*mixture
26+
| RULE of string*rule
27+
val print : t -> unit

concret.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
let decorate s = [s]
3+
4+
let linears s =
5+
LinearPoset.linearisations(s)
6+
7+
let refine (t:Trace.t) (r: (Event.t*Transition.t) list) s id = [Trace.empty]
8+
9+
let concretise (s:LinearPoset.t) id concretisations1 =
10+
List.fold_left
11+
(fun concretisations2
12+
(t,r) -> refine t r s id) [] concretisations1
13+
14+
let concret (s:Poset.t) = concretise (linears s) 0 []

concret.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
val concret : Poset.t -> Trace.t list

grammar/lexerRule.mll

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
open ParserRule(* The type token is defined in parser.mli *)
3+
open Lexing
4+
exception Eof
5+
6+
let reach_eof lexbuf =
7+
lexbuf.lex_eof_reached <- true
8+
}
9+
10+
let eol = '\r'? '\n'
11+
let blank = [' ' '\t']
12+
let integer = '-'? (['0'-'9']+)
13+
let real =
14+
'-'?
15+
((((['0'-'9']+ ('.' ['0'-'9']*)?) | ('.' ['0'-'9']+))
16+
['e' 'E'] ['+' '-']? ['0'-'9']+)
17+
| ((['0'-'9']+ '.' ['0'-'9']* ) | (['0'-'9']* '.' ['0'-'9']+)))
18+
let id = (['a'-'z' 'A'-'Z'] ['a'-'z' 'A'-'Z' '0'-'9' '_' '-' '+']* )
19+
let internal_state = '~' (['0'-'9' 'a'-'z' 'A'-'Z' '_' '-' '+']+)
20+
21+
22+
rule token = parse
23+
| '\\' blank* eol {Lexing.new_line lexbuf ; token lexbuf}
24+
| "<->" {KAPPA_LRAR}
25+
| "->" {KAPPA_RAR}
26+
| "<-" {LAR}
27+
| eol {Lexing.new_line lexbuf ; NEWLINE}
28+
| integer as n {try INT (int_of_string n)
29+
with Failure _ -> raise (ExceptionDefn.Syntax_Error
30+
(n^" is a incorrect integer"))}
31+
| real as f {FLOAT (float_of_string f)}
32+
| '\'' ([^'\n''\'']+ as x) '\''{LABEL(x)}
33+
| id as str {ID str}
34+
| '@' {AT}
35+
| ',' {COMMA}
36+
| '(' {OP_PAR}
37+
| ')' {CL_PAR}
38+
| '.' {DOT}
39+
| '|' {PIPE}
40+
| '%' (id as lab) ':' {
41+
match lab with
42+
| "init" -> INIT
43+
| "obs" -> OBS
44+
| _ as s ->
45+
raise (ExceptionDefn.Syntax_Error("invalid use of %"))}
46+
| '!' {KAPPA_LNK}
47+
| internal_state as s {let i = String.index s '~' in
48+
let r = String.sub s (i+1) (String.length s-i-1) in
49+
KAPPA_MRK r
50+
}
51+
| '?' {KAPPA_WLD}
52+
| '_' {KAPPA_SEMI}
53+
| blank {token lexbuf}
54+
| eof {raise Eof}
55+
| _ {raise (ExceptionDefn.Syntax_Error("invalid use of character "))}

grammar/parserRule.mly

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
%token EOF NEWLINE SEMICOLON COMMA DOT OP_PAR CL_PAR OP_CUR CL_CUR AT TYPE LAR
2+
%token GREATER SMALLER TRUE FALSE DIFF KAPPA_RAR KAPPA_LRAR KAPPA_LNK PIPE
3+
%token INIT OBS KAPPA_WLD KAPPA_SEMI
4+
%token <int> INT
5+
%token <string> ID
6+
%token <string> KAPPA_MRK LABEL
7+
%token <float> FLOAT
8+
%token <string> STRING
9+
%start newline
10+
%type <Ast.t> newline
11+
%%
12+
13+
newline:
14+
| start_rule NEWLINE {$1}
15+
;
16+
17+
start_rule:
18+
| rule_expression {$1}
19+
| instruction {$1}
20+
| error
21+
{raise (ExceptionDefn.Syntax_Error("start_rule"))}
22+
;
23+
24+
rule_expression:
25+
| rule_label lhs_rhs arrow lhs_rhs
26+
{ Ast.RULE ($1,({Ast.lhs=$2; Ast.bidirectional=$3;
27+
Ast.rhs=$4;}))}
28+
;
29+
30+
arrow:
31+
| KAPPA_RAR {false}
32+
| KAPPA_LRAR {true}
33+
;
34+
35+
rule_label:
36+
| LABEL {$1}
37+
;
38+
39+
instruction:
40+
| INIT init_declaration {$2}
41+
| INIT error
42+
{ raise (ExceptionDefn.Syntax_Error("Malformed initial condition"))}
43+
| OBS variable_declaration {$2}
44+
;
45+
46+
variable_declaration:
47+
| LABEL non_empty_mixture {Ast.OBS ($1,$2)}
48+
;
49+
50+
init_declaration:
51+
| non_empty_mixture {(Ast.INIT $1)}
52+
;
53+
54+
lhs_rhs:
55+
mixture {$1};
56+
57+
mixture:
58+
/*empty*/ {[]}
59+
| non_empty_mixture {$1}
60+
;
61+
62+
non_empty_mixture:
63+
| OP_PAR non_empty_mixture CL_PAR {$2}
64+
| agent_expression COMMA non_empty_mixture {$1 :: $3}
65+
| agent_expression {[$1]}
66+
;
67+
68+
agent_expression:
69+
| ID OP_PAR interface_expression CL_PAR {($1,$3)}
70+
| ID error
71+
{ raise (ExceptionDefn.Syntax_Error("Malformed agent '"^$1^"'"))}
72+
;
73+
74+
interface_expression:
75+
/*empty*/ {[]}
76+
| ne_interface_expression {$1}
77+
;
78+
79+
ne_interface_expression:
80+
| port_expression COMMA ne_interface_expression {$1::$3}
81+
| port_expression {[$1]}
82+
;
83+
84+
port_expression:
85+
| ID internal_state link_state
86+
{{Ast.port_nme=$1; Ast.port_int=$2; Ast.port_lnk=$3}}
87+
;
88+
89+
internal_state:
90+
/*empty*/ {[]}
91+
| KAPPA_MRK internal_state {$1::$2}
92+
| error
93+
{raise (ExceptionDefn.Syntax_Error ("Invalid internal state"))}
94+
;
95+
96+
link_state:
97+
/*empty*/ {[]}
98+
| KAPPA_LNK INT link_state {(Ast.LNK_VALUE $2)::$3}
99+
| KAPPA_LNK KAPPA_SEMI link_state {(Ast.LNK_SOME)::$3}
100+
| KAPPA_LNK ID DOT ID link_state {(Ast.LNK_TYPE($2,$4))::$5}
101+
| KAPPA_WLD link_state {(Ast.LNK_ANY)::$2}
102+
| KAPPA_LNK error
103+
{raise (ExceptionDefn.Syntax_Error("Invalid link state"))}
104+
;

rule.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
type kt = INIT of Site_graph.t
3+
| OBS of string*Site_graph.t
4+
| RULE of string*Site_graph.t*Site_graph.t
5+
6+
type t = {
7+
left : Site_graph.t;
8+
right : Site_graph.t;
9+
middle : Site_graph.t;
10+
id : int;
11+
}
12+
13+
let print rule = Format.printf "\n"

rule.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
type t = {
3+
left : Site_graph.t;
4+
right : Site_graph.t;
5+
middle : Site_graph.t;
6+
id : int;
7+
}
8+
val print : t -> unit

trace.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
type t = {
3+
transitions : Transition.t list;
4+
}
5+
6+
let empty = {transitions = [];}

trace.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
type t = {
3+
transitions : Transition.t list;
4+
}
5+
6+
val empty: t

0 commit comments

Comments
 (0)