-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInspeqtorParser.mly
executable file
·179 lines (135 loc) · 3.68 KB
/
InspeqtorParser.mly
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/***********************************************
Laboratoire Specification et Verification
Etienne ANDRE
Created : 2009/04/27
Last modified : 2009/04/28
***********************************************/
%{
(****************************************************************)
(** Modules *)
(****************************************************************)
open Global
open AbstractStructure
(****************************************************************)
(** Functions *)
(****************************************************************)
(* Convert a float to a Num.num *)
let num_of_float f =
(* Split the float in integer and fractional part *)
let (fractional, integer) = modf f in
let integer = int_of_float integer in
(* Case of an integer *)
if fractional = 0.0 then Num.num_of_int integer
else(
let fractional = string_of_float fractional in
(* Remove the "0." in front of the fractional part *)
let fractional = String.sub fractional 2 (String.length fractional -2) in
(* Find the denominator *)
let denominator = int_of_string ("1" ^ (String.make (String.length fractional) '0')) in
let fractional = int_of_string fractional in
(* Create the fraction *)
Num.div_num (Num.num_of_int (integer * denominator + fractional)) (Num.num_of_int (denominator))
)
%}
%token <int> INT
%token <float> FLOAT
%token <string> NAME
%token OP_EQ
%token OP_MULT OP_DIV OP_PLUS OP_MINUS
%token LPAREN RPAREN
%token AMPERSAND ARROW COLON COMMA SEMICOLON
%token CT_COSTS CT_STRUCTURE
%token EOF
%start program /* the entry point */
%type <AbstractStructure.abstract_program> program
%%
/**********************************************/
program:
structure costs EOF
{
make_abstract_program ($1, $2)
}
;
/***********************************************
STRUCTURE
***********************************************/
/**********************************************/
structure:
CT_STRUCTURE state_list {$2}
;
/**********************************************/
state_list:
state state_list { $1 :: $2 }
| { [] }
;
/**********************************************/
state:
NAME COLON transitions {
($1, $3)
}
;
/**********************************************/
transitions:
| transition transitions { $1 :: $2 }
| { [] }
;
/**********************************************/
transition:
ARROW LPAREN cost RPAREN NAME SEMICOLON { ($3, $5) }
;
/**********************************************/
cost:
| arithm_exp { TmpConstCost $1 }
| NAME { TmpParametricCost $1 }
;
/**********************************************/
arithm_exp:
add_exp {$1}
;
/**********************************************/
add_exp:
| add_exp OP_PLUS mult_exp {Num.add_num $1 $3}
| add_exp OP_MINUS mult_exp {Num.sub_num $1 $3}
| mult_exp {$1}
;
/**********************************************/
mult_exp:
| mult_exp OP_MULT number {Num.mult_num $1 $3}
| mult_exp OP_DIV number {Num.div_num $1 $3}
| number {$1}
;
/**********************************************/
number:
| pos_number {$1}
| OP_MINUS pos_number {Num.minus_num $2}
;
/**********************************************/
pos_number:
| INT { Num.num_of_int $1 }
| FLOAT { (num_of_float $1)}
;
/***********************************************
COSTS
***********************************************/
costs:
CT_COSTS cost_list { $2 }
;
/**********************************************/
cost_list:
| and_opt cost_def cost_list2 {$2 :: $3}
| { [] }
;
/**********************************************/
cost_list2:
| AMPERSAND cost_def cost_list2 {$2 :: $3}
| { [] }
;
/**********************************************/
and_opt:
| AMPERSAND {}
| {}
;
/**********************************************/
cost_def:
NAME OP_EQ arithm_exp { ($1, $3) }
;