forked from TUfischl/newdetkdecomp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.cpp
821 lines (662 loc) · 20.3 KB
/
Parser.cpp
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
// Parser.cpp: implementation of the Parser class.
//
//////////////////////////////////////////////////////////////////////
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdlib>
#include <cstring>
#include "Parser.h"
#include "Globals.h"
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Parser::Parser(bool bDef)
{
cMyBuffer[0] = '\0';
iMyBufferPos = 0;
iMyLineNumber = 1;
iMyColumnNumber = 0;
iMyEndOfAtoms = 0;
iMyNbrOfWarnings = 0;
bMyEOF = false;
bMyDef = bDef;
}
Parser::~Parser()
{
int iDefAtom = 0, iDefVar = 0;
vector<set<int> *>::iterator sVectorIter;
vector<bool>::iterator bVectorIter;
for (sVectorIter=MyAtomVars.begin(); sVectorIter != MyAtomVars.end(); sVectorIter++)
delete *sVectorIter;
for (sVectorIter=MyAtomNeighbours.begin(); sVectorIter != MyAtomNeighbours.end(); sVectorIter++)
delete *sVectorIter;
for (sVectorIter=MyVarAtoms.begin(); sVectorIter != MyVarAtoms.end(); sVectorIter++)
delete *sVectorIter;
for (sVectorIter=MyVarNeighbours.begin(); sVectorIter != MyVarNeighbours.end(); sVectorIter++)
delete *sVectorIter;
for (bVectorIter=MyDefAtomUsed.begin(); bVectorIter != MyDefAtomUsed.end(); bVectorIter++, iDefAtom++)
if (!*bVectorIter)
delete MyDefAtoms[iDefAtom];
for (bVectorIter=MyDefVarUsed.begin(); bVectorIter != MyDefVarUsed.end(); bVectorIter++, iDefVar++)
if (!*bVectorIter)
delete MyDefVariables[iDefVar];
}
//////////////////////////////////////////////////////////////////////
// Class methods
//////////////////////////////////////////////////////////////////////
void Parser::SyntaxError(const char *cMsg, bool bLineNbr)
{
if (bLineNbr)
cerr << "Error in Ln " << iMyLineNumber << ", Col " << iMyColumnNumber << ": " << cMsg << endl;
else
cerr << "Error: " << cMsg << endl;
exit(EXIT_FAILURE);
}
void Parser::SyntaxWarning(const char *cMsg, bool bLineNbr)
{
if (bLineNbr)
cerr << "Warning in Ln " << iMyLineNumber << ", Col " << iMyColumnNumber << ": " << cMsg << endl;
else
cerr << "Warning: " << cMsg << endl;
++iMyNbrOfWarnings;
}
void Parser::fillBuffer()
{
if (!MyFile.eof()) {
// Reinitialize buffer; this is necessary because of the 'read'-method
for(int i=0; i < IF_BUFFER_SIZE; i++)
cMyBuffer[i] = '\0';
MyFile.read(cMyBuffer, IF_BUFFER_SIZE);
iMyBufferPos = 0;
}
else {
bMyEOF = true;
// If end-token was not found yet
if (iMyEndOfAtoms == 0)
SyntaxError("Unexpected end of file.", true);
}
}
void Parser::readIgnoreText()
{
bool bEndIgnore = false;
do {
switch (cMyBuffer[iMyBufferPos]) {
case '\0': // End of buffer reached -> refill
fillBuffer();
break;
case ' ': // Ignore spaces
++iMyBufferPos;
++iMyColumnNumber;
break;
case 9: // Ignore tabulators
++iMyBufferPos;
++iMyColumnNumber;
while(iMyColumnNumber%8 != 1)
++iMyColumnNumber;
break;
case '\n': // Ignore newlines
++iMyBufferPos;
++iMyLineNumber;
iMyColumnNumber = 1;
break;
case '%': // Ignore comments
do {
++iMyBufferPos;
++iMyColumnNumber;
if (cMyBuffer[iMyBufferPos] == '\0') // End of buffer reached -> refill
fillBuffer();
} while ((cMyBuffer[iMyBufferPos] != '\n') && !bMyEOF);
// Until newline or end of file
break;
default:
bEndIgnore = true;
}
} while (!bEndIgnore && !bMyEOF);
}
char *Parser::readIdentifier()
{
bool bEndIdentifier = false;
char cIdentBuffer[MAX_IDENTIFIER_SIZE + 1], *cIdentifier = NULL;
int iIdentifierSize = 0;
readIgnoreText();
do {
if (cMyBuffer[iMyBufferPos] == '\0') // End of buffer reached -> refill
fillBuffer();
else {
if (((cMyBuffer[iMyBufferPos] >= 'A') && (cMyBuffer[iMyBufferPos] <= 'Z')) ||
((cMyBuffer[iMyBufferPos] >= 'a') && (cMyBuffer[iMyBufferPos] <= 'z')) ||
((cMyBuffer[iMyBufferPos] >= '0') && (cMyBuffer[iMyBufferPos] <= '9')) ||
(cMyBuffer[iMyBufferPos] == '_') || (cMyBuffer[iMyBufferPos] == ':')) {
// Copy identifier from input file in temporary identifier buffer
cIdentBuffer[iIdentifierSize++] = cMyBuffer[iMyBufferPos++];
++iMyColumnNumber;
if (iIdentifierSize > MAX_IDENTIFIER_SIZE)
SyntaxError("Maximum length of identifier exceeded.", true);
}
else
bEndIdentifier = true;
}
} while (!bEndIdentifier);
// Until character was found that is not allowed in an identifier
cIdentBuffer[iIdentifierSize] = '\0';
if(iIdentifierSize == 0)
SyntaxError("Illegal or missing identifier.", true);
// Allocate character array for identifier and copy identifier from the identifier buffer in this array
cIdentifier = new char[iIdentifierSize + 1];
if (cIdentifier == NULL)
writeErrorMsg("Error assigning memory.", "Parser::readIdentifier");
return strcpy(cIdentifier, cIdentBuffer);
}
bool Parser::readIdentifier(const char *cIdent)
{
int i = 0;
readIgnoreText();
while (cIdent[i] != '\0') {
if (cMyBuffer[iMyBufferPos] == '\0') // End of buffer reached -> refill
fillBuffer();
if (cMyBuffer[iMyBufferPos] != cIdent[i++])
return false;
++iMyBufferPos;
++iMyColumnNumber;
}
return true;
}
int Parser::readArity()
{
bool bEndArity = false;
int iArity = 0, iNbrOfDigits = 0;
readIgnoreText();
do {
if (cMyBuffer[iMyBufferPos] == '\0') // End of buffer reached -> refill
fillBuffer();
else {
if ((cMyBuffer[iMyBufferPos] >= '0') && (cMyBuffer[iMyBufferPos] <= '9')) {
iArity *= 10;
iArity += (int)cMyBuffer[iMyBufferPos]-48;
++iMyBufferPos;
++iMyColumnNumber;
++iNbrOfDigits;
// Maximum number of digits is restricted to 4 (Arity: 1 - 9999)
if (iNbrOfDigits == 4)
bEndArity = true;
}
else
bEndArity = true;
}
} while (!bEndArity);
// Until a non-numerical character was found or the maximum number of digits was exceeded
if(iArity == 0)
SyntaxError("Illegal arity number.", true);
return iArity;
}
void Parser::readVarDefs()
{
char *cIdentifier = NULL, cErrorMsg[MAX_IDENTIFIER_SIZE + 32];
vector<char *>::iterator VectorIter;
do {
cIdentifier = readIdentifier();
// Check whether the variable is already defined
VectorIter = MyDefVariables.begin();
while ((VectorIter != MyDefVariables.end()) && (strcmp(*VectorIter, cIdentifier) != 0))
++VectorIter;
// If the variable is not defined yet
if (VectorIter == MyDefVariables.end()) {
// Store the variable identifier
MyDefVariables.push_back(cIdentifier);
// Initialize usage of the variable
MyDefVarUsed.push_back(false);
}
else {
strcpy(cErrorMsg, "Variable \"");
strcat(cErrorMsg, cIdentifier);
strcat(cErrorMsg, "\" is already defined.");
SyntaxError(cErrorMsg, true);
}
} while (readSeparator());
}
void Parser::readAtomDefs()
{
char *cIdentifier = NULL, cErrorMsg[MAX_IDENTIFIER_SIZE + 32];
vector<char *>::iterator VectorIter;
do {
cIdentifier = readIdentifier();
// Check whether the atom is already defined
VectorIter = MyDefAtoms.begin();
while ((VectorIter != MyDefAtoms.end()) && (strcmp(*VectorIter, cIdentifier) != 0))
++VectorIter;
// If the atom is not defined yet
if (VectorIter == MyDefAtoms.end())
// Store the variable identifier
MyDefAtoms.push_back(cIdentifier);
else {
strcpy(cErrorMsg, "Atom \"");
strcat(cErrorMsg, cIdentifier);
strcat(cErrorMsg, "\" is already defined.");
SyntaxError(cErrorMsg, true);
}
// Read separator between atom identifier and arity
readIgnoreText();
if(!readIdentifier("/"))
SyntaxError("Illegal character.", true);
// Read arity of the actual atom
MyArities.push_back(readArity());
// Initialize usage of the atom
MyDefAtomUsed.push_back(false);
} while (readSeparator());
}
bool Parser::readOpenDef()
{
return readIdentifier("<");
}
void Parser::readCloseDef()
{
if(!readIdentifier(">"))
SyntaxError("Illegal character.", true);
}
void Parser::readOpenBody()
{
if(!readIdentifier("("))
SyntaxError("Illegal character.", true);
}
void Parser::readCloseBody()
{
if(!readIdentifier(")"))
SyntaxError("Illegal character.", true);
}
bool Parser::readSeparator()
{
return readIdentifier(",");
}
void Parser::readEnd()
{
if(readIdentifier("."))
// Remember the line number where the end-token was found for error messages
iMyEndOfAtoms = iMyLineNumber;
else
SyntaxError("Illegal character.", true);
}
void Parser::readDefinitions()
{
bool bVarDef, bAtomDef;
// While a definition block '<...>' can be found
while(readOpenDef()) {
bVarDef = bAtomDef = false;
if(readIdentifier("def")) {
if(readIdentifier("Var")) // Read "defVar" identifier
bVarDef = true;
else
if(readIdentifier("Rel")) // Read "defRel" identifier
bAtomDef = true;
else
SyntaxError("Unknown identifier.", true);
}
else
SyntaxError("Unknown identifier.", true);
readIgnoreText();
// Check whether the definition identifier is followed by a colon
if(!readIdentifier(":"))
SyntaxError("Illegal character.", true);
if(bVarDef)
readVarDefs(); // Read variable definitions
else
if(bAtomDef)
readAtomDefs(); // Read relation definitions
readCloseDef();
}
}
void Parser::readAtom()
{
char *cIdentifier = NULL;
vector<char *>::iterator VectorIter;
set<int> *Set = NULL;
char cErrorMsg[MAX_IDENTIFIER_SIZE + 64];
int iDefAtom = 0, iArity = 0;
cIdentifier = readIdentifier();
// Check if the same atom identifier was already used before
for (VectorIter=MyAtoms.begin(); VectorIter != MyAtoms.end(); VectorIter++)
if (strcmp(*VectorIter, cIdentifier) == 0) {
strcpy(cErrorMsg, "Atom identifier \"");
strcat(cErrorMsg, cIdentifier);
strcat(cErrorMsg, "\" occurs the second time.");
SyntaxError(cErrorMsg, true);
}
if (bMyDef) {
// Check whether the atom is defined
VectorIter=MyDefAtoms.begin();
while ((VectorIter != MyDefAtoms.end()) && (strcmp(*VectorIter, cIdentifier) != 0)) {
++VectorIter;
++iDefAtom;
}
// If the atom is not defined
if (VectorIter == MyDefAtoms.end()) {
strcpy(cErrorMsg, "Undefined atom \"");
strcat(cErrorMsg, cIdentifier);
strcat(cErrorMsg, "\".");
SyntaxError(cErrorMsg, true);
}
// Update atom usage
MyDefAtomUsed[iDefAtom] = true;
// Store the atom identifier
MyAtoms.push_back(MyDefAtoms[iDefAtom]);
delete cIdentifier;
}
else
// Store the atom identifier
MyAtoms.push_back(cIdentifier);
// Allocate a set of variables for the atom
Set = new set<int>;
if (Set == NULL)
writeErrorMsg("Error assigning memory.", "Parser::readAtom");
MyAtomVars.push_back(Set);
// Allocate a set of neighbours for the atom
Set = new set<int>;
if (Set == NULL)
writeErrorMsg("Error assigning memory.", "Parser::readAtom");
MyAtomNeighbours.push_back(Set);
// Read the atom body
readOpenBody();
do {
readVariable();
++iArity;
} while (readSeparator());
readCloseBody();
// Check whether the number of arguments equals the defined arity
if (bMyDef && (MyArities[iDefAtom] != iArity))
SyntaxError("Illegal number of arguments.", true);
}
void Parser::readVariable()
{
int iVar, iDefVar, iAtom;
char *cIdentifier = NULL;
vector<char *>::iterator VectorIter;
set<int>::iterator SetIter;
set<int> *Set = NULL;
pair<set<int>::iterator, bool> SetInsertRet;
char cErrorMsg[(2*MAX_IDENTIFIER_SIZE) + 64];
iAtom = (int)MyAtoms.size()-1;
cIdentifier = readIdentifier();
// Check if the same variable was already used before
iVar = iDefVar = 0;
VectorIter = MyVariables.begin();
while ((VectorIter != MyVariables.end()) && (strcmp(*VectorIter, cIdentifier) != 0)) {
++VectorIter;
++iVar;
}
// If the variable did not occur previously
if (VectorIter == MyVariables.end()) {
if (bMyDef) {
// Check whether the variable is defined
VectorIter = MyDefVariables.begin();
while ((VectorIter != MyDefVariables.end()) && (strcmp(*VectorIter, cIdentifier) != 0)) {
++VectorIter;
++iDefVar;
}
// If the variable is not defined
if (VectorIter == MyDefVariables.end()) {
strcpy(cErrorMsg, "Undefined variable \"");
strcat(cErrorMsg, cIdentifier);
strcat(cErrorMsg, "\".");
SyntaxError(cErrorMsg, true);
}
// Update variable usage
MyDefVarUsed[iDefVar] = true;
// Store the variable identifier
MyVariables.push_back(MyDefVariables[iDefVar]);
delete cIdentifier;
}
else
// Store the variable identifier
MyVariables.push_back(cIdentifier);
// Allocate a set of atoms for the variable
Set = new set<int>;
if (Set == NULL)
writeErrorMsg("Error assigning memory.", "Parser::readVariable");
MyVarAtoms.push_back(Set);
// Allocate a set of neighbours for the variable
Set = new set<int>;
if (Set == NULL)
writeErrorMsg("Error assigning memory.", "Parser::readVariable");
MyVarNeighbours.push_back(Set);
}
// Add variable to the set of variables of the actual atom
SetInsertRet = MyAtomVars[iAtom]->insert(iVar);
// Write syntax warning if the variable occurs multiple times in the actual atom
if (SetInsertRet.second == false) {
strcpy(cErrorMsg, "Multiple occurrences of variable \"");
strcat(cErrorMsg, cIdentifier);
strcat(cErrorMsg, "\" in atom \"");
strcat(cErrorMsg, MyAtoms.back());
strcat(cErrorMsg, "\".");
SyntaxWarning(cErrorMsg, true);
}
// Update the neighbourhood relation between the actual atom and the atoms already stored before
for (SetIter=MyVarAtoms[iVar]->begin(); SetIter != MyVarAtoms[iVar]->end(); SetIter++)
if (*SetIter != iAtom) {
MyAtomNeighbours[*SetIter]->insert(iAtom);
MyAtomNeighbours[iAtom]->insert(*SetIter);
}
// Update the neighbourhood relation between the actual variable and the variables already stored before
for (SetIter=MyAtomVars[iAtom]->begin(); SetIter != MyAtomVars[iAtom]->end(); SetIter++)
if (*SetIter != iVar) {
MyVarNeighbours[*SetIter]->insert(iVar);
MyVarNeighbours[iVar]->insert(*SetIter);
}
// Add actual atom to the set of atoms of the variable
MyVarAtoms[iVar]->insert(iAtom);
}
void Parser::parseFile(const char *cNameOfFile)
{
int iDefVar = 0, iDefAtom = 0;
char cErrorMsg[96], cLineNumber[(sizeof(int)*8)+1];
vector<bool>::iterator bVectorIter;
vector<char *>::iterator cVectorIter;
// Open input file stream
MyFile.open(cNameOfFile, ios::in);
// Check if file opening was successful
if(!MyFile.is_open())
SyntaxError("Error opening file.");
// Read definitions of variables and relations
readDefinitions();
// Delete all definition informations
if (!bMyDef) {
for (cVectorIter=MyDefAtoms.begin(); cVectorIter != MyDefAtoms.end(); cVectorIter++)
delete *cVectorIter;
for (cVectorIter=MyDefVariables.begin(); cVectorIter != MyDefVariables.end(); cVectorIter++)
delete *cVectorIter;
MyDefAtoms.clear();
MyDefVariables.clear();
MyArities.clear();
MyDefAtomUsed.clear();
MyDefVarUsed.clear();
}
// Read atoms until the separator cannot be found
do {
readAtom();
} while(readSeparator());
// Read the end-token
readEnd();
// Read the text after the end-token
readIgnoreText();
// Close input file stream
MyFile.close();
// Write syntax warning if EOF does not appear during reading the ignore text, i.e., there appears
// some text after the end-token was found
if(!bMyEOF) {
strcpy(cErrorMsg, "Illegal character after termination symbol \".\" in line ");
strcat(cErrorMsg, uitoa(iMyEndOfAtoms, cLineNumber));
strcat(cErrorMsg, ".");
SyntaxWarning(cErrorMsg, true);
}
if (bMyDef) {
// Write a syntax warning if a defined atom was not used
for (bVectorIter = MyDefAtomUsed.begin(); bVectorIter != MyDefAtomUsed.end(); bVectorIter++, iDefAtom++)
if (!*bVectorIter) {
strcpy(cErrorMsg, "Atom \"");
strcat(cErrorMsg, MyDefAtoms[iDefAtom]);
strcat(cErrorMsg, "\" is not used.");
SyntaxWarning(cErrorMsg);
}
// Write a syntax warning if a defined variable was not used
for (bVectorIter = MyDefVarUsed.begin(); bVectorIter != MyDefVarUsed.end(); bVectorIter++, iDefVar++)
if (!*bVectorIter) {
strcpy(cErrorMsg, "Variable \"");
strcat(cErrorMsg, MyDefVariables[iDefVar]);
strcat(cErrorMsg, "\" is not used.");
SyntaxWarning(cErrorMsg);
}
}
}
int Parser::getNbrOfAtoms() const
{
return (int)MyAtoms.size();
}
int Parser::getNbrOfVars() const
{
return (int)MyVariables.size();
}
int Parser::getNbrOfVars(int iAtom) const
{
if (iAtom >= (int)MyAtomVars.size()) {
writeErrorMsg("Position not available.", "Parser::getNbrOfVars");
return 0;
}
else
return (int)MyAtomVars[iAtom]->size();
}
int Parser::getNbrOfAtoms(int iVar) const
{
if (iVar >= (int)MyVarAtoms.size()) {
writeErrorMsg("Position not available.", "Parser::getNbrOfAtoms");
return 0;
}
else
return (int)MyVarAtoms[iVar]->size();
}
int Parser::getNbrOfAtomNeighbours(int iAtom) const
{
if (iAtom >= (int)MyAtomNeighbours.size()) {
writeErrorMsg("Position not available.", "Parser::getNbrOfAtomNeighbours");
return 0;
}
else
return (int)MyAtomNeighbours[iAtom]->size();
}
int Parser::getNbrOfVarNeighbours(int iVar) const
{
if (iVar >= (int)MyVarNeighbours.size()) {
writeErrorMsg("Position not available.", "Parser::getNbrOfVarNeighbours");
return 0;
}
else
return (int)MyVarNeighbours[iVar]->size();
}
int Parser::getNbrOfWarnings() const
{
return iMyNbrOfWarnings;
}
char *Parser::getAtom(int iAtom) const
{
if (iAtom >= (int)MyAtoms.size()) {
writeErrorMsg("Position not available.", "Parser::getAtom");
return NULL;
}
else
return MyAtoms[iAtom];
}
char *Parser::getVariable(int iVar) const
{
if (iVar >= (int)MyVariables.size()) {
writeErrorMsg("Position not available.", "Parser::getVariable");
return NULL;
}
else
return MyVariables[iVar];
}
int Parser::getNextAtomVar(bool bReset)
{
static vector<set<int> *>::iterator VectorIter;
static set<int>::iterator SetIter;
static bool bFirstCall = true;
// Initialize resp. reset the iterator
if(bFirstCall || bReset) {
VectorIter = MyAtomVars.begin();
if(VectorIter == MyAtomVars.end())
writeErrorMsg("Position not available.", "Parser::getNextAtomVar");
SetIter = (*VectorIter)->begin();
bFirstCall = false;
}
else
++SetIter; // Increment the iterator
while(SetIter == (*VectorIter)->end()) {
if(++VectorIter == MyAtomVars.end())
writeErrorMsg("Position not available.", "Parser::getNextAtomVar");
SetIter = (*VectorIter)->begin();
}
return *SetIter; // Return the next neighbour index
}
int Parser::getNextVarAtom(bool bReset)
{
static vector<set<int> *>::iterator VectorIter;
static set<int>::iterator SetIter;
static bool bFirstCall = true;
// Initialize resp. reset the iterator
if(bFirstCall || bReset) {
VectorIter = MyVarAtoms.begin();
if(VectorIter == MyVarAtoms.end())
writeErrorMsg("Position not available.", "Parser::getNextVarAtom");
SetIter = (*VectorIter)->begin();
bFirstCall = false;
}
else
++SetIter; // Increment the iterator
while(SetIter == (*VectorIter)->end()) {
if(++VectorIter == MyVarAtoms.end())
writeErrorMsg("Position not available.", "Parser::getNextVarAtom");
SetIter = (*VectorIter)->begin();
}
return *SetIter; // Return the next neighbour index
}
int Parser::getNextAtomNeighbour(bool bReset)
{
static vector<set<int> *>::iterator VectorIter;
static set<int>::iterator SetIter;
static bool bFirstCall = true;
// Initialize resp. reset the iterator
if(bFirstCall || bReset) {
VectorIter = MyAtomNeighbours.begin();
if(VectorIter == MyAtomNeighbours.end())
writeErrorMsg("Position not available.", "Parser::getNextAtomNeighbour");
SetIter = (*VectorIter)->begin();
bFirstCall = false;
}
else
++SetIter; // Increment the iterator
while(SetIter == (*VectorIter)->end()) {
if(++VectorIter == MyAtomNeighbours.end())
writeErrorMsg("Position not available.", "Parser::getNextAtomNeighbour");
SetIter = (*VectorIter)->begin();
}
return *SetIter; // Return the next neighbour index
}
int Parser::getNextVarNeighbour(bool bReset)
{
static vector<set<int> *>::iterator VectorIter;
static set<int>::iterator SetIter;
static bool bFirstCall = true;
// Initialize resp. reset the iterator
if(bFirstCall || bReset) {
VectorIter = MyVarNeighbours.begin();
if(VectorIter == MyVarNeighbours.end())
writeErrorMsg("Position not available.", "Parser::getNextVarNeighbour");
SetIter = (*VectorIter)->begin();
bFirstCall = false;
}
else
++SetIter; // Increment the iterator
while(SetIter == (*VectorIter)->end()) {
if(++VectorIter == MyVarNeighbours.end())
writeErrorMsg("Position not available.", "Parser::getNextVarNeighbour");
SetIter = (*VectorIter)->begin();
}
return *SetIter; // Return the next neighbour index
}