本文整理汇总了C++中Symbol::addArgument方法的典型用法代码示例。如果您正苦于以下问题:C++ Symbol::addArgument方法的具体用法?C++ Symbol::addArgument怎么用?C++ Symbol::addArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symbol
的用法示例。
在下文中一共展示了Symbol::addArgument方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addRelation
void SymbolTable::addRelation(const RelationNode *relationNode) {
const std::vector<Token> arguments = relationNode->getArguments();
for (const Token &token : arguments) {
if (token.getType() != TOKENIZER_TOKEN_TYPE_TERM) {
throw Exception("Unexpected type in relation node");
}
}
std::string name = relationNode->getName();
STable::iterator it = table.find(name);
Symbol *symbol;
if (it == table.end()) {
symbol = new Symbol(name, SYMBOL_TYPE_RELATION, relationNode->getArguments().size());
std::pair<std::string, Symbol*> entry(name, symbol);
table.insert(entry);
} else {
symbol = it->second;
if (symbol->getNumOfArgument() != relationNode->getArguments().size()) {
throw Exception("Different number of argument in same relation: " + name);
}
}
for (size_t i = 0; i < relationNode->getArguments().size(); ++i) {
symbol->addArgument(i, relationNode->getArguments()[i].getTokenStr());
}
}
示例2: addProposition
void SymbolTable::addProposition(const PropositionNode *propositionNode, bool isRule) {
std::string name = propositionNode->getName();
STable::iterator it = table.find(name);
Symbol *symbol;
if (it != table.end()) {
symbol = it->second;
if (symbol->getType() == SYMBOL_TYPE_RELATION) {
if (isRule) {
throw Exception("Relation cannot be in the head of if node: " + name);
} else {
return;
}
} else if (symbol->getType() == SYMBOL_TYPE_PROPOSITION && isRule) {
symbol->setType(SYMBOL_TYPE_RULE);
}
if (symbol->getNumOfArgument() != propositionNode->getArguments().size()) {
throw Exception(std::string("Different number of arguments in same") + std::string(((isRule) ? "rule" : "proposition")) + std::string(": ") + name);
}
} else {
symbol = new Symbol(name, ((isRule) ? SYMBOL_TYPE_RULE : SYMBOL_TYPE_PROPOSITION), propositionNode->getArguments().size());
std::pair<std::string, Symbol*> entry(name, symbol);
table.insert(entry);
}
for (size_t i = 0; i < propositionNode->getArguments().size(); ++i) {
if (propositionNode->getArguments()[i].getType() == TOKENIZER_TOKEN_TYPE_TERM) {
std::string argument = propositionNode->getArguments()[i].getTokenStr();
if (!argumentExists(symbol->getArgumentDomain(i), argument)) {
symbol->addArgument(i, argument);
}
}
}
}
示例3: addAction
void SymbolTable::addAction(const PropositionNode *action) {
std::string name = action->getName();
STable::iterator it = table.find(name);
Symbol *symbol;
if (it != table.end()) {
symbol = it->second;
if (symbol->getType() != SYMBOL_TYPE_ACTION) {
throw Exception("Action is already in the table with differnet type: " + name);
}
if (symbol->getNumOfArgument() != action->getArguments().size()) {
throw Exception("Different number of arguments in same action: " + name);
}
} else {
symbol = new Symbol(name, SYMBOL_TYPE_ACTION, action->getArguments().size());
std::pair<std::string, Symbol*> entry(name, symbol);
table.insert(entry);
}
for (size_t i = 0; i < action->getArguments().size(); ++i) {
if (action->getArguments()[i].getType() == TOKENIZER_TOKEN_TYPE_TERM) {
std::string argument = action->getArguments()[i].getTokenStr();
if (!argumentExists(symbol->getArgumentDomain(i), argument)) {
symbol->addArgument(i, argument);
}
}
}
}