int main(int argc, char* argv[]) { if (argc != 4) { printHelp(argv); return 1; } // QUADRATURE RULE if (strlen(argv[1]) > 1) { printHelp(argv); return 2; } QuadratureFactory* factory = createFactory(argv[1][0]); // FUNCTION TO BE USED/TESTED int functionIndex = atoi(argv[2]); if (functionIndex == 0) { printHelp(argv); return 3; } fptr func = chooseFunc(functionIndex); // INTEGRATION GRID IntegrationGrid grid = createGrid(argv[3]); //grid.print(); CompositeIntegrator integrator(func, factory, grid); printf("performing integration\n"); integrator.integrate(); printf("result of integrating function %d = %5.3lf\n", functionIndex, integrator.getResult()); return 0; }
int main(int argc, char* argv[]) { double a = 0; double b = 2; if (argc != 3 && argc != 5) { printHelp(argv); return 1; } if (strlen(argv[1]) > 1) { printHelp(argv); return 2; } char method = argv[1][0]; int functionIndex = atoi(argv[2]); if (functionIndex == 0) { printHelp(argv); return 3; } if (argc == 5) { a = atof(argv[3]); b = atof(argv[4]); if (b <= a) { printHelp(argv); return 4; } } fptr func = chooseFunc(functionIndex); QuadratureRule* integrator = createMethod(method, func, a, b); printf("performing integration\n"); integrator->integrate(); printf("result of integrating function %d in interval [%5.3lf, %5.3lf] = %5.3lf\n", functionIndex, a, b, integrator->getResult()); return 0; }
void FormModifyWeight::mtcKeyPressed(MtcKeyPressedEvent *mtcKeyEvent) { switch(m_nEditStatus) { case esInit: chooseFunc(mtcKeyEvent); break; case esWeight: inputWeight(mtcKeyEvent); break; case esAxisNo: inputAxisNo(mtcKeyEvent); break; case esAxisCount: inputAxisCount(mtcKeyEvent); break; default: break; } mtcKeyEvent->setKeyType(KC_Func); }
float build_in_func::doFunction(char *pFuncName, float *pArgs, int iArgsNum) { int iChosenIndex = chooseFunc(pFuncName); switch (iChosenIndex) { case 0: if (iFuncArgsNum[iChosenIndex] != iArgsNum) throw ArgsNumError; return abs(pArgs[0]); case 1: if (iFuncArgsNum[iChosenIndex] != iArgsNum) throw ArgsNumError; return power(pArgs[0], floatToInt(pArgs[1])); case 2: if (iFuncArgsNum[iChosenIndex] != iArgsNum) throw ArgsNumError; show(pArgs[0]); return 0; default: // Case when we not found any build in function with such name throw BuildInFuncExistanceError; break; } }
bool parserLL1()/***语法分析主函数,返回真假值表示是否出现了语法错误***/ { /***init***/ if(!isInitFuncs) { initParserLL1Funcs(); isInitFuncs=true; } deleteParserLL1Tree(); expflag=0; getExpResult2=false; getExpResult=true; savePtr=NULL; errors.clear(); CreatLL1Table(); symbolStack.clear(); operatorStack.clear(); numStack.clear(); syntaxStack.clear(); productsSequence.clear(); symbolStack.push_back(Symbol::Program); rt=new TreeNode(0,NodeKinds::ProK);///根节点 for(int i=2; i>=0; i--) syntaxStack.push_back(&(rt->son[i])); /***init***/ ReadOneToken(currentToken); while(!symbolStack.empty()) { if(isTerminalSymbol(symbolStack.back()))///终极符 { if(currentToken.type==symbolStack.back()) { symbolStack.pop_back(); #ifdef LL1CURTERMINALSYMBOL /**输出调试信息**/ printf(">>>>>> Pop Terminal Symbol %s\n",currentToken.name.c_str()); #endif // LL1CURTERMINALSYMBOL ReadOneToken(currentToken); } else { sprintf(strError,"syntax error : unexpected tokentype= '%s' name= %s found at line %d,\n\ expected Token type is %s.\n", getTokenStr(currentToken.type).c_str(),currentToken.name.c_str(), currentToken.lineNum,getTokenStr(symbolStack.back()).c_str()); insertError(strError); #ifdef LL1OUTSYMBOLSTACK /**输出调试信息**/ puts("Rest Symbol in Stack is:"); for(Symbol tmp:symbolStack) printf("%-8s ",getTokenStr(tmp).c_str()); puts(""); #endif // LL1OUTSYMBOLSTACK return false; } } else///非终极符 { int pnum=LL1Table[int(symbolStack.back())][int(currentToken.type)];///取得对应的产生式 printf("LL1 List %s %s \n",getTokenStr(symbolStack.back()).c_str(),getTokenStr(currentToken.type).c_str()); Symbol tsym=symbolStack.back(); symbolStack.pop_back(); if(!chooseFunc(pnum))///没有对应的产生式 { printf("ok shit???????????"); sprintf(strError,"syntax error : unexpected tokentype= '%s' name= %s found at line %d.\n maybe missed one of these: %s", getTokenStr(currentToken.type).c_str(),currentToken.name.c_str(), currentToken.lineNum,getPredictStr(tsym).c_str()); insertError(strError); return false; } } } if(currentToken.type!=TokenType::DOT)/***匹配结束符 . ***/ { sprintf(strError,"syntax error : unexpected token found at line %d,Expected Dot\n",currentToken.lineNum); insertError(strError); return false; } else if(!ReadOneToken(currentToken))/***有结束符 . 则读入下一个TOKEN EOF***/ { sprintf(strError,"syntax error : Token ends Before Code or File end\n"); insertError(strError); return false; } if(currentToken.type==TokenType::ENDFILE) return true; else { sprintf(strError,"syntax error : unexpected token '%s' found at line %d,Expected EOF\n" ,getTokenStr(currentToken.type).c_str(),currentToken.lineNum); insertError(strError); return false; } return errors.size()==0; }