本文整理汇总了C++中tree::getVal方法的典型用法代码示例。如果您正苦于以下问题:C++ tree::getVal方法的具体用法?C++ tree::getVal怎么用?C++ tree::getVal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree
的用法示例。
在下文中一共展示了tree::getVal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evaluateOpFunc
//
//
// calculates expressions stored in a parse Tree
//
//
int evaluateOpFunc(opNode* exp, tree& symbolTable, tree& localVar, funcS& funcTable){
int rights;
int lefts ;
String s = exp->stringOp();
if(s == "NONE"){
return exp->val();
}else if(isValidVarName(s)){// if s is not an operation
if(s == "call"){
exp = exp->leftNode();
String funcName = exp->stringOp();// gets function name
param* parameter;
if(funcTable.isMember(funcName)){
parameter = funcTable.getParameters(funcName);// passing arguments
}else{
printf("WARNING: Function %s is not declared \n", funcName.c_str());
return 0;
}
int i = 0;
opNode* params = exp->leftNode();
if(params->stringOp() != "Ecall"){
while(params->stringOp() != "Ecall"){
parameter->op[i].value = evaluateOpFunc(params->rightNode(), symbolTable, localVar, funcTable);
params = params->leftNode();
i += 1;
}
}
tree* newTree = new tree;
for(int j =0; j < i ; j+=1){
newTree->insert(parameter->op[j].para, parameter->op[j].value);
}
if(funcTable.isMember(funcName)){
funcTable.addLocalVar(funcName, newTree);
evaluateFunc(funcName, symbolTable, funcTable);
return funcTable.getVal(funcName);
}else{
printf("Warning: function %s is not declared \n", funcName.c_str());
}
}
if(localVar.isMember(s)){
return localVar.getVal(s);
}else if(symbolTable.isMember(s)){
return symbolTable.getVal(s);
}
}
if(exp->leftNode()){
lefts = evaluateOpFunc(exp->leftNode(), symbolTable, localVar, funcTable);
if(s == "~" || s == "!"){return result(s, lefts, rights);}
}
if(exp->rightNode()){
rights = evaluateOpFunc(exp->rightNode(), symbolTable, localVar, funcTable);
}
return result(s,lefts,rights);
}