Line data Source code
1 : %skeleton "lalr1.cc" /* -*- C++ -*- */
2 : %require "2.4"
3 : %defines
4 : %define parser_class_name {Lha_parser}
5 :
6 : %code requires {
7 : #include <math.h>
8 : #include <limits.h>
9 : # include <string>
10 :
11 : #include <fstream>
12 : #include <sstream>
13 : #include <set>
14 : #include "../Eval/Eval.hpp"
15 : #include "../HaslFormula.hpp"
16 :
17 : class Lha_Reader;
18 :
19 :
20 : #define BUFF_SIZE 5000
21 : }
22 :
23 : // The parsing context.
24 : %parse-param { Lha_Reader& Reader }
25 : %lex-param { Lha_Reader& Reader }
26 :
27 : %locations
28 :
29 : %debug
30 : %error-verbose
31 :
32 : // Symbols.
33 : %union
34 : {
35 : double RealVal;
36 : int IntVal;
37 : std::string *name;
38 : char expression[BUFF_SIZE];
39 : HaslFormulasTop *TOPHASL;
40 : };
41 :
42 : %code {
43 : #include "../HaslFormula.hpp"
44 : #include "Lha-Reader.hpp"
45 : #include <set>
46 : #include <vector>
47 :
48 35 : Eval LhaEvaluate;
49 :
50 :
51 :
52 35 : vector<string> FuncFlowVector;
53 :
54 35 : vector<string> FuncUpdateVector;
55 35 : vector<string> FuncUpdateVectorIndex;
56 :
57 35 : set <string> PetriTransitions;
58 35 : set <string> SubSet;
59 :
60 :
61 :
62 35 : vector < string > CoeffsVector;
63 35 : vector < vector <string> > CoeffsMatrix;
64 35 : vector <string> CST;
65 35 : vector <string> comp;
66 :
67 :
68 :
69 :
70 :
71 :
72 : }
73 :
74 : %token END 0 "end of file"
75 :
76 : %token <name> str
77 : %token <RealVal> rval
78 : %token <IntVal> ival
79 :
80 : %token <name> SEMICOLON
81 : %token <name> COLON
82 : %token <name> COMMA
83 : %token <name> LB
84 : %token <name> RB
85 : %token <name> LSB
86 : %token <name> RSB
87 :
88 : %token <name> SHARP
89 : %token <name> ALL
90 : %token <name> BackSlash
91 :
92 : %token <name> EQ
93 : %token <name> GEQ
94 : %token <name> LEQ
95 : %token <name> LL
96 : %token <name> GG
97 :
98 : %token <name> AND
99 : %token <name> OR
100 : %token <name> NOT
101 :
102 : %token <name> TRUE
103 : %token <name> FALSE
104 :
105 : %token <name> DOUBLE
106 : %token <name> INT
107 :
108 : %token <name> DIV
109 : %token <name> MUL
110 : %token <name> PLUS
111 : %token <name> MINUS
112 : %token <name> POWER
113 : %token <name> FLOOR
114 :
115 : %token <name> MIN
116 : %token <name> MAX
117 : %token <name> MOD
118 :
119 : %token <name> LhaMIN
120 : %token <name> LhaMAX
121 : %token <name> AVG
122 : %token <name> VAR
123 : %token <name> PROB
124 : %token <name> SPRT
125 : %token <name> LAST
126 : %token <name> INTEGRAL
127 : %token <name> MEAN
128 : %token <name> DISC
129 :
130 : %token <name> NOTDET
131 :
132 : %token <name> LhaName
133 :
134 : %token <name> Const
135 : %token <name> Hybrid
136 :
137 : %token <name> NbLoc
138 : %token <name> NbVar
139 :
140 : %token <name> VList
141 : %token <name> LList
142 :
143 : %token <name> Iloc
144 : %token <name> Floc
145 :
146 : %token <name> locations
147 : %token <name> edges
148 :
149 : %token <name> PDF
150 : %token <namd> CDF
151 :
152 : %token <name> EXIST_TOK
153 : %token <name> NOTALL_TOK
154 :
155 : %type<expression> IntMarkingFormula
156 : %type<expression> RealMarkingFormula
157 : %type<expression> RealVarMarkingFormula
158 : %type<expression> ColorClassList
159 : %type<expression> LogExpr
160 : %type<expression> CompExpr
161 :
162 : %type<expression> AlgExpr
163 : %type<expression> LhaFunc
164 : %type<expression> LinForm
165 : %type<expression> VarTerm
166 :
167 : %type<TOPHASL> TopHaslExp
168 : %type<RealVal> rorival
169 :
170 0 : %printer { debug_stream () << *$$; } str
171 0 : %destructor { delete $$; } str
172 :
173 0 : %printer { debug_stream () << $$; } <IntVal>
174 0 : %printer { debug_stream () << $$; } <RealVal>
175 :
176 : %%
177 : %left OR;
178 : %left AND;
179 : %left NOT;
180 : %left LEQ GEQ LL GG EQ;
181 : %left PLUS MINUS;
182 : %left NEG;
183 : %left MUL DIV;
184 : %left POWER;
185 : %left LB RB;
186 :
187 :
188 : %start LHA;
189 :
190 : LHA:
191 0 : | NOTDET declarations InitFinal definitions {Reader.MyLha.isDeterministic=false;}
192 : | declarations InitFinal definitions
193 : | HaslExps;
194 :
195 : declarations:
196 : | Sizes Constants HybridVars Lists HaslExps
197 : | Sizes HybridVars Lists HaslExps
198 : | Sizes Constants Lists HaslExps
199 : | Sizes Lists HaslExps;
200 :
201 :
202 :
203 :
204 : IntMarkingFormula:
205 9 : ival {sprintf($$,"%i",$1);}
206 : | str {
207 0 : if(Reader.MyLha.PlaceIndex.find(*$1)!=Reader.MyLha.PlaceIndex.end())
208 0 : {std::ostringstream s; s<<" Marking.P->_PL_"<< $1->c_str()<<" ";
209 0 : sprintf($$, "%s",(s.str()).c_str());
210 : }
211 0 : else if(Reader.MyLha.LhaIntConstant.find(*$1)!=Reader.MyLha.LhaIntConstant.end())
212 0 : {std::ostringstream s; s<<Reader.MyLha.LhaIntConstant[*$1];
213 0 : sprintf($$, "%s",(s.str()).c_str());
214 : } else {
215 0 : size_t vararray = Reader.MyLha.Vars.find(*$1);
216 0 : if(vararray!= Reader.MyLha.NbVar && Reader.MyLha.Vars.type[vararray]==DISCRETE_VARIABLE){
217 0 : sprintf($$, " floor(Vars->%s)", Reader.MyLha.Vars.label[vararray].c_str() );
218 0 : } else {cout<<"'"<<*$1<<"' is not a place label or a defined constant"<<endl;YYABORT;}
219 : }
220 : }
221 : | str LSB ColorClassList RSB {
222 0 : auto pi = Reader.MyLha.PlaceIndex.find(*$1);
223 0 : if( pi !=Reader.MyLha.PlaceIndex.end())
224 0 : {std::ostringstream s;
225 0 : s<<" Marking.P->_PL_"<< $1->c_str()<< ".mult";
226 0 : if(P.is_domain_impl_set){
227 0 : size_t coldom = Reader.MyLha.MyGspn->placeStruct[pi->second].colorDom;
228 0 : s << "("<< Reader.MyLha.MyGspn->colDoms[coldom].tokname()<< "(" << $3 << "))";
229 0 : } else s << $3;
230 0 : sprintf($$, "%s",(s.str()).c_str());
231 0 : }else{cout<<"'"<<*$1<<"' is not a place label "<<endl;YYABORT;}}
232 : | str LSB IntMarkingFormula RSB {
233 0 : size_t vararray = Reader.MyLha.Vars.find(*$1);
234 0 : if(vararray!= Reader.MyLha.NbVar && Reader.MyLha.Vars.type[vararray]==INT_INDEXED_DISC_ARRAY)
235 0 : {std::ostringstream s;
236 0 : s<<" Vars.P->" << Reader.MyLha.Vars.label[vararray] << "["<< *$3 << "]";
237 0 : sprintf($$, "%s",(s.str()).c_str());
238 0 : }else{cout<<"'"<<*$1<<"' is not a discrete array name "<<endl;YYABORT;}}
239 0 : | LB IntMarkingFormula RB{snprintf($$,BUFF_SIZE,"( %s )", $2); }
240 0 : | MINUS IntMarkingFormula %prec NEG {snprintf($$,BUFF_SIZE,"-%s",$2);}
241 0 : | IntMarkingFormula PLUS IntMarkingFormula {snprintf($$,BUFF_SIZE,"%s + %s", $1, $3); }
242 0 : | IntMarkingFormula MINUS IntMarkingFormula {snprintf($$,BUFF_SIZE,"%s - %s", $1, $3); }
243 0 : | IntMarkingFormula MUL IntMarkingFormula {snprintf($$,BUFF_SIZE,"%s * %s", $1, $3); }
244 0 : | IntMarkingFormula POWER IntMarkingFormula {snprintf($$,BUFF_SIZE,"pow(%s , %s)", $1, $3); }
245 0 : | FLOOR LB IntMarkingFormula RB {snprintf($$,BUFF_SIZE,"floor( %s )", $3); }
246 0 : | FLOOR LB IntMarkingFormula DIV IntMarkingFormula RB {snprintf($$,BUFF_SIZE,"floor( %s /double(%s))", $3,$5); }
247 0 : | MIN LB IntMarkingFormula COMMA IntMarkingFormula RB {snprintf($$,BUFF_SIZE,"min(%s , %s)", $3, $5); }
248 0 : | MAX LB IntMarkingFormula COMMA IntMarkingFormula RB {snprintf($$,BUFF_SIZE,"max(%s , %s)", $3, $5); };
249 0 : | MOD LB IntMarkingFormula COMMA IntMarkingFormula RB {snprintf($$,BUFF_SIZE,"((int)%s %% (int)%s)", $3, $5); };
250 :
251 :
252 13 : RealMarkingFormula: rval {sprintf($$, "%f",$1);}
253 127 : | ival {sprintf($$,"%d",$1);}
254 : | str SHARP {
255 0 : if(Reader.MyLha.PlaceIndex.find(*$1)!=Reader.MyLha.PlaceIndex.end())
256 0 : {std::ostringstream s; s<<" Marking.P->_PL_"<<$1->c_str();
257 0 : if(Reader.MyLha.MyGspn->placeStruct[Reader.MyLha.PlaceIndex[*$1]].colorDom !=0 )s <<".value()";
258 0 : sprintf($$, "%s ",(s.str()).c_str());
259 : }
260 0 : else {cout<<"'"<<*$1<<"' is not a place label"<<endl;YYABORT;}}
261 : | str {
262 470 : if(Reader.MyLha.PlaceIndex.find(*$1)!=Reader.MyLha.PlaceIndex.end())
263 422 : {std::ostringstream s; s<<" Marking.P->_PL_"<<$1->c_str();
264 211 : if(Reader.MyLha.MyGspn->placeStruct[Reader.MyLha.PlaceIndex[*$1]].colorDom !=0 )s <<".card()";
265 211 : snprintf($$,BUFF_SIZE, "%s ",(s.str()).c_str());
266 : }
267 259 : else if(Reader.MyLha.LhaRealConstant.find(*$1)!=Reader.MyLha.LhaRealConstant.end())
268 518 : {std::ostringstream s; s<<Reader.MyLha.LhaRealConstant[*$1];
269 259 : snprintf($$, BUFF_SIZE,"%s",(s.str()).c_str());
270 : }
271 :
272 0 : else{cout<<"'"<<*$1<<"' is not a place label or a defined constant"<<endl;YYABORT;}}
273 : | str LSB ColorClassList RSB {
274 0 : auto pi = Reader.MyLha.PlaceIndex.find(*$1);
275 0 : if( pi !=Reader.MyLha.PlaceIndex.end())
276 0 : {std::ostringstream s;
277 0 : s<<" Marking.P->_PL_"<< $1->c_str()<< ".mult";
278 0 : if(P.is_domain_impl_set){
279 0 : size_t coldom = Reader.MyLha.MyGspn->placeStruct[pi->second].colorDom;
280 0 : s << "("<< Reader.MyLha.MyGspn->colDoms[coldom].tokname()<< "(" << $3 << "))";
281 0 : } else s << $3;
282 0 : snprintf($$,BUFF_SIZE, "%s",(s.str()).c_str());
283 0 : }else{cout<<"'"<<*$1<<"' is not a place label "<<endl;YYABORT;}}
284 10 : | LB RealMarkingFormula RB {snprintf($$,BUFF_SIZE,"( %s )", $2); }
285 0 : | MINUS RealMarkingFormula %prec NEG {snprintf($$,BUFF_SIZE,"-%s",$2);}
286 0 : | RealMarkingFormula DIV RealMarkingFormula {snprintf($$,BUFF_SIZE,"%s /double(%s)", $1, $3); }
287 34 : | RealMarkingFormula PLUS RealMarkingFormula {snprintf($$,BUFF_SIZE,"%s + %s", $1, $3); }
288 0 : | RealMarkingFormula MINUS RealMarkingFormula {snprintf($$,BUFF_SIZE,"%s - %s", $1, $3); }
289 101 : | RealMarkingFormula MUL RealMarkingFormula {snprintf($$,BUFF_SIZE,"%s * %s", $1, $3); }
290 0 : | RealMarkingFormula POWER RealMarkingFormula {snprintf($$,BUFF_SIZE,"pow(%s , %s)", $1, $3); }
291 0 : | FLOOR LB RealMarkingFormula RB {snprintf($$,BUFF_SIZE,"floor( %s )", $3); }
292 0 : | MIN LB RealMarkingFormula COMMA RealMarkingFormula RB {snprintf($$,BUFF_SIZE,"min(%s , %s)", $3, $5); }
293 0 : | MAX LB RealMarkingFormula COMMA RealMarkingFormula RB {snprintf($$,BUFF_SIZE,"max(%s , %s)", $3, $5); };
294 :
295 0 : RealVarMarkingFormula: rval {sprintf($$, "%f",$1);}
296 121 : | ival {sprintf($$,"%d",$1);}
297 : | str SHARP {
298 0 : if(Reader.MyLha.PlaceIndex.find(*$1)!=Reader.MyLha.PlaceIndex.end())
299 0 : {std::ostringstream s; s<<" Marking.P->_PL_"<<$1->c_str();
300 0 : if(Reader.MyLha.MyGspn->placeStruct[Reader.MyLha.PlaceIndex[*$1]].colorDom !=0 )s <<".value()";
301 0 : sprintf($$, "%s ",(s.str()).c_str());
302 : }
303 0 : else {cout<<"'"<<*$1<<"' is not a place label"<<endl;YYABORT;}}
304 : | str {
305 254 : if(Reader.MyLha.PlaceIndex.find(*$1)!=Reader.MyLha.PlaceIndex.end())
306 0 : {std::ostringstream s; s<<" Marking.P->_PL_"<<$1->c_str();
307 0 : if(Reader.MyLha.MyGspn->placeStruct[Reader.MyLha.PlaceIndex[*$1]].colorDom !=0 )s <<".card()";
308 0 : snprintf($$,BUFF_SIZE, "%s ",(s.str()).c_str());
309 : }
310 254 : else{ if(Reader.MyLha.LhaRealConstant.find(*$1)!=Reader.MyLha.LhaRealConstant.end())
311 166 : {std::ostringstream s; s<<Reader.MyLha.LhaRealConstant[*$1];
312 83 : snprintf($$,BUFF_SIZE, "%s",(s.str()).c_str());
313 : }
314 171 : else {if(Reader.MyLha.Vars.find(*$1)!=Reader.MyLha.Vars.label.size())
315 : {
316 342 : std::ostringstream s; s<<"Vars->"<< $1->c_str();
317 171 : snprintf($$,BUFF_SIZE, "%s",(s.str()).c_str());
318 : }
319 0 : else {cout<<"'"<<*$1<<"' is not a place label, a lha variable or a defined constant"<<endl;YYABORT;}
320 : }
321 : }
322 : }
323 : | str LSB IntMarkingFormula RSB {
324 0 : size_t varin = Reader.MyLha.Vars.find(*$1);
325 0 : if(varin != Reader.MyLha.Vars.label.size()){
326 0 : snprintf($$,BUFF_SIZE, "Vars->%s[%s]", $1->c_str(),$3);
327 : }
328 0 : else {cout<<"'"<<*$1<<"' is not an lha array variable"<<endl;YYABORT;}
329 : }
330 : | str LSB ColorClassList RSB {
331 0 : auto pi = Reader.MyLha.PlaceIndex.find(*$1);
332 0 : if( pi !=Reader.MyLha.PlaceIndex.end())
333 0 : {std::ostringstream s;
334 0 : s<<" Marking.P->_PL_"<< $1->c_str()<< ".mult";
335 0 : if(P.is_domain_impl_set){
336 0 : size_t coldom = Reader.MyLha.MyGspn->placeStruct[pi->second].colorDom;
337 0 : s << "("<< Reader.MyLha.MyGspn->colDoms[coldom].tokname()<< "(" << $3 << "))";
338 0 : } else s << $3;
339 0 : snprintf($$,BUFF_SIZE, "%s",(s.str()).c_str());
340 0 : }else{cout<<"'"<<*$1<<"' is not a place label "<<endl;YYABORT;}}
341 0 : | LB RealVarMarkingFormula RB {snprintf($$,BUFF_SIZE,"( %s )", $2); }
342 0 : | MINUS RealVarMarkingFormula %prec NEG {snprintf($$,BUFF_SIZE,"-%s",$2);}
343 1 : | RealVarMarkingFormula DIV RealVarMarkingFormula {snprintf($$,BUFF_SIZE,"%s /double(%s)", $1, $3); }
344 170 : | RealVarMarkingFormula PLUS RealVarMarkingFormula {snprintf($$,BUFF_SIZE,"%s + %s", $1, $3); }
345 0 : | RealVarMarkingFormula MINUS RealVarMarkingFormula {snprintf($$,BUFF_SIZE,"%s - %s", $1, $3); }
346 0 : | RealVarMarkingFormula MUL RealVarMarkingFormula {snprintf($$,BUFF_SIZE,"%s * %s", $1, $3); }
347 0 : | RealVarMarkingFormula POWER RealVarMarkingFormula {snprintf($$,BUFF_SIZE,"pow(%s , %s)", $1, $3); }
348 0 : | FLOOR LB RealVarMarkingFormula RB {snprintf($$,BUFF_SIZE,"floor( %s )", $3); }
349 0 : | MIN LB RealVarMarkingFormula COMMA RealVarMarkingFormula RB {snprintf($$,BUFF_SIZE,"min(%s , %s)", $3, $5); }
350 0 : | MAX LB RealVarMarkingFormula COMMA RealVarMarkingFormula RB {snprintf($$,BUFF_SIZE,"max(%s , %s)", $3, $5); };
351 :
352 0 : ColorClassList: str COMMA {if(P.is_domain_impl_set){
353 0 : snprintf($$,BUFF_SIZE,"%s", $1->c_str()); }
354 0 : else snprintf($$,BUFF_SIZE,"[%s]", $1->c_str()); }
355 0 : | str COMMA ColorClassList {if(P.is_domain_impl_set){
356 0 : snprintf($$,BUFF_SIZE,"%s,%s", $1->c_str(), $3); }
357 : else
358 0 : snprintf($$,BUFF_SIZE,"[%s]%s", $1->c_str(), $3); };
359 :
360 : Sizes: NbLocations NbVariables
361 : |NbVariables NbLocations
362 0 : |NbLocations {Reader.MyLha.NbVar=0;}
363 0 : |NbVariables {Reader.MyLha.NbLoc=0;}
364 16 : | {Reader.MyLha.NbVar=0;Reader.MyLha.NbLoc=0;}
365 :
366 : Constants: Constant
367 : |Constant Constants;
368 :
369 : HybridVars: HybridVar
370 : |HybridVar HybridVars;
371 :
372 : Constant: Const INT str EQ IntMarkingFormula SEMICOLON
373 9 : {if(Reader.MyLha.LhaRealConstant.find(*$3)!=Reader.MyLha.LhaRealConstant.end())
374 0 : {cout<<"Constant "<<*$3<<" already defined."<<endl; YYABORT;}
375 18 : else {string st=$5;
376 9 : if (Reader.P.constants.count(*$3)>0)st = Reader.P.constants[*$3];
377 :
378 9 : LhaEvaluate.parse(st);
379 9 : Reader.MyLha.LhaIntConstant[*$3]=LhaEvaluate.IntResult;Reader.MyLha.LhaRealConstant[*$3]=LhaEvaluate.RealResult;}
380 : }
381 : | Const DOUBLE str EQ RealMarkingFormula SEMICOLON
382 41 : {if(Reader.MyLha.LhaRealConstant.find(*$3)!=Reader.MyLha.LhaRealConstant.end())
383 0 : {cout<<"Constant "<<*$3<<" already defined."<<endl; YYABORT;}
384 82 : else {string st=$5;
385 41 : if (Reader.P.constants.count(*$3)>0)st = Reader.P.constants[*$3];
386 41 : LhaEvaluate.parse(st);
387 41 : Reader.MyLha.LhaRealConstant[*$3]=LhaEvaluate.RealResult;}
388 : };
389 :
390 : HybridVar: Hybrid INT str SEMICOLON
391 0 : {if(Reader.MyLha.LhaRealHybrid.find(*$3)!=Reader.MyLha.LhaRealHybrid.end())
392 0 : {cout<<"Hybrid Variable "<<*$3<<" defined twice in the LHA."<<endl; YYABORT;}
393 : else {
394 0 : Reader.MyLha.LhaIntHybrid[*$3]=1;
395 0 : Reader.MyLha.LhaRealHybrid[*$3]=1.0;
396 : }
397 : }
398 : | Hybrid DOUBLE str SEMICOLON
399 0 : {if(Reader.MyLha.LhaRealHybrid.find(*$3)!=Reader.MyLha.LhaRealHybrid.end())
400 0 : {cout<<"Hybrid Variable "<<*$3<<" defined twice in the LHA."<<endl; YYABORT;}
401 : else {
402 0 : Reader.MyLha.LhaRealHybrid[*$3]=1.0;
403 : }
404 : }
405 : ;
406 :
407 :
408 11 : NbVariables: NbVar EQ ival SEMICOLON {Reader.MyLha.NbVar=$3;};
409 :
410 11 : NbLocations: NbLoc EQ ival SEMICOLON {Reader.MyLha.NbLoc=$3;};
411 :
412 : Lists: VariablesList LocationsList
413 : | LocationsList VariablesList;
414 :
415 : VariablesList: VList EQ '{' VLabels '}' SEMICOLON {
416 27 : if(Reader.MyLha.NbVar==0)Reader.MyLha.NbVar = Reader.MyLha.Vars.label.size();
417 27 : if(Reader.MyLha.Vars.label.size()!=Reader.MyLha.NbVar){
418 0 : std::cout<<"Variable label missing or redeclared, please check your variables list"<<std::endl;
419 0 : YYABORT;
420 : }
421 :
422 27 : FuncFlowVector.resize(Reader.MyLha.NbVar);
423 27 : FuncUpdateVector.resize(Reader.MyLha.NbVar);
424 27 : FuncUpdateVectorIndex.resize(Reader.MyLha.NbVar);
425 27 : CoeffsVector.resize(Reader.MyLha.NbVar);
426 :
427 513 : for(const auto &it : Reader.MyLha.TransitionIndex)
428 486 : PetriTransitions.insert(it.first);
429 : };
430 :
431 : VLabels : str {
432 27 : Reader.MyLha.Vars.label.push_back(*$1);
433 27 : Reader.MyLha.Vars.initialValue.push_back(0.0);
434 27 : Reader.MyLha.Vars.type.push_back(CONTINIOUS_VARIABLE);
435 27 : Reader.MyLha.Vars.colorDomain.push_back(UNCOLORED_DOMAIN);
436 27 : Reader.MyLha.Vars.isTraced.push_back(true);
437 : //Reader.MyLha.VarIndex[*$1]=Reader.MyLha.VarLabel.size()-1;
438 : }
439 : | DISC str {
440 :
441 0 : Reader.MyLha.Vars.label.push_back(*$2);
442 0 : Reader.MyLha.Vars.initialValue.push_back(0.0);
443 0 : Reader.MyLha.Vars.type.push_back(DISCRETE_VARIABLE);
444 0 : Reader.MyLha.Vars.colorDomain.push_back(UNCOLORED_DOMAIN);
445 0 : Reader.MyLha.Vars.isTraced.push_back(true);
446 : //Reader.MyLha.VarIndex[*$1]=Reader.MyLha.VarLabel.size()-1;
447 :
448 : }
449 : | DISC str LSB ival RSB {
450 :
451 0 : Reader.MyLha.Vars.label.push_back(*$2);
452 0 : Reader.MyLha.Vars.initialValue.push_back(0.0);
453 0 : Reader.MyLha.Vars.type.push_back(INT_INDEXED_DISC_ARRAY);
454 0 : Reader.MyLha.Vars.colorDomain.push_back($4);
455 0 : Reader.MyLha.Vars.isTraced.push_back(true);
456 : //Reader.MyLha.VarIndex[*$1]=Reader.MyLha.VarLabel.size()-1;
457 :
458 : }
459 :
460 : |VLabels COMMA str {
461 184 : Reader.MyLha.Vars.label.push_back(*$3);
462 184 : Reader.MyLha.Vars.initialValue.push_back(0.0);
463 184 : Reader.MyLha.Vars.type.push_back(CONTINIOUS_VARIABLE);
464 184 : Reader.MyLha.Vars.colorDomain.push_back(UNCOLORED_DOMAIN);
465 184 : Reader.MyLha.Vars.isTraced.push_back(true);
466 : //Reader.MyLha.VarIndex[*$3]=Reader.MyLha.VarLabel.size()-1;
467 : };
468 : |VLabels COMMA DISC str {
469 16 : Reader.MyLha.Vars.label.push_back(*$4);
470 16 : Reader.MyLha.Vars.initialValue.push_back(0.0);
471 16 : Reader.MyLha.Vars.type.push_back(DISCRETE_VARIABLE);
472 16 : Reader.MyLha.Vars.colorDomain.push_back(UNCOLORED_DOMAIN);
473 16 : Reader.MyLha.Vars.isTraced.push_back(true);
474 : //Reader.MyLha.VarIndex[*$3]=Reader.MyLha.VarLabel.size()-1;
475 : }
476 : |VLabels COMMA DISC str LSB ival RSB {
477 0 : Reader.MyLha.Vars.label.push_back(*$4);
478 0 : Reader.MyLha.Vars.initialValue.push_back(0.0);
479 0 : Reader.MyLha.Vars.type.push_back(INT_INDEXED_DISC_ARRAY);
480 0 : Reader.MyLha.Vars.colorDomain.push_back($6);
481 0 : Reader.MyLha.Vars.isTraced.push_back(true);
482 :
483 : };
484 :
485 : LocationsList: LList EQ '{' LLabels '}' SEMICOLON {
486 27 : if(Reader.MyLha.NbLoc ==0)Reader.MyLha.NbLoc = Reader.MyLha.LocIndex.size();
487 27 : if(Reader.MyLha.LocIndex.size()!=Reader.MyLha.NbLoc){
488 0 : std::cout<<"Location label missing or redeclared, please check your locations list"<<std::endl;
489 0 : YYABORT;
490 : }
491 27 : Reader.MyLha.FuncLocProperty=vector<string>(Reader.MyLha.NbLoc,"");
492 27 : Reader.MyLha.FuncFlow=vector<vector<string> >(Reader.MyLha.NbLoc,vector<string>(Reader.MyLha.NbVar,""));
493 : };
494 :
495 : LLabels : str {
496 27 : Reader.MyLha.LocLabel.push_back(*$1);
497 27 : Reader.MyLha.LocIndex[*$1]=Reader.MyLha.LocLabel.size()-1;
498 : }
499 58 : |LLabels COMMA str {Reader.MyLha.LocLabel.push_back(*$3);
500 58 : Reader.MyLha.LocIndex[*$3]=Reader.MyLha.LocLabel.size()-1;
501 : };
502 :
503 :
504 : InitFinal: init final
505 : |final init;
506 :
507 : init: Iloc EQ '{' iLLabels '}' SEMICOLON;
508 :
509 : iLLabels : str {
510 :
511 27 : if(Reader.MyLha.LocIndex.find(*$1)!=Reader.MyLha.LocIndex.end())
512 27 : Reader.MyLha.InitLoc.insert(Reader.MyLha.LocIndex[*$1]);
513 0 : else cout<<"Unknown location:" << *$1 <<endl;
514 :
515 :
516 : }
517 0 : |iLLabels COMMA str {if(Reader.MyLha.LocIndex.find(*$3)!=Reader.MyLha.LocIndex.end())
518 0 : Reader.MyLha.InitLoc.insert(Reader.MyLha.LocIndex[*$3]);
519 0 : else cout<<"Unknown location:"<< *$3 << endl;
520 : };
521 :
522 : final: Floc EQ '{' fLLabels '}' SEMICOLON;
523 :
524 : fLLabels : str {
525 :
526 27 : if(Reader.MyLha.LocIndex.find(*$1)!=Reader.MyLha.LocIndex.end())
527 27 : Reader.MyLha.FinalLoc.insert(Reader.MyLha.LocIndex[*$1]);
528 0 : else cout<<"Unknown location: "<< *$1 <<endl;
529 :
530 :
531 : }
532 8 : |fLLabels COMMA str {if(Reader.MyLha.LocIndex.find(*$3)!=Reader.MyLha.LocIndex.end())
533 8 : Reader.MyLha.FinalLoc.insert(Reader.MyLha.LocIndex[*$3]);
534 0 : else {cout<<"Unknown location: "<< *$3 <<endl;YYABORT;}
535 : };
536 :
537 :
538 :
539 :
540 :
541 : definitions: LocationsDef EdgesDef
542 : |EdgesDef LocationsDef;
543 :
544 :
545 :
546 : LocationsDef: locations EQ '{' LOCATIONS '}' SEMICOLON {
547 112 : for(size_t l=0; l<Reader.MyLha.FuncLocProperty.size();l++)
548 85 : if(Reader.MyLha.FuncLocProperty[l]=="")
549 0 : {cout<<"Some locations are not definded. Please define all the declared locations."<<endl;
550 0 : YYABORT;}
551 :
552 27 : Reader.MyLha.Out_S_Edges.resize(Reader.MyLha.NbLoc);
553 27 : Reader.MyLha.Out_A_Edges.resize(Reader.MyLha.NbLoc);
554 : };
555 :
556 : LOCATIONS: LOCATION
557 : |LOCATIONS LOCATION;
558 :
559 : LOCATION: LB str COMMA LogExpr COMMA LB FLOWS RB RB SEMICOLON
560 : {
561 41 : auto loc = Reader.MyLha.LocIndex.find(*$2);
562 41 : if(loc !=Reader.MyLha.LocIndex.end()){
563 41 : Reader.MyLha.FuncLocProperty[loc->second]= $4;
564 41 : Reader.MyLha.FuncFlow[loc->second] = FuncFlowVector;
565 41 : FuncFlowVector=vector<string>(Reader.MyLha.NbVar,"");
566 : }
567 0 : else {cout<<"Unknown location: "<< *$2 <<endl;YYABORT;}
568 :
569 : }
570 : |LB str COMMA LogExpr RB SEMICOLON
571 :
572 :
573 : {
574 44 : auto loc = Reader.MyLha.LocIndex.find(*$2);
575 44 : if(loc != Reader.MyLha.LocIndex.end()){
576 44 : Reader.MyLha.FuncLocProperty[loc->second]= $4;
577 44 : Reader.MyLha.FuncFlow[loc->second] = FuncFlowVector;
578 : }
579 0 : else {cout<<"Unknown location: "<< *$2 <<endl;YYABORT;}
580 :
581 :
582 : };
583 :
584 : FLOWS: FLOW
585 : |FLOWS COMMA FLOW;
586 : FLOW: str COLON RealMarkingFormula {
587 143 : if(Reader.MyLha.Vars.find(*$1)!=Reader.MyLha.Vars.label.size())
588 143 : FuncFlowVector[Reader.MyLha.Vars.find(*$1)]=$3;
589 0 : else{ cout<<"'"<<*$1<<"' is not an Lha variable"<<endl;
590 0 : YYABORT;}
591 : };
592 :
593 44 : LogExpr: TRUE {snprintf($$,BUFF_SIZE,"true");}
594 0 : |FALSE {snprintf($$,BUFF_SIZE,"false");}
595 75 : |CompExpr {snprintf($$,BUFF_SIZE,"%s", $1);}
596 28 : |LogExpr AND LogExpr {snprintf($$,BUFF_SIZE,"%s && %s", $1, $3);}
597 6 : |LogExpr OR LogExpr {snprintf($$,BUFF_SIZE,"%s || %s", $1, $3);}
598 63 : |LB LogExpr RB {snprintf($$,BUFF_SIZE,"( %s )", $2);}
599 9 : |NOT LogExpr {snprintf($$,BUFF_SIZE,"! %s", $2);};
600 :
601 48 : CompExpr: RealMarkingFormula EQ RealMarkingFormula {snprintf($$,BUFF_SIZE,"%s == %s", $1, $3);}
602 0 : |RealMarkingFormula LEQ RealMarkingFormula {snprintf($$,BUFF_SIZE,"%s <= %s", $1, $3);}
603 0 : |RealMarkingFormula GEQ RealMarkingFormula {snprintf($$,BUFF_SIZE,"%s >= %s", $1, $3);}
604 8 : |RealMarkingFormula LL RealMarkingFormula {snprintf($$,BUFF_SIZE,"%s < %s", $1, $3);}
605 19 : |RealMarkingFormula GG RealMarkingFormula {snprintf($$,BUFF_SIZE,"%s > %s", $1, $3);};
606 :
607 :
608 :
609 :
610 : EdgesDef: edges EQ '{' EDGES '}' SEMICOLON{
611 :
612 : } ;
613 :
614 : EDGES: EDGE
615 : |EDGE EDGES;
616 :
617 : EDGE: LB LB str COMMA str RB COMMA ACTIONS COMMA CONSTRAINTS COMMA UPDATES RB SEMICOLON{
618 :
619 177 : if(Reader.MyLha.LocIndex.find(*$3)!=Reader.MyLha.LocIndex.end())
620 177 : if(Reader.MyLha.LocIndex.find(*$5)!=Reader.MyLha.LocIndex.end())
621 177 : { int ne=Reader.MyLha.Edge.size();
622 177 : Reader.MyLha.AnEdge.Index=ne;
623 177 : Reader.MyLha.AnEdge.Source=Reader.MyLha.LocIndex[*$3];
624 177 : Reader.MyLha.AnEdge.Target=Reader.MyLha.LocIndex[*$5];
625 177 : Reader.MyLha.Edge.push_back(Reader.MyLha.AnEdge);
626 177 : Reader.MyLha.EdgeActions.push_back(SubSet);
627 177 : if(SubSet.size()>0) Reader.MyLha.Out_S_Edges[Reader.MyLha.AnEdge.Source].insert(ne);
628 36 : else Reader.MyLha.Out_A_Edges[Reader.MyLha.AnEdge.Source].insert(ne);
629 177 : SubSet.erase(SubSet.begin(),SubSet.end());
630 177 : Reader.MyLha.ConstraintsCoeffs.push_back(CoeffsMatrix);
631 177 : Reader.MyLha.ConstraintsConstants.push_back(CST);
632 177 : Reader.MyLha.ConstraintsRelOp.push_back(comp);
633 177 : Reader.MyLha.unTimeEdgeConstraints.push_back("true");
634 354 : vector<string> vs;comp=vs;CST=vs;
635 177 : vector <vector <string> > ms;CoeffsMatrix=ms;
636 :
637 : }
638 0 : else {cout<<*$5<<" is not a location label"<<endl;YYABORT;}
639 0 : else {cout<<*$3<<" is not a location label"<<endl;YYABORT;}
640 : };
641 :
642 : ACTIONS: SHARP
643 57 : | ALL {SubSet=PetriTransitions;}
644 0 : | ALL BackSlash SetOfActions {set<string> temp=PetriTransitions;
645 0 : for(set<string>::iterator it=SubSet.begin();it!=SubSet.end();it++)
646 0 : temp.erase((*it));
647 0 : SubSet=temp;}
648 : | SetOfActions;
649 :
650 : SetOfActions: '{' Actions '}';
651 :
652 84 : Actions: str {if(Reader.MyLha.TransitionIndex.find(*$1)!=Reader.MyLha.TransitionIndex.end())
653 84 : SubSet.insert(*$1);
654 0 : else {cout<<*$1<<" is not a Petri-net transition "<<endl;YYABORT;}
655 : }
656 40 : |Actions COMMA str {if(Reader.MyLha.TransitionIndex.find(*$3)!=Reader.MyLha.TransitionIndex.end())
657 40 : SubSet.insert(*$3);
658 0 : else {cout<<*$3<<" is not a Petri-net transition "<<endl;YYABORT;}};
659 :
660 :
661 : CONSTRAINTS: CONSTRAINT {}
662 : |CONSTRAINT AND CONSTRAINTS {}
663 : |SHARP;
664 :
665 : CONSTRAINT: LinearExp EQ RealMarkingFormula
666 37 : {CoeffsMatrix.push_back(CoeffsVector);
667 37 : comp.push_back("==");
668 37 : CST.push_back($3);
669 37 : vector<string> vs(Reader.MyLha.NbVar,"");CoeffsVector=vs;}
670 : |LinearExp LEQ RealMarkingFormula
671 103 : {CoeffsMatrix.push_back(CoeffsVector);
672 103 : comp.push_back("<=");
673 103 : CST.push_back($3);
674 103 : vector<string> vs(Reader.MyLha.NbVar,"");CoeffsVector=vs;}
675 : |LinearExp GEQ RealMarkingFormula
676 1 : {CoeffsMatrix.push_back(CoeffsVector);
677 1 : comp.push_back(">=");
678 1 : CST.push_back($3);
679 1 : vector<string> vs(Reader.MyLha.NbVar,"");CoeffsVector=vs;};
680 :
681 : LinearExp: term
682 : |LinearExp MINUS term
683 : |LinearExp PLUS term;
684 :
685 : term: str
686 141 : { if(Reader.MyLha.Vars.find(*$1)!=Reader.MyLha.Vars.label.size())
687 141 : {CoeffsVector[Reader.MyLha.Vars.find(*$1)]="1";}
688 0 : else {cout<<*$1<<" is not a Lha variable"<<endl;YYABORT;}}
689 : | LB RealMarkingFormula RB MUL str
690 0 : { if(Reader.MyLha.Vars.find(*$5)!=Reader.MyLha.Vars.label.size())
691 0 : {std::ostringstream s; s<<"("<<$2<<")";
692 0 : CoeffsVector[Reader.MyLha.Vars.find(*$5)]=s.str();}
693 0 : else {cout<<*$5<<" is not a Lha variable"<<endl;YYABORT;}}
694 : | ival MUL str
695 0 : { if(Reader.MyLha.Vars.find(*$3)!=Reader.MyLha.Vars.label.size())
696 0 : {std::ostringstream s; s<<$1;
697 0 : CoeffsVector[Reader.MyLha.Vars.find(*$3)]=s.str();}
698 0 : else {cout<<*$3<<" is not a Lha variable"<<endl;YYABORT;}}
699 : | rval MUL str
700 0 : { if(Reader.MyLha.Vars.find(*$3)!=Reader.MyLha.Vars.label.size())
701 0 : {std::ostringstream s; s<<$1;
702 0 : CoeffsVector[Reader.MyLha.Vars.find(*$3)]=s.str();}
703 0 : else {cout<<*$3<<" is not a Lha variable"<<endl;YYABORT;}}
704 : | str MUL str
705 0 : { if(Reader.MyLha.Vars.find(*$3)!=Reader.MyLha.Vars.label.size())
706 0 : {if(Reader.MyLha.LhaRealConstant.find(*$1)!=Reader.MyLha.LhaRealConstant.end())
707 0 : {std::ostringstream s; s<<Reader.MyLha.LhaRealConstant[*$1];
708 0 : CoeffsVector[Reader.MyLha.Vars.find(*$3)]=s.str();
709 : }
710 : else
711 : {
712 0 : if(Reader.MyLha.PlaceIndex.find(*$1)!=Reader.MyLha.PlaceIndex.end())
713 0 : {std::ostringstream s; s<<"Marking.P->_PL_"<<$1->c_str()<<" ";
714 0 : CoeffsVector[Reader.MyLha.Vars.find(*$3)]=s.str();
715 : }
716 : else
717 : {
718 0 : cout<<*$1<<" is not Petri-net Place or a defined constant "<<endl;
719 0 : YYABORT;
720 : }
721 : }
722 : }
723 0 : else {cout<<*$3<<" is not a Lha variable"<<endl;YYABORT;}
724 : }
725 : | MINUS str %prec NEG
726 0 : { if(Reader.MyLha.Vars.find(*$2)!=Reader.MyLha.Vars.label.size())
727 0 : {CoeffsVector[Reader.MyLha.Vars.find(*$2)]="-1";}
728 0 : else {cout<<*$2<<" is not a Lha variable"<<endl;YYABORT;}}
729 : | MINUS LB RealMarkingFormula RB MUL str %prec NEG
730 0 : { if(Reader.MyLha.Vars.find(*$6)!=Reader.MyLha.Vars.label.size())
731 0 : {std::ostringstream s; s<<"-("<<$3<<")";
732 0 : CoeffsVector[Reader.MyLha.Vars.find(*$6)]=s.str();}
733 0 : else {cout<<*$6<<" is not a Lha variable"<<endl;YYABORT;}}
734 : | MINUS ival MUL str %prec NEG
735 0 : { if(Reader.MyLha.Vars.find(*$4)!=Reader.MyLha.Vars.label.size())
736 0 : {std::ostringstream s; s<<"-"<<$2;
737 0 : CoeffsVector[Reader.MyLha.Vars.find(*$4)]=s.str();}
738 0 : else {cout<<*$4<<" is not a Lha variable"<<endl;YYABORT;}}
739 : | MINUS rval MUL str %prec NEG
740 0 : { if(Reader.MyLha.Vars.find(*$4)!=Reader.MyLha.Vars.label.size())
741 0 : {std::ostringstream s; s<<"-"<<$2;
742 0 : CoeffsVector[Reader.MyLha.Vars.find(*$4)]=s.str();}
743 0 : else {cout<<*$4<<" is not a Lha variable"<<endl;YYABORT;}}
744 : | MINUS str MUL str %prec NEG
745 0 : { if(Reader.MyLha.Vars.find(*$4)!=Reader.MyLha.Vars.label.size())
746 0 : {if(Reader.MyLha.LhaRealConstant.find(*$2)!=Reader.MyLha.LhaRealConstant.end())
747 0 : {std::ostringstream s; s<<"-"<<Reader.MyLha.LhaRealConstant[*$2];
748 0 : CoeffsVector[Reader.MyLha.Vars.find(*$4)]=s.str();
749 : }
750 : else
751 : {
752 0 : if(Reader.MyLha.PlaceIndex.find(*$2)!=Reader.MyLha.PlaceIndex.end())
753 0 : {std::ostringstream s; s<<"-Marking.P->_PL_"<<$2->c_str()<<" ";
754 0 : CoeffsVector[Reader.MyLha.Vars.find(*$4)]=s.str();
755 : }
756 : else
757 : {
758 0 : cout<<*$2<<" is not Petri-net Place or a defined constant "<<endl;
759 0 : YYABORT;
760 : }
761 : }
762 : }
763 0 : else {cout<<*$4<<" is not a Lha variable"<<endl;YYABORT;}
764 : } ;
765 :
766 :
767 : UPDATES: '{' Updates '}' {
768 116 : Reader.MyLha.FuncEdgeUpdates.push_back(FuncUpdateVector);
769 116 : Reader.MyLha.FuncEdgeUpdatesIndex.push_back(FuncUpdateVectorIndex);
770 116 : FuncUpdateVector=vector<string>(Reader.MyLha.NbVar,"");
771 116 : FuncUpdateVectorIndex=vector<string>(Reader.MyLha.NbVar,"");
772 : }
773 : | SHARP {
774 61 : Reader.MyLha.FuncEdgeUpdates.push_back(FuncUpdateVector);
775 61 : Reader.MyLha.FuncEdgeUpdatesIndex.push_back(FuncUpdateVectorIndex);
776 : };
777 :
778 : Updates: Update
779 : |Updates COMMA Update ;
780 :
781 : Update: str EQ RealVarMarkingFormula {
782 204 : if(Reader.MyLha.Vars.find(*$1)!=Reader.MyLha.Vars.label.size())
783 204 : {FuncUpdateVector[Reader.MyLha.Vars.find(*$1)]= $3;}
784 0 : else{cout<<*$1<<" is not variable label"<<endl;YYABORT;}
785 : }
786 : | str LSB IntMarkingFormula RSB EQ RealVarMarkingFormula {
787 0 : size_t varin = Reader.MyLha.Vars.find(*$1);
788 0 : if(varin != Reader.MyLha.Vars.label.size()){
789 0 : FuncUpdateVector[varin]= $6;
790 0 : FuncUpdateVectorIndex[varin]= $3;
791 : //cout << "var:" << *$1 << "\tindex:" << $3 << "\tupdate:" << $6<< endl;
792 0 : }else{cout<<*$1<<" is not variable label"<<endl;YYABORT;}
793 : }
794 :
795 :
796 :
797 :
798 : HaslExps: HaslExp | HaslExp HaslExps;
799 :
800 : HaslExp: str EQ TopHaslExp SEMICOLON {
801 196 : if($3 != NULL){
802 196 : Reader.MyLha.HASLname.push_back(*$1);
803 196 : Reader.MyLha.HASLtop.push_back($3);
804 : }else{
805 0 : for(vector<string>::iterator it = Reader.MyLha.HASLname.begin(); it <Reader.MyLha.HASLname.end() ; it++){
806 0 : if( it->find("$_$") == 0)
807 0 : it->replace(0,3,*$1);
808 : }
809 : }
810 : }
811 : | TopHaslExp SEMICOLON {
812 10 : if($1 != NULL){
813 10 : Reader.MyLha.HASLname.push_back("");
814 10 : Reader.MyLha.HASLtop.push_back($1);
815 : }else{
816 0 : for(vector<string>::iterator it = Reader.MyLha.HASLname.begin(); it <Reader.MyLha.HASLname.end() ; it++){
817 0 : if( it->find("$_$") == 0)
818 0 : it->replace(0,3,"");
819 : }
820 : }
821 : }
822 :
823 : rorival:
824 0 : rval {$$=$1;}
825 0 : | ival {$$=(double)$1;}
826 0 : | str { if(Reader.MyLha.LhaRealConstant.find(*$1)!=Reader.MyLha.LhaRealConstant.end())
827 0 : $$ = Reader.MyLha.LhaRealConstant[*$1];
828 0 : else { if(Reader.MyLha.LhaIntConstant.find(*$1)!=Reader.MyLha.LhaIntConstant.end())
829 0 : $$ = (double)Reader.MyLha.LhaIntConstant[*$1];
830 : else {
831 0 : cout<<*$1<<" is not a definded constant "<<endl;
832 0 : YYABORT;
833 : }}}
834 :
835 : TopHaslExp:
836 : AVG LB AlgExpr RB {
837 197 : Reader.MyLha.Algebraic.push_back($3);
838 197 : $$ = new HaslFormulasTop((size_t)Reader.MyLha.Algebraic.size()-1);
839 : }
840 : | PROB {
841 9 : $$ = new HaslFormulasTop(PROBABILITY);
842 : }
843 : | PROB LB RB {
844 0 : $$ = new HaslFormulasTop(PROBABILITY);
845 : }
846 : | PROB LB str RB {
847 0 : Reader.MyLha.FinalStateCond.push_back(*$3);
848 0 : $$ = new HaslFormulasTop(PROBCOND,(size_t)Reader.MyLha.FinalStateCond.size()-1);
849 : }
850 : | EXIST_TOK {
851 0 : $$ = new HaslFormulasTop(EXISTS);
852 : }
853 : | NOTALL_TOK {
854 0 : $$ = new HaslFormulasTop(NOTALLS);
855 : }
856 : | SPRT LB rval COMMA rval RB {
857 0 : $$ = new HaslFormulasTop($3,$5);
858 : }
859 : | PDF LB AlgExpr COMMA rorival COMMA rorival COMMA rorival RB {
860 :
861 0 : for(double bucket = $7 ; bucket < $9 ; bucket+= $5){
862 0 : std::ostringstream algPDF;
863 0 : algPDF << "(("<<$3<<" >= "<<bucket<<"&& "<<$3<<"<"<<bucket+$5<<") ? 1:0)";
864 :
865 0 : Reader.MyLha.Algebraic.push_back(algPDF.str());
866 0 : Reader.MyLha.HASLtop.push_back(
867 0 : new HaslFormulasTop((size_t)Reader.MyLha.Algebraic.size()-1));
868 0 : Reader.MyLha.HASLtop.back()->TypeOp = PDF_PART;
869 0 : std::ostringstream s; s<<"$_$: Value in ["<< bucket<< " , "<<bucket+$5<<"]";
870 0 : Reader.MyLha.HASLname.push_back(s.str());
871 : }
872 0 : $$ = NULL;
873 : }
874 : | CDF LB AlgExpr COMMA rorival COMMA rorival COMMA rorival RB {
875 :
876 0 : for(double bucket = $7 ; bucket < $9 ; bucket+= $5){
877 0 : std::ostringstream algCDF;
878 0 : algCDF << "(("<<$3<<" <= "<<bucket<<") ? 1:0)";
879 :
880 0 : Reader.MyLha.Algebraic.push_back(algCDF.str());
881 0 : Reader.MyLha.HASLtop.push_back(
882 0 : new HaslFormulasTop((size_t)Reader.MyLha.Algebraic.size()-1));
883 0 : Reader.MyLha.HASLtop.back()->TypeOp = CDF_PART;
884 0 : std::ostringstream s; s<<"$_$: Value in [-infinity , "<< bucket<<"]";
885 0 : Reader.MyLha.HASLname.push_back(s.str());
886 : }
887 0 : $$ = NULL;
888 : }
889 : | VAR LB AlgExpr RB {
890 0 : Reader.MyLha.Algebraic.push_back($3);
891 : char tmp[5000];
892 0 : snprintf(tmp,BUFF_SIZE,"(%s * %s)", $3,$3);
893 0 : Reader.MyLha.Algebraic.push_back(tmp);
894 0 : $$ = new HaslFormulasTop(HASL_MINUS,
895 0 : new HaslFormulasTop((size_t)Reader.MyLha.Algebraic.size()-1),
896 0 : new HaslFormulasTop(HASL_TIME,
897 0 : new HaslFormulasTop((size_t)Reader.MyLha.Algebraic.size()-2),
898 0 : new HaslFormulasTop((size_t)Reader.MyLha.Algebraic.size()-2)));
899 : }
900 : | LB TopHaslExp RB {
901 1 : $$ = $2;
902 : }
903 : | TopHaslExp PLUS TopHaslExp {
904 1 : $$ = new HaslFormulasTop(HASL_PLUS, $1,$3);
905 : }
906 : | TopHaslExp MINUS TopHaslExp {
907 0 : $$ = new HaslFormulasTop(HASL_MINUS, $1,$3);
908 : }
909 : | TopHaslExp MUL TopHaslExp {
910 1 : $$ = new HaslFormulasTop(HASL_TIME, $1, $3);
911 : }
912 : | TopHaslExp DIV TopHaslExp {
913 1 : $$ = new HaslFormulasTop(HASL_DIV, $1,$3);
914 : }
915 : | ival {
916 3 : $$ = new HaslFormulasTop((double)$1,0.0,1.0);
917 : }
918 : | rval {
919 0 : $$ = new HaslFormulasTop((double)$1,0.0,1.0);
920 : }
921 :
922 394 : AlgExpr:LhaFunc {string ss=$1;
923 197 : snprintf($$,BUFF_SIZE,"LhaFunc[%d]", Reader.MyLha.LhaFunction[ss]);
924 : }
925 0 : |MIN LB AlgExpr COMMA AlgExpr RB {snprintf($$,BUFF_SIZE,"min(%s,%s)", $3,$5);}
926 0 : |MAX LB AlgExpr COMMA AlgExpr RB {snprintf($$,BUFF_SIZE,"max(%s,%s)", $3,$5);}
927 0 : |MINUS AlgExpr %prec NEG {snprintf($$,BUFF_SIZE,"-%s", $2);}
928 0 : |FLOOR LB AlgExpr RB {snprintf($$,BUFF_SIZE,"floor(%s)", $3);}
929 0 : |LB AlgExpr RB {snprintf($$,BUFF_SIZE,"(%s)", $2);}
930 0 : |AlgExpr POWER AlgExpr {snprintf($$,BUFF_SIZE,"pow(%s , %s)", $1,$3);}
931 0 : |AlgExpr PLUS AlgExpr {snprintf($$,BUFF_SIZE,"(%s + %s)", $1,$3);}
932 0 : |AlgExpr MINUS AlgExpr {snprintf($$,BUFF_SIZE,"(%s - %s)", $1,$3);}
933 0 : |AlgExpr MUL AlgExpr {snprintf($$,BUFF_SIZE,"(%s * %s)", $1,$3);}
934 0 : |AlgExpr DIV AlgExpr {snprintf($$,BUFF_SIZE,"(%s / %s)", $1,$3);};
935 :
936 392 : LhaFunc: LAST LB LinForm RB {std::ostringstream s; s<<$3;
937 196 : if(Reader.MyLha.LinearForm.find(s.str())==Reader.MyLha.LinearForm.end())
938 195 : {int i=Reader.MyLha.LinearForm.size();Reader.MyLha.LinearForm[s.str()]=i;}
939 196 : Reader.MyLha.LhaFuncArg.push_back(Reader.MyLha.LinearForm[s.str()]);
940 196 : Reader.MyLha.LhaFuncType.push_back("Last");
941 392 : string ss="Last("; ss.append(s.str()); ss.append(")");
942 196 : if(Reader.MyLha.LhaFunction.find(ss)==Reader.MyLha.LhaFunction.end())
943 195 : {int i=Reader.MyLha.LhaFunction.size();Reader.MyLha.LhaFunction[ss]=i;}
944 196 : snprintf($$,BUFF_SIZE,"%s", ss.c_str());
945 : }
946 0 : |LhaMIN LB LinForm RB {std::ostringstream s; s<<$3;
947 0 : if(Reader.MyLha.LinearForm.find(s.str())==Reader.MyLha.LinearForm.end())
948 0 : {int i=Reader.MyLha.LinearForm.size();Reader.MyLha.LinearForm[s.str()]=i;}
949 0 : Reader.MyLha.LhaFuncArg.push_back(Reader.MyLha.LinearForm[s.str()]);
950 0 : Reader.MyLha.LhaFuncType.push_back("Min");
951 0 : string ss="Min("; ss.append(s.str()); ss.append(")");
952 0 : if(Reader.MyLha.LhaFunction.find(ss)==Reader.MyLha.LhaFunction.end())
953 0 : {int i=Reader.MyLha.LhaFunction.size();Reader.MyLha.LhaFunction[ss]=i;}
954 0 : snprintf($$,BUFF_SIZE,"%s", ss.c_str());
955 : }
956 2 : |LhaMAX LB LinForm RB{std::ostringstream s; s<<$3;
957 1 : if(Reader.MyLha.LinearForm.find(s.str())==Reader.MyLha.LinearForm.end())
958 1 : {int i=Reader.MyLha.LinearForm.size();Reader.MyLha.LinearForm[s.str()]=i;}
959 1 : Reader.MyLha.LhaFuncArg.push_back(Reader.MyLha.LinearForm[s.str()]);
960 1 : Reader.MyLha.LhaFuncType.push_back("Max");
961 2 : string ss="Max("; ss.append(s.str()); ss.append(")");
962 1 : if(Reader.MyLha.LhaFunction.find(ss)==Reader.MyLha.LhaFunction.end())
963 1 : {int i=Reader.MyLha.LhaFunction.size();Reader.MyLha.LhaFunction[ss]=i;}
964 1 : snprintf($$,BUFF_SIZE,"%s", ss.c_str());
965 : }
966 0 : |INTEGRAL LB LinForm RB{std::ostringstream s; s<<$3;
967 0 : if(Reader.MyLha.LinearForm.find(s.str())==Reader.MyLha.LinearForm.end())
968 0 : {int i=Reader.MyLha.LinearForm.size();Reader.MyLha.LinearForm[s.str()]=i;}
969 0 : Reader.MyLha.LhaFuncArg.push_back(Reader.MyLha.LinearForm[s.str()]);
970 0 : Reader.MyLha.LhaFuncType.push_back("Integral");
971 0 : string ss="Integral("; ss.append(s.str()); ss.append(")");
972 0 : if(Reader.MyLha.LhaFunction.find(ss)==Reader.MyLha.LhaFunction.end())
973 0 : {int i=Reader.MyLha.LhaFunction.size();Reader.MyLha.LhaFunction[ss]=i;}
974 0 : snprintf($$,BUFF_SIZE,"%s", ss.c_str());
975 : }
976 0 : | MEAN LB LinForm RB{std::ostringstream s; s<<$3;
977 0 : if(Reader.MyLha.LinearForm.find(s.str())==Reader.MyLha.LinearForm.end())
978 0 : {int i=Reader.MyLha.LinearForm.size();Reader.MyLha.LinearForm[s.str()]=i;}
979 0 : Reader.MyLha.LhaFuncArg.push_back(Reader.MyLha.LinearForm[s.str()]);
980 0 : Reader.MyLha.LhaFuncType.push_back("Mean");
981 0 : string ss="Mean("; ss.append(s.str()); ss.append(")");
982 0 : if(Reader.MyLha.LhaFunction.find(ss)==Reader.MyLha.LhaFunction.end())
983 0 : {int i=Reader.MyLha.LhaFunction.size();Reader.MyLha.LhaFunction[ss]=i;}
984 0 : snprintf($$,BUFF_SIZE,"%s", ss.c_str());
985 : };
986 :
987 197 : LinForm: VarTerm {snprintf($$,BUFF_SIZE,"%s", $1); }
988 0 : |LinForm MINUS VarTerm {snprintf($$,BUFF_SIZE,"%s - %s", $1, $3); }
989 0 : |LinForm PLUS VarTerm {snprintf($$,BUFF_SIZE,"%s + %s", $1, $3); };
990 :
991 : VarTerm:
992 : str
993 197 : { if(Reader.MyLha.Vars.find(*$1)!=Reader.MyLha.Vars.label.size())
994 197 : {snprintf($$,BUFF_SIZE,"Vars->%s", $1->c_str());}
995 0 : else if(Reader.MyLha.LhaRealHybrid.find(*$1)!=Reader.MyLha.LhaRealHybrid.end())
996 0 : {snprintf($$,BUFF_SIZE," hybridVar::%s",$1->c_str());}
997 0 : else if(Reader.MyLha.PlaceIndex.find(*$1)!=Reader.MyLha.PlaceIndex.end())
998 0 : {std::ostringstream s; s<<" Marking.P->_PL_"<< $1->c_str();
999 0 : if(Reader.MyLha.MyGspn->placeStruct[Reader.MyLha.PlaceIndex[*$1]].colorDom !=0 )s <<".card()";
1000 0 : snprintf($$,BUFF_SIZE, "%s ",(s.str()).c_str());
1001 0 : } else {cout<<*$1<<" is not a Hybrid variable, a Lha variable or a place name"<<endl;YYABORT;}
1002 : }
1003 : | str SHARP {
1004 0 : if(Reader.MyLha.PlaceIndex.find(*$1)!=Reader.MyLha.PlaceIndex.end())
1005 0 : {std::ostringstream s; s<<" Marking.P->_PL_"<<$1->c_str();
1006 0 : if(Reader.MyLha.MyGspn->placeStruct[Reader.MyLha.PlaceIndex[*$1]].colorDom !=0 )s <<".value()";
1007 0 : snprintf($$,BUFF_SIZE, "%s ",(s.str()).c_str());
1008 : }
1009 0 : else {cout<<"'"<<*$1<<"' is not a place label"<<endl;YYABORT;}}
1010 : | str LSB IntMarkingFormula RSB {
1011 0 : if(Reader.MyLha.Vars.find(*$1)!=Reader.MyLha.Vars.label.size()){
1012 0 : snprintf($$,BUFF_SIZE,"Vars->%s[%s]", $1->c_str(), $3);
1013 0 : } else {cout<<*$1<<" is not a Lha array variable "<<endl;YYABORT;}
1014 : }
1015 :
1016 : //| RealMarkingFormula { sprintf($$,"(%s)", $1); }
1017 : | LB RealMarkingFormula RB MUL str
1018 0 : { if(Reader.MyLha.Vars.find(*$5)!=Reader.MyLha.Vars.label.size())
1019 0 : {snprintf($$,BUFF_SIZE,"(%s) * Vars->%s", $2, $5->c_str());
1020 : }
1021 0 : else {cout<<*$5<<" is not a Lha variable"<<endl;YYABORT;}}
1022 : | ival MUL str
1023 0 : { if(Reader.MyLha.Vars.find(*$3)!=Reader.MyLha.Vars.label.size())
1024 0 : {snprintf($$,BUFF_SIZE,"%d * Vars->%s", $1, $3->c_str());
1025 : }
1026 0 : else {cout<<*$3<<" is not a Lha variable"<<endl;YYABORT;}}
1027 : | rval MUL str
1028 0 : { if(Reader.MyLha.Vars.find(*$3)!=Reader.MyLha.Vars.label.size())
1029 0 : {snprintf($$,BUFF_SIZE,"%f * Vars->%s", $1, $3->c_str());
1030 : }
1031 0 : else {cout<<*$3<<" is not a Lha variable"<<endl;YYABORT;}}
1032 :
1033 : | ival
1034 0 : { sprintf($$,"%i ", $1);
1035 : }
1036 : | rval
1037 0 : { sprintf($$,"%f ", $1);}
1038 :
1039 : | str MUL str
1040 0 : { if(Reader.MyLha.Vars.find(*$3)!=Reader.MyLha.Vars.label.size())
1041 0 : {if(Reader.MyLha.LhaRealConstant.find(*$1)!=Reader.MyLha.LhaRealConstant.end())
1042 0 : {snprintf($$,BUFF_SIZE,"%f * Vars->%s", Reader.MyLha.LhaRealConstant[*$1],$3->c_str());
1043 : }
1044 : else
1045 : {
1046 0 : if(Reader.MyLha.PlaceIndex.find(*$1)!=Reader.MyLha.PlaceIndex.end())
1047 0 : {snprintf($$,BUFF_SIZE,"Marking.P->_PL_%s * Vars->%s", $1->c_str() ,$3->c_str());
1048 : }
1049 : else
1050 : {
1051 0 : cout<<*$1<<" is not Petri-net Place or a definded constant "<<endl;
1052 0 : YYABORT;
1053 : }
1054 : }
1055 : }
1056 0 : else {cout<<*$3<<" is not a Lha variable"<<endl;YYABORT;}
1057 : }
1058 : |MINUS str %prec NEG
1059 0 : { if(Reader.MyLha.Vars.find(*$2)!=Reader.MyLha.Vars.label.size())
1060 0 : {snprintf($$,BUFF_SIZE,"-Vars->%s", $2->c_str());}
1061 0 : else {cout<<*$2<<" is not a Lha variable"<<endl;YYABORT;}}
1062 : | MINUS LB RealMarkingFormula RB MUL str
1063 0 : { if(Reader.MyLha.Vars.find(*$6)!=Reader.MyLha.Vars.label.size())
1064 0 : {snprintf($$,BUFF_SIZE,"-(%s) * Vars->%s", $3, $6->c_str());
1065 : }
1066 0 : else {cout<<*$5<<" is not a Lha variable"<<endl;YYABORT;}}
1067 : | MINUS ival MUL str %prec NEG
1068 0 : { if(Reader.MyLha.Vars.find(*$4)!=Reader.MyLha.Vars.label.size())
1069 0 : {snprintf($$,BUFF_SIZE,"-%d * Vars->%s", $2, $4->c_str());
1070 : }
1071 0 : else {cout<<*$4<<" is not a Lha variable"<<endl;YYABORT;}}
1072 : | MINUS rval MUL str %prec NEG
1073 0 : { if(Reader.MyLha.Vars.find(*$4)!=Reader.MyLha.Vars.label.size())
1074 0 : {snprintf($$,BUFF_SIZE,"-%f * Vars->%s", $2, $4->c_str());
1075 : }
1076 0 : else {cout<<*$4<<" is not a Lha variable"<<endl;YYABORT;}}
1077 : | MINUS str MUL str %prec NEG
1078 0 : { if(Reader.MyLha.Vars.find(*$4)!=Reader.MyLha.Vars.label.size())
1079 0 : {if(Reader.MyLha.LhaRealConstant.find(*$2)!=Reader.MyLha.LhaRealConstant.end())
1080 0 : {snprintf($$,BUFF_SIZE,"-%f * Vars->%s", Reader.MyLha.LhaRealConstant[*$2],$4->c_str());
1081 : }
1082 : else
1083 : {
1084 0 : if(Reader.MyLha.PlaceIndex.find(*$2)!=Reader.MyLha.PlaceIndex.end())
1085 0 : {sprintf($$,"-Marking.P->_PL_%s * Vars->%s", $2->c_str() ,$4->c_str());
1086 : }
1087 : else
1088 : {
1089 0 : cout<<*$2<<" is not Petri-net Place or a definded constant "<<endl;
1090 0 : YYABORT;
1091 : }
1092 : }
1093 : }
1094 0 : else {cout<<*$4<<" is not a Lha variable"<<endl;YYABORT;}
1095 : };
1096 :
1097 :
1098 :
1099 :
1100 :
1101 : %%
1102 :
1103 : void
1104 0 : lha::Lha_parser::error (const lha::Lha_parser::location_type& l,
1105 : const std::string& m)
1106 : {
1107 0 : Reader.error (l, m);
1108 105 : }
|