-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrule.cc
71 lines (61 loc) · 1.05 KB
/
rule.cc
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
# include <rule.h>
# include <iostream>
Rule::Rule()
{
length =0;
}
void Rule::addSymbol(Symbol *s)
{
data.push_back(s);
length++;
}
int Rule::getSymbolPos(string s)
{
for(int i=0;i<length;i++)
if(data[i]->getName()==s) return i;
return -1;
}
Symbol *Rule::getSymbol(int pos) const
{
if(pos<0 || pos>=length) return NULL;
return data[pos];
}
void Rule::setSymbol(int pos,Symbol *s)
{
if(pos<0 || pos>=length) return;
data[pos]=s;
}
int Rule::getLength() const
{
return length;
}
string Rule::printRule(vector<int> genome,int &pos,int &redo)
{
string str="";
string str2="";
Rule *r;
int old_pos;
for(int i=0;i<length;i++)
{
Symbol *s=data[i];
if(s->getTerminalStatus())
{
str=str+s->getName();
}
else
{
if(pos>=genome.size()) {redo++;pos=0;}
if(pos<0 || s==NULL) {redo=REDO_MAX+100;return str;}
r=s->getRule((genome[pos]%s->getCountRules()));
pos++;
if(pos>=genome.size()) {redo++;pos=0;}
if(redo>=REDO_MAX) return str;
str2=r->printRule(genome,pos,redo);
str=str+str2;
}
}
return str;
}
Rule::~Rule()
{
}