本文整理汇总了C++中table::find方法的典型用法代码示例。如果您正苦于以下问题:C++ table::find方法的具体用法?C++ table::find怎么用?C++ table::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类table
的用法示例。
在下文中一共展示了table::find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: push
void push(table& t, string key, int val)
{
if (t.find(key) == t.end())
t[key] = vector<int>();
t[key].push_back(val);
}
示例2: main
int main() {
int P, i, j, prev, next;
char X;
string right;
bool complete = false;
// read in the CFG
ifstream fin("CFG.txt");
fin >> P;
for(i=0; i<P; i++) {
fin >> X >> right;
// if the first symbol on the right side of a production is a terminal,
// include it in the FIRST set of the variable on the left side of the production.
if(islower(right[0]))
FIRST[X - 'A'] |= 1 << (right[0] - 'a');
else if(productions.find(X) != productions.end())
productions[X].push_back(right);
else {
vector <string> vec;
vec.push_back(right);
productions[X] = vec;
}
}
fin.close();
// iterate until no more elements can be added to FIRST set of any variable
while(!complete) {
complete = true;
for(table::iterator it=productions.begin(); it != productions.end(); it++) {
prev = next = FIRST[it->first - 'A'];
for(vector<string>::iterator jt=(it->second).begin(); jt != (it->second).end(); jt++) {
for(i=0; i<jt->length(); i++) {
X = (*jt)[i];
if(islower(X)) {
next |= 1 << (X - 'a'); break;
}
if((FIRST[X - 'A'] & (1 << 'e' - 'a')) == 0) {
next |= FIRST[X - 'A']; break;
} else
next |= ~(~FIRST[X - 'A'] | (1 << 'e' - 'a'));
}
if(i == jt->length())
next |= (1 << 'e' - 'a');
}
if(prev != next) {
FIRST[it->first - 'A'] = next; complete = false;
}
}
}
// print out the FIRST set of each variable
for(i=0; i<26; i++)
if(FIRST[i]) {
printf("FIRST(%c) = { ", i + 'A');
for(j=0; j<26; j++)
if(FIRST[i] & (1 << j))
printf("%c ", j + 'a');
printf("}\n");
}
return 0;
}