Line data Source code
1 : %skeleton "lalr1.cc" /* -*- C++ -*- */
2 : %require "2.4"
3 : %defines
4 : %define parser_class_name {Gspn_parser}
5 :
6 : %code requires {
7 : #include <math.h>
8 : #include <limits.h>
9 : #include <string>
10 : #include <fstream>
11 : #include <sstream>
12 : #include <set>
13 :
14 : #include "../expressionStruct.hpp"
15 : #include "../../Simulator/DistributionDef.hpp"
16 : #include "../Eval/Eval.hpp"
17 :
18 : class Gspn_Reader;
19 : using namespace std;
20 :
21 : #define BUFF_SIZE 5000
22 :
23 : }
24 :
25 :
26 : %parse-param { Gspn_Reader& Reader }
27 : %lex-param { Gspn_Reader& Reader }
28 :
29 : %locations
30 :
31 : %debug
32 : %error-verbose
33 :
34 : // Symbols.
35 : %union
36 : {
37 : double RealVal;
38 : int IntVal;
39 : std::string *name;
40 : char CharVal[100];
41 : char expression[BUFF_SIZE];
42 : };
43 :
44 : %code {
45 : #include "Gspn-Reader.hpp"
46 : #include <set>
47 : #include <vector>
48 :
49 35 : vector<string> Par;
50 35 : std::string distrib;
51 35 : Eval Evaluate;
52 :
53 :
54 : int NbServers;
55 : bool SingleService;
56 : bool MarkingDependent;
57 : bool AgeMemory;
58 :
59 : }
60 :
61 : %token END 0 "end of file"
62 :
63 : %token <name> str
64 : %token <CharVal> chr
65 : %token <RealVal> rval
66 : %token <IntVal> ival
67 :
68 : %token <name> SEMICOLON
69 : %token <name> COMMA
70 : %token <name> LB
71 : %token <name> RB
72 : %token <name> EQ
73 : %token <name> DIV
74 : %token <name> MUL
75 : %token <name> PLUS
76 : %token <name> MINUS
77 : %token <name> POWER
78 : %token <name> GspnName
79 : %token <name> NbPl
80 : %token <name> NbTr
81 : %token <name> PList
82 : %token <name> TList
83 :
84 : %token <name> in
85 : %token <name> out
86 : %token <name> marking
87 : %token <name> transitions
88 : %token <name> Const
89 : %token <name> INT
90 : %token <name> DOUBLE
91 : %token <name> inhibitor
92 : %token <name> MIN
93 : %token <name> MAX
94 : %token <name> FLOOR
95 :
96 : %token <name> SINGLE
97 : %token <name> INFINITE
98 : %token <name> MULTIPLE
99 :
100 : %token <name> ENABLINGMEMORY
101 : %token <name> AGEMEMORY
102 :
103 : %token <name> IMDT
104 : %token <name> EXPO
105 :
106 : %type<expression> IntStringFormula
107 : %type<expression> RealStringFormula
108 : %type<expression> WEIGHT
109 : %type<expression> PRIORITY
110 :
111 :
112 :
113 :
114 0 : %printer { debug_stream () << *$$; } str
115 0 : %destructor { delete $$; } str
116 :
117 0 : %printer { debug_stream () << $$; } <IntVal>
118 0 : %printer { debug_stream () << $$; } <RealVal>
119 :
120 : %%
121 :
122 :
123 : %left PLUS MINUS;
124 : %left MUL DIV;
125 : %left POWER;
126 :
127 :
128 : %start GSPN;
129 :
130 233 : IntStringFormula: ival { sprintf($$,"%d",$1);}
131 : | str {
132 8 : if(Reader.spn->PlacesId.find(*$1)!=Reader.spn->PlacesId.end())
133 0 : {std::ostringstream s; s<<" Marking.P->_PL_"<< $1->c_str() <<" ";
134 0 : sprintf($$, "%s",(s.str()).c_str());
135 : }
136 8 : else if(Reader.spn->IntConstant.find(*$1)!=Reader.spn->IntConstant.end())
137 16 : {std::ostringstream s; s<<Reader.spn->IntConstant[*$1];
138 8 : sprintf($$, "%s",(s.str()).c_str());
139 :
140 : }
141 0 : else{cout<<"'"<<*$1<<"' has not been declared"<<endl;YYABORT;}}
142 0 : | LB IntStringFormula RB{snprintf($$,BUFF_SIZE,"( %s )", $2); }
143 0 : | IntStringFormula PLUS IntStringFormula {snprintf($$,BUFF_SIZE,"%s + %s", $1, $3); }
144 0 : | IntStringFormula MINUS IntStringFormula {snprintf($$,BUFF_SIZE,"%s - %s", $1, $3); }
145 0 : | IntStringFormula MUL IntStringFormula {snprintf($$,BUFF_SIZE,"%s * %s", $1, $3); }
146 0 : | IntStringFormula POWER IntStringFormula {snprintf($$,BUFF_SIZE,"pow(%s , %s)", $1, $3); }
147 0 : | FLOOR LB IntStringFormula RB {snprintf($$,BUFF_SIZE,"floor( %s )", $3); }
148 0 : | FLOOR LB IntStringFormula DIV IntStringFormula RB {snprintf($$,BUFF_SIZE,"floor( %s /double(%s)", $3,$5); }
149 0 : | MIN LB IntStringFormula COMMA IntStringFormula RB {snprintf($$,BUFF_SIZE,"min(%s , %s)", $3, $5); }
150 0 : | MAX LB IntStringFormula COMMA IntStringFormula RB {snprintf($$,BUFF_SIZE,"max(%s , %s)", $3, $5); };
151 :
152 :
153 28 : RealStringFormula: rval {sprintf($$, "%f",$1);}
154 168 : | ival {snprintf($$,BUFF_SIZE,"%d",$1);}
155 : | str {
156 46 : if(Reader.spn->PlacesId.find(*$1)!=Reader.spn->PlacesId.end())
157 20 : {std::ostringstream s; s<<" Marking.P->_PL_"<<$1->c_str()<<" ";
158 10 : snprintf($$,BUFF_SIZE, "%s",(s.str()).c_str());
159 : }
160 36 : else if(Reader.spn->RealConstant.find(*$1)!=Reader.spn->RealConstant.end())
161 72 : {std::ostringstream s; s<<Reader.spn->RealConstant[*$1];
162 36 : snprintf($$,BUFF_SIZE, "%s",(s.str()).c_str());
163 : }
164 0 : else{cout<<"'"<<*$1<<"' has not been declared"<<endl;YYABORT;}}
165 0 : | LB RealStringFormula RB {snprintf($$,BUFF_SIZE,"( %s )", $2); }
166 0 : | RealStringFormula DIV RealStringFormula {snprintf($$,BUFF_SIZE,"%s /double(%s)", $1, $3); }
167 0 : | RealStringFormula PLUS RealStringFormula {snprintf($$,BUFF_SIZE,"%s + %s", $1, $3); }
168 0 : | RealStringFormula MINUS RealStringFormula {snprintf($$,BUFF_SIZE,"%s - %s", $1, $3); }
169 12 : | RealStringFormula MUL RealStringFormula {snprintf($$,BUFF_SIZE,"%s * %s", $1, $3); }
170 0 : | RealStringFormula POWER RealStringFormula {snprintf($$,BUFF_SIZE,"pow(%s , %s)", $1, $3); }
171 0 : | FLOOR LB RealStringFormula RB {snprintf($$,BUFF_SIZE,"floor( %s )", $3); }
172 0 : | MIN LB RealStringFormula COMMA RealStringFormula RB {snprintf($$,BUFF_SIZE,"min(%s , %s)", $3, $5); }
173 0 : | MAX LB RealStringFormula COMMA RealStringFormula RB {snprintf($$,BUFF_SIZE,"max(%s , %s)", $3, $5); };
174 :
175 :
176 :
177 : GSPN: declarations definitions
178 : |declarations definitions redifinitions;
179 :
180 : declarations: Constants Sizes Lists
181 : | Sizes Lists;
182 :
183 :
184 :
185 : Constants: Constant
186 : |Constant Constants;
187 :
188 : Sizes: NbPlaces NbTransitions
189 : |NbTransitions NbPlaces;
190 :
191 : Constant: Const INT str EQ IntStringFormula SEMICOLON
192 11 : {if(Reader.spn->RealConstant.find(*$3)!=Reader.spn->RealConstant.end())
193 0 : {cout<<"Constant "<<*$3<<" already defined."<<endl; YYABORT;}
194 22 : else {string st=$5;
195 11 : if (Reader.P.constants.count(*$3)>0)st = Reader.P.constants[*$3];
196 :
197 11 : Evaluate.parse(st);
198 11 : Reader.spn->IntConstant[*$3]=Evaluate.IntResult;
199 11 : Reader.spn->RealConstant[*$3]=Evaluate.RealResult;}
200 : }
201 : | Const DOUBLE str EQ RealStringFormula SEMICOLON
202 24 : {if(Reader.spn->RealConstant.find(*$3)!=Reader.spn->RealConstant.end())
203 0 : {cout<<"Constant "<<*$3<<" already defined."<<endl; YYABORT;}
204 48 : else {string st=$5;
205 24 : if (Reader.P.constants.count(*$3)>0)st = Reader.P.constants[*$3];
206 24 : Evaluate.parse(st);
207 24 : Reader.spn->RealConstant[*$3]=Evaluate.RealResult;}
208 : };
209 :
210 : Lists: PlacesList TransitionsList
211 : |TransitionsList PlacesList;
212 :
213 11 : NbPlaces: NbPl EQ ival SEMICOLON {Reader.spn->pl=$3;
214 :
215 : }
216 0 : |NbPl EQ str SEMICOLON {if(Reader.spn->IntConstant.find(*$3)==Reader.spn->IntConstant.end())
217 : {
218 0 : std::cout<<*$3<<" was not declared"<<std::endl;
219 0 : YYABORT;
220 : }
221 0 : Reader.spn->pl=Reader.spn->IntConstant[*$3];
222 :
223 : };
224 :
225 11 : NbTransitions: NbTr EQ ival SEMICOLON {Reader.spn->tr=$3;
226 :
227 : }
228 0 : |NbTr EQ str SEMICOLON {if(Reader.spn->IntConstant.find(*$3)==Reader.spn->IntConstant.end())
229 : {
230 0 : std::cout<<*$3<<" was not declared"<<std::endl;
231 0 : YYABORT;
232 : }
233 0 : Reader.spn->tr=Reader.spn->IntConstant[*$3];
234 :
235 : };
236 :
237 : PlacesList: PList EQ '{' PLabels '}' SEMICOLON {
238 11 : if(Reader.spn->PlacesId.size()!=Reader.spn->pl){
239 0 : std::cout<<"Place label missing or redeclared, expected:"<< Reader.spn->pl <<"; found: "<< Reader.spn->PlacesId.size() <<std::endl;
240 0 : YYABORT;
241 : }
242 :
243 : //Reader.spn->Marking= vector<string>(Reader.spn->pl, " ");
244 :
245 11 : MarkingDependent=false;
246 11 : AgeMemory=false;
247 :
248 :
249 : };
250 :
251 : PLabels : str {
252 : //cout << "New place name:" << *$1 << endl;
253 22 : place p;
254 11 : p.name = *$1;
255 11 : p.id = Reader.spn->placeStruct.size();
256 11 : Reader.spn->placeStruct.push_back(p);
257 11 : int sz=Reader.spn->PlacesId.size();
258 11 : Reader.spn->PlacesId[*$1]=sz;
259 : }
260 : |PLabels COMMA str {
261 : //cout << "New place name:" << *$3 << endl;
262 :
263 98 : place p;
264 49 : p.name = *$3;
265 49 : p.id = Reader.spn->placeStruct.size();
266 49 : Reader.spn->placeStruct.push_back(p);
267 49 : int sz=Reader.spn->PlacesId.size();
268 49 : Reader.spn->PlacesId[*$3]=sz;
269 : };
270 :
271 : TransitionsList: TList EQ '{' TLabels '}' SEMICOLON {
272 11 : if(Reader.spn->TransList.size()!=Reader.spn->tr){
273 0 : std::cout<<"Transition label missing or redeclared, expected:"<< Reader.spn->tr <<"; found: "<< Reader.spn->TransList.size() << endl;
274 0 : YYABORT;
275 : }
276 :
277 : };
278 :
279 11 : TLabels : str {Reader.spn->TransList.insert(*$1);
280 : /*int sz=Reader.spn->TransId.size();
281 : Reader.spn->TransId[*$1]=sz;*/
282 :
283 : }
284 62 : |TLabels COMMA str {Reader.spn->TransList.insert(*$3);
285 : /*int sz=Reader.spn->TransId.size();
286 : Reader.spn->TransId[*$3]=sz;*/
287 :
288 : };
289 :
290 :
291 : definitions: PlacesDef TransitionsDef InArcs OutArcs
292 : |PlacesDef TransitionsDef InArcs OutArcs Inhibitors;
293 :
294 : PlacesDef: marking EQ '{' PLACES '}' SEMICOLON {};
295 :
296 : PLACES: PLACE
297 : |PLACES PLACE;
298 :
299 : PLACE: LB str COMMA IntStringFormula RB SEMICOLON
300 60 : { if(Reader.spn->PlacesId.find(*$2)==Reader.spn->PlacesId.end())
301 0 : {cout<<"'"<<*$2<<"' has not been declared"<<endl;
302 0 : YYABORT;
303 : }
304 120 : string st=$4;
305 60 : if(Evaluate.parse(st)){
306 0 : std::cout<<"Initial Marking is not marking dependent"<<std::endl;
307 0 : YYABORT;
308 : }
309 120 : stringstream ss;
310 60 : ss << Evaluate.IntResult;
311 60 : Reader.spn->placeStruct[Reader.spn->PlacesId[*$2]].Marking=ss.str();
312 60 : Reader.spn->placeStruct[Reader.spn->PlacesId[*$2]].initMarking=vector<coloredToken>(1, coloredToken(ss.str()));
313 : };
314 :
315 :
316 : TransitionsDef: transitions EQ '{' TRANSITIONS '}' SEMICOLON;
317 :
318 : TRANSITIONS: TRANSITION {}
319 : |TRANSITIONS TRANSITION {};
320 :
321 : TRANSITION: LB str COMMA dist COMMA PRIORITY COMMA WEIGHT RB SEMICOLON {
322 2 : if(Reader.spn->TransList.find(*$2)==Reader.spn->TransList.end())
323 : {
324 0 : std::cout<<"Transition: "<<*$2<<" was not declared"<<std::endl;
325 0 : YYABORT;
326 : }
327 2 : transition *trans = new transition();
328 2 : trans->name = $2->c_str();
329 2 : trans->type = Timed;
330 2 : trans->dist.name = distrib;
331 2 : for(auto &s:Par)trans->dist.Param.push_back(expr(s));
332 2 : trans->priority = expr(string($6));
333 2 : trans->weight = expr(string($8));
334 2 : trans->singleService = true;
335 2 : trans->markingDependant = false;
336 2 : trans->ageMemory = false;
337 2 : trans->nbServers = 1;
338 2 : trans->id = Reader.spn->transitionStruct.size();
339 2 : int sz=Reader.spn->TransId.size();
340 2 : Reader.spn->TransId[*$2]=sz;
341 2 : Reader.spn->transitionStruct.push_back(*trans);
342 :
343 2 : Par.clear();
344 : }
345 : | LB str COMMA dist COMMA PRIORITY COMMA WEIGHT COMMA MEMORY RB SEMICOLON {
346 0 : if(Reader.spn->TransList.find(*$2)==Reader.spn->TransList.end())
347 : {
348 0 : std::cout<<"Transition: "<<*$2<<" was not declared"<<std::endl;
349 0 : YYABORT;
350 : }
351 0 : transition *trans = new transition();
352 0 : trans->name = $2->c_str();
353 0 : trans->type = Timed;
354 0 : trans->dist.name = distrib;
355 0 : for(auto &s:Par)trans->dist.Param.push_back(expr(s));
356 0 : trans->priority = *$6;
357 0 : trans->weight = *$8;
358 0 : trans->singleService = true;
359 0 : trans->markingDependant = false;
360 0 : trans->ageMemory = AgeMemory;
361 0 : trans->nbServers = 1;
362 0 : trans->id = Reader.spn->transitionStruct.size();
363 0 : int sz=Reader.spn->TransId.size();
364 0 : Reader.spn->TransId[*$2]=sz;
365 0 : Reader.spn->transitionStruct.push_back(*trans);
366 :
367 0 : Par.clear();
368 0 : AgeMemory=false;
369 : }
370 : | LB str COMMA EXPO LB RealStringFormula RB COMMA PRIORITY COMMA WEIGHT COMMA SERVICE RB SEMICOLON {
371 56 : if(Reader.spn->TransList.find(*$2)==Reader.spn->TransList.end())
372 : {
373 0 : std::cout<<"Transition: "<<*$2<<" was not declared"<<std::endl;
374 0 : YYABORT;
375 : }
376 56 : if(!SingleService) MarkingDependent=true;
377 112 : string st=$6;
378 112 : vector<string> v(1);
379 56 : if(Evaluate.parse(st))
380 10 : {MarkingDependent=true;v[0]=st;
381 : }
382 46 : else{ if (Evaluate.RealResult<= 0 ) {
383 0 : cout << "In exponential distribution Lambda > 0" << endl;
384 0 : YYABORT;
385 : }
386 92 : std::ostringstream s;s<<Evaluate.RealResult;
387 46 : v[0]=s.str();
388 46 : Par.clear();
389 : }
390 :
391 56 : transition *trans = new transition();
392 56 : trans->name = $2->c_str();
393 56 : trans->type = Timed;
394 56 : trans->dist.name = "EXPONENTIAL";
395 56 : for(auto &s:v)trans->dist.Param.push_back(expr(s));
396 56 : trans->priority = expr(string($9));
397 56 : trans->weight = expr(string($11));
398 56 : trans->singleService = SingleService;
399 56 : trans->markingDependant = MarkingDependent;
400 56 : trans->ageMemory = false;
401 56 : trans->nbServers = NbServers;
402 56 : trans->id = Reader.spn->transitionStruct.size();
403 56 : int sz=Reader.spn->TransId.size();
404 56 : Reader.spn->TransId[*$2]=sz;
405 56 : Reader.spn->transitionStruct.push_back(*trans);
406 :
407 56 : Par.clear();
408 56 : MarkingDependent=false;
409 :
410 : }
411 :
412 : | LB str COMMA EXPO LB RealStringFormula RB COMMA PRIORITY COMMA WEIGHT COMMA SERVICE COMMA MEMORY RB SEMICOLON {
413 0 : if(Reader.spn->TransList.find(*$2)==Reader.spn->TransList.end())
414 : {
415 0 : std::cout<<"Transition: "<<*$2<<" was not declared"<<std::endl;
416 0 : YYABORT;
417 : }
418 :
419 0 : if(!SingleService) MarkingDependent=true;
420 0 : string st=$6;
421 0 : vector<string> v(1);
422 0 : if(Evaluate.parse(st))
423 0 : {MarkingDependent=true;v[0]=st;
424 : }
425 0 : else{ if (Evaluate.RealResult<= 0 ) {
426 0 : cout << "In exponential distribution Lambda > 0" << endl;
427 0 : YYABORT;
428 : }
429 0 : std::ostringstream s;s<<Evaluate.RealResult;
430 0 : v[0]=s.str();
431 : }
432 :
433 0 : transition *trans = new transition();
434 0 : trans->name= $2->c_str();
435 0 : trans->type = Timed;
436 0 : trans->dist.name = "EXPONENTIAL";
437 0 : for(auto &s:v)trans->dist.Param.push_back(expr(s));
438 0 : trans->priority = expr(string($9));
439 0 : trans->weight = expr(string($11));
440 0 : trans->singleService = SingleService;
441 0 : trans->markingDependant = MarkingDependent;
442 0 : trans->ageMemory = AgeMemory;
443 0 : trans->nbServers = NbServers;
444 0 : trans->id = Reader.spn->transitionStruct.size();
445 0 : Reader.spn->transitionStruct.push_back(*trans);
446 0 : int sz=Reader.spn->TransId.size();
447 0 : Reader.spn->TransId[*$2]=sz;
448 0 : MarkingDependent=false;
449 0 : AgeMemory=false;
450 0 : Par.clear();
451 : }
452 :
453 : |LB str COMMA IMDT COMMA PRIORITY COMMA WEIGHT RB SEMICOLON {
454 15 : if(Reader.spn->TransList.find(*$2)==Reader.spn->TransList.end())
455 : {
456 0 : std::cout<<"Transition: "<<*$2<<" was not declared"<<std::endl;
457 0 : YYABORT;
458 : }
459 :
460 15 : transition *trans = new transition();
461 15 : trans->name = $2->c_str();
462 15 : trans->type = unTimed;
463 15 : trans->dist.name = "IMMEDIATE";
464 15 : trans->priority = expr(string($6));
465 15 : trans->weight = expr(string($8));
466 15 : trans->singleService = true;
467 15 : trans->markingDependant = false;
468 15 : trans->ageMemory = false;
469 15 : trans->nbServers = 1;
470 15 : trans->id = Reader.spn->transitionStruct.size();
471 15 : int sz=Reader.spn->TransId.size();
472 15 : Reader.spn->TransId[*$2]=sz;
473 15 : Reader.spn->transitionStruct.push_back(*trans);
474 15 : Par.clear();
475 : };
476 :
477 :
478 :
479 :
480 :
481 : WEIGHT: RealStringFormula
482 146 : {string st=$1;
483 73 : if(Evaluate.parse(st))
484 0 : {cout<<"Weight is not marking dependent: '"<<st<<"'"<<endl;YYABORT; }
485 73 : else{ if(Evaluate.RealResult<0)
486 0 : {cout<<"Weight is a positive value: '"<<st<<"'"<<endl; YYABORT;}
487 146 : else{std::ostringstream s;s<<Evaluate.RealResult;
488 73 : sprintf($$, "%s",(s.str()).c_str());
489 : }
490 : }
491 : };
492 : PRIORITY: RealStringFormula
493 146 : {string st=$1;
494 73 : if(Evaluate.parse(st))
495 0 : {cout<<"Priority is not marking dependent: '"<<st<<"'"<<endl;YYABORT; }
496 73 : else{ if(Evaluate.RealResult<0)
497 0 : {cout<<"Priority is a positive value: '"<<st<<"'"<<endl; YYABORT;}
498 146 : else{std::ostringstream s;s<<Evaluate.RealResult;
499 73 : sprintf($$, "%s",(s.str()).c_str());
500 : }
501 : }
502 : };
503 :
504 56 : SERVICE: SINGLE {SingleService=true; NbServers=1;}
505 0 : | INFINITE {SingleService=false;NbServers=INT_MAX;}
506 0 : | MULTIPLE LB ival RB {NbServers= $3;
507 0 : if(NbServers<1)
508 0 : { cout<<"Number of servers should be at least one"<<endl;
509 0 : YYABORT;
510 : }
511 0 : if(NbServers==1) SingleService=true;
512 0 : else {SingleService=false;}
513 :
514 :
515 : }
516 : | MULTIPLE LB str RB {
517 0 : if(Reader.spn->IntConstant.find(*$3)!=Reader.spn->IntConstant.end()){
518 0 : NbServers=Reader.spn->IntConstant[*$3];
519 0 : if(NbServers<1)
520 0 : { cout<<"Number of servers should be at least one"<<endl;
521 0 : YYABORT;
522 : }
523 0 : if(NbServers==1) SingleService=true;
524 0 : else {SingleService=false;}
525 : }
526 0 : else{cout<<*$3<<" not defined or not defined like an integer constant "<<endl;}
527 :
528 : };
529 :
530 0 : MEMORY: AGEMEMORY{AgeMemory=true;}
531 0 : | ENABLINGMEMORY{AgeMemory=false;};
532 :
533 :
534 : dist:str LB params RB {
535 2 : distrib=*$1;
536 2 : int np=Par.size();
537 2 : switch (Reader.IndexDist[distrib]) {
538 : case UNIFORM:
539 : {
540 2 : if (np != 2){
541 0 : cout << "Uniform distribution has two parameters: min and max where 0<=min<max" << endl;
542 0 : YYABORT;
543 : }
544 : double p1,p2;
545 2 : string st=Par[0];
546 2 : Evaluate.parse(st);p1=Evaluate.RealResult;
547 2 : st=Par[1];
548 2 : Evaluate.parse(st);p2=Evaluate.RealResult;
549 2 : if ((p1>=p2) || (p1<0)) {
550 0 : cout << "In uniform distribution 0 <= min< max " << endl;
551 0 : YYABORT;
552 : }
553 2 : break;
554 : }
555 :
556 : case EXPONENTIAL:
557 : {
558 0 : if (np != 1) {
559 0 : cout << "exponential distribution has one parameter: Lambda > 0, got "<< np << " parameters "<< distrib <<"[";
560 0 : for(const auto &x : Par) cout << x << ", ";
561 0 : cout << "]" << endl;
562 0 : YYABORT;
563 : }
564 :
565 : double p1;
566 0 : string st=Par[0];
567 0 : Evaluate.parse(st);p1=Evaluate.RealResult;
568 0 : if (p1<= 0 ) {
569 0 : cout << "In exponential distribution Lambda > 0" << endl;
570 0 : YYABORT;
571 : }
572 0 : break;
573 : }
574 :
575 : case DETERMINISTIC:
576 : {
577 0 : if (np != 1) {
578 0 : cout << "Deterministic distribution has one parameter: T >= 0" << endl;
579 0 : YYABORT;
580 : }
581 :
582 : double p1;
583 0 : string st=Par[0];
584 0 : Evaluate.parse(st);p1=Evaluate.RealResult;
585 0 : if (p1<0 ) {
586 0 : cout << "In Deterministic distribution Lambda > 0" << endl;
587 0 : YYABORT;
588 : }
589 0 : break;
590 : }
591 :
592 : case LOGNORMAL:
593 : {
594 0 : if (np != 2) {
595 0 : cout << "Lognormal distribution has two parameters: mu and sigma^2, where mu > 0 sigma^2 > 0" << endl;
596 0 : YYABORT;
597 : }
598 :
599 : double p1,p2;
600 0 : string st=Par[0];
601 0 : Evaluate.parse(st);p1=Evaluate.RealResult;
602 0 : st=Par[1];
603 0 : Evaluate.parse(st);p2=Evaluate.RealResult;
604 0 : if ((p1<=0) || (p2<=0)) {
605 0 : cout << "In Lognormal distribution mu > 0 sigma^2 > 0" << endl;
606 0 : YYABORT;
607 : }
608 0 : break;
609 : }
610 :
611 : case TRIANGLE:
612 : {
613 0 : if (np != 3) {
614 0 : cout << "Triangle distribution has three parameters: 0 <= b <= c <= a" << endl;
615 0 : YYABORT;
616 : }
617 : double p1,p2,p3;
618 0 : string st=Par[0];
619 0 : Evaluate.parse(st);p1=Evaluate.RealResult;
620 0 : st=Par[1];
621 0 : Evaluate.parse(st);p2=Evaluate.RealResult;
622 0 : st=Par[2];
623 0 : Evaluate.parse(st);p3=Evaluate.RealResult;
624 0 : if ((p1<0) || (p2<p1) || (p3<p2)) {
625 0 : cout << "In Triangle distribution: 0 <= b <= c<= a" << endl;
626 0 : YYABORT;
627 : }
628 :
629 :
630 0 : break;
631 : }
632 :
633 : case GEOMETRIC:
634 : {
635 0 : if (np != 2) {
636 0 : cout << "Geometric distribution has two parameters: 0 <= p <= 1 (probability of success) and T > 0 (duration of one step)" << endl;
637 0 : YYABORT;
638 : }
639 : double p1,p2;
640 0 : string st=Par[0];
641 0 : Evaluate.parse(st);p1=Evaluate.RealResult;
642 0 : st=Par[1];
643 0 : Evaluate.parse(st);p2=Evaluate.RealResult;
644 0 : if ((p1<0) || (p1>1) || p2<=0) {
645 0 : cout << "In Geometric distribution 0 <= p <= 1 (probability of success) and T > 0 (duration of one step)" << endl;
646 0 : YYABORT;
647 : }
648 0 : break;
649 : }
650 : case ERLANG:
651 : {
652 0 : if (np != 2) {
653 0 : cout << "Erlang distribution has two parameters: Shape and Rate, where Shape is a positive integer and Rate > 0" << endl;
654 0 : YYABORT;
655 : }
656 :
657 :
658 0 : string st=Par[0];
659 0 : Evaluate.parse(st);
660 0 : if(Evaluate.RealResult != Evaluate.IntResult || Evaluate.IntResult < 1){
661 0 : cout << "In Erlang distribution Shape is a positive integer" << endl;
662 0 : YYABORT;
663 : }
664 :
665 0 : st=Par[1];
666 0 : Evaluate.parse(st);
667 0 : if (Evaluate.RealResult<=0) {
668 0 : cout << "In Erlang distribution Rate > 0" << endl;
669 0 : YYABORT;
670 : }
671 0 : break;
672 : }
673 : case GAMMA:
674 : {
675 0 : if (np != 2) {
676 0 : cout << "Gamma distribution has two parameters: Shape>0 and Scale>0" << endl;
677 0 : YYABORT;
678 : }
679 :
680 :
681 0 : string st=Par[0];
682 0 : Evaluate.parse(st);
683 0 : if(Evaluate.RealResult<=0){
684 0 : cout << "In Gamma distribution Shape > 0" << endl;
685 0 : YYABORT;
686 : }
687 :
688 0 : st=Par[1];
689 0 : Evaluate.parse(st);
690 0 : if (Evaluate.RealResult<=0) {
691 0 : cout << "In Gamma distribution Scale > 0" << endl;
692 0 : YYABORT;
693 : }
694 0 : break;
695 : }
696 :
697 :
698 0 : default: cout << "\nUnknown distribution !" << endl;
699 0 : YYABORT;
700 :
701 : }
702 : };
703 :
704 :
705 :
706 : params:param
707 : |params COMMA param;
708 :
709 :
710 :
711 8 : param:RealStringFormula {string st=$1;
712 4 : if(Evaluate.parse(st))
713 0 : {cout<<"The exponential distribution is the only marking dependent distribution: '"<<st<<"'"<<endl;YYABORT; }
714 8 : else{std::ostringstream s;s<<Evaluate.RealResult;
715 4 : Par.push_back(s.str());
716 : }
717 : };
718 :
719 :
720 : InArcs: in EQ '{' incells '}' SEMICOLON {};
721 :
722 : incells: incell {}
723 : |incells incell {};
724 :
725 : incell: LB str COMMA str COMMA IntStringFormula RB SEMICOLON {
726 85 : if(Reader.spn->PlacesId.find(*$2)==Reader.spn->PlacesId.end())
727 : {
728 0 : std::cout<<"Place: "<<*$2<<" was not declared"<<std::endl;
729 0 : YYABORT;
730 : }
731 85 : if(Reader.spn->TransList.find(*$4)==Reader.spn->TransList.end())
732 : {
733 0 : std::cout<<"Transition: "<<*$4<<" was not declared"<<std::endl;
734 0 : YYABORT;
735 : }
736 170 : string st=$6;
737 :
738 85 : if(Evaluate.parse(st)){
739 0 : Reader.spn->inArcsStruct.insert(make_pair<pair<size_t,size_t>,arc>(Reader.spn->arckey(Reader.spn->TransId[*$4],Reader.spn->PlacesId[*$2]), arc(st)));
740 85 : }else Reader.spn->inArcsStruct.insert(make_pair<pair<size_t,size_t>,arc>(Reader.spn->arckey(Reader.spn->TransId[*$4],Reader.spn->PlacesId[*$2]),arc(Evaluate.IntResult)));
741 :
742 : }
743 : |LB str COMMA str RB SEMICOLON {
744 1 : if(Reader.spn->PlacesId.find(*$2)==Reader.spn->PlacesId.end())
745 : {
746 0 : std::cout<<"Place: "<<*$2<<" was not declared"<<std::endl;
747 0 : YYABORT;
748 : }
749 1 : if(Reader.spn->TransList.find(*$4)==Reader.spn->TransList.end())
750 : {
751 0 : std::cout<<"Transition: "<<*$4<<" was not declared"<<std::endl;
752 0 : YYABORT;
753 : }
754 1 : Reader.spn->inArcsStruct.insert(make_pair<pair<size_t,size_t>,arc>(Reader.spn->arckey(Reader.spn->TransId[*$4],Reader.spn->PlacesId[*$2]),arc(1)));
755 :
756 : };
757 :
758 : OutArcs: out EQ '{' outcells '}' SEMICOLON {};
759 :
760 : outcells: outcell {}
761 : |outcells outcell {};
762 :
763 : outcell: LB str COMMA str COMMA IntStringFormula RB SEMICOLON {
764 85 : if(Reader.spn->TransList.find(*$2)==Reader.spn->TransList.end())
765 : {
766 0 : std::cout<<"Transition: "<<*$2<<" was not declared"<<std::endl;
767 0 : YYABORT;
768 : }
769 85 : if(Reader.spn->PlacesId.find(*$4)==Reader.spn->PlacesId.end())
770 : {
771 0 : std::cout<<"Place: "<<*$4<<" was not declared"<<std::endl;
772 0 : YYABORT;
773 : }
774 170 : string st=$6;
775 :
776 85 : if(Evaluate.parse(st)){
777 0 : Reader.spn->outArcsStruct.insert(make_pair<pair<size_t,size_t>,arc>(Reader.spn->arckey(Reader.spn->TransId[*$2],Reader.spn->PlacesId[*$4]),arc(st)));
778 : }
779 85 : else Reader.spn->outArcsStruct.insert(make_pair<pair<size_t,size_t>,arc>(Reader.spn->arckey(Reader.spn->TransId[*$2],Reader.spn->PlacesId[*$4]),arc(Evaluate.IntResult)));
780 :
781 : }
782 : |LB str COMMA str RB SEMICOLON {
783 1 : if(Reader.spn->TransList.find(*$2)==Reader.spn->TransList.end())
784 : {
785 0 : std::cout<<"Transition: "<<*$2<<" was not declared"<<std::endl;
786 0 : YYABORT;
787 : }
788 1 : if(Reader.spn->PlacesId.find(*$4)==Reader.spn->PlacesId.end())
789 : {
790 0 : std::cout<<"Place: "<<*$4<<" was not declared"<<std::endl;
791 0 : YYABORT;
792 : }
793 1 : Reader.spn->outArcsStruct.insert(make_pair<pair<size_t,size_t>,arc>(Reader.spn->arckey(Reader.spn->TransId[*$2],Reader.spn->PlacesId[*$4]),arc(1)));
794 : };
795 :
796 :
797 :
798 : Inhibitors: inhibitor EQ '{' inhibcells '}' SEMICOLON {};
799 :
800 : inhibcells: inhibcell {}
801 : |inhibcells inhibcell {};
802 :
803 : inhibcell: LB str COMMA str COMMA IntStringFormula RB SEMICOLON {
804 0 : if(Reader.spn->PlacesId.find(*$2)==Reader.spn->PlacesId.end())
805 : {
806 0 : std::cout<<"Place: "<<*$2<<" was not declared"<<std::endl;
807 0 : YYABORT;
808 : }
809 0 : if(Reader.spn->TransList.find(*$4)==Reader.spn->TransList.end())
810 : {
811 0 : std::cout<<"Transition: "<<*$4<<" was not declared"<<std::endl;
812 0 : YYABORT;
813 : }
814 0 : string st=$6;
815 :
816 0 : if(Evaluate.parse(st)){
817 0 : Reader.spn->inhibArcsStruct.insert(make_pair<pair<size_t,size_t>,arc>(Reader.spn->arckey(Reader.spn->TransId[*$4],Reader.spn->PlacesId[*$2]),arc(st)));
818 : }
819 0 : else Reader.spn->inhibArcsStruct.insert(make_pair<pair<size_t,size_t>,arc>(Reader.spn->arckey(Reader.spn->TransId[*$4],Reader.spn->PlacesId[*$2]),arc(Evaluate.IntResult)));
820 :
821 : }
822 :
823 : |LB str COMMA str RB SEMICOLON {
824 0 : if(Reader.spn->PlacesId.find(*$2)==Reader.spn->PlacesId.end())
825 : {
826 0 : std::cout<<"Place: "<<*$2<<" was not declared"<<std::endl;
827 0 : YYABORT;
828 : }
829 0 : if(Reader.spn->TransList.find(*$4)==Reader.spn->TransList.end())
830 : {
831 0 : std::cout<<"Transition: "<<*$4<<" was not declared"<<std::endl;
832 0 : YYABORT;
833 : }
834 0 : Reader.spn->inhibArcsStruct.insert(make_pair<pair<size_t,size_t>,arc>(Reader.spn->arckey(Reader.spn->TransId[*$4],Reader.spn->PlacesId[*$2]),arc(1)));
835 :
836 : };
837 :
838 :
839 :
840 : redifinitions: TransitionsDef;
841 :
842 : %%
843 :
844 : void
845 0 : gspn::Gspn_parser::error (const gspn::Gspn_parser::location_type& l,
846 : const std::string& m)
847 : {
848 0 : Reader.error (l, m);
849 105 : }
|