当前位置: 首页>>代码示例>>C++>>正文


C++ Factor函数代码示例

本文整理汇总了C++中Factor函数的典型用法代码示例。如果您正苦于以下问题:C++ Factor函数的具体用法?C++ Factor怎么用?C++ Factor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Factor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Factor

Node* Parser::Term()
{
	Node* pNode = Factor();
	EToken token = _scanner.Token();
	if (token == tMult || token == tDivide)
	{
		MultiNode* pMultiNode = new ProductNode(pNode);
		do
		{
			_scanner.Accept();
			Node* pRight = Factor();
			pMultiNode->AddChild (pRight, (token == tMult));
			token = _scanner.Token();
		}while (token == tMult || token == tDivide);
		pNode = pMultiNode;
	}
	return pNode;
	/*
	if (_scanner.Token() == tMult )
	{
		_scanner.Accept();
		Node* pRight = Term();
		pNode = new MultNode(pNode,pRight);
	}
	else if(_scanner.Token() == tDivide)
	{
		_scanner.Accept();
		Node* pRight = Term();
		pNode = new DivideNode (pNode, pRight );
	}
	return pNode;
	*/
}
开发者ID:Accordeur,项目名称:Calc,代码行数:33,代码来源:Parser.cpp

示例2: TermPrime

void TermPrime(void)
{
   switch (Symb.type) {
   case TIMES:
      /* T' -> * F BinOp T' */
      Symb = readLexem();
      Factor();
      Gener(BinOp, '*');      /* BinOp.dop = '*' */
      TermPrime();
      break;
   case DIVIDE:
      /* T' -> / F BinOp T' */
      Symb = readLexem();
      Factor();
      Gener(BinOp, '/');      /* BinOp.dop = '/' */
      TermPrime();
      break;
   case PLUS:
   case MINUS:
   case RPAR:
   case EOI:
      /* T' -> e */
      break;
   default:
      ExpansionError("T'", Symb.type);
   }
}
开发者ID:kkthx,项目名称:bi-pjp-sfe,代码行数:27,代码来源:parser.c

示例3: Item

//16.<项>—> <因子> [ *|/  <因子> ]
Val Item(){
	Val v1 = Factor();

	while (lookahead == mutiply || lookahead == div){
		int op = lookahead;
		if (op == mutiply) match(mutiply);
		else match(div);
		Val v2 = Factor();


		quadruples.push_back(Quadruple(sno++, op == mutiply ? mutiply : div, v1, v2, temp));
		//生成四元式
		/*printf("%3d (%c,", sno++, op == mutiply ? '*' : '/');
		
		if (v1.type == 1) printf("%s", GetNameByID(v1.value1));
		else if (v1.type == 0)  printf("%d", v1.value1);
		else if (v1.type == 2) printf("%lf", v1.value2);
		else printf("t%d", v1.value1);
		printf(",");
		if (v2.type == 1) printf("%s", GetNameByID(v2.value1));
		else if (v2.type == 0) printf("%d", v2.value1);
		else if (v2.type == 2) printf("%lf", v2.value2);
		else printf("t%d", v2.value1);
		printf(",t%d)\n", temp);*/

		v1.type = -1;
		v1.value1 = temp++;

	}
	return v1;
}
开发者ID:SherryPan123,项目名称:Compiler,代码行数:32,代码来源:语法分析.cpp

示例4: Term

result Term() {
    result lhs = Factor(), rhs;
    token op;
    if(lhs.error !=  ERR_NONE) {
        return lhs;
    }
    for(op = next_token(); op.type == TT_ASTERISK || op.type == TT_SLASH; op = next_token() ) { 
        rhs = Factor();
#ifdef DEBUG_1
        print_result("Term:lhs:", lhs);
        printf("Term:op:%d\n", op.type);
        print_result("Term:rhs:", rhs);
#endif
        if(rhs.error != ERR_NONE) {
            return rhs;
        }
        if(op.type == TT_ASTERISK) {
            lhs.value *= rhs.value;
        }
        else if(op.type == TT_SLASH) {
            if(rhs.value != 0) {
                lhs.value /= rhs.value;
            }
            else {
                return make_result(ERR_DIVISION_BY_ZERO, 0); 
            }
        }
        else {
            return make_result(ERR_UNEXPECTED_TOKEN, 0);
        }
    }
    rollback();
    return make_result(ERR_NONE, lhs.value);
}
开发者ID:melentyev,项目名称:spbu-homework,代码行数:34,代码来源:expressinons.c

示例5: switch

 void Polynomial<Degree>::getSolutions(const double& c,std::vector<double>& roots,const double& EPS) const {
   double r[4][2];
   int rCount=0;
   roots.clear();
   switch(Degree){
     case 1:
       rCount=Factor(coefficients[1],coefficients[0]-c,r,EPS);
       break;
     case 2:
       rCount=Factor(coefficients[2],coefficients[1],coefficients[0]-c,r,EPS);
       break;
     case 3:
       rCount=Factor(coefficients[3],coefficients[2],coefficients[1],coefficients[0]-c,r,EPS);
       break;
       //	case 4:
       //		rCount=Factor(coefficients[4],coefficients[3],coefficients[2],coefficients[1],coefficients[0]-c,r,EPS);
       //		break;
     default:
       printf("Can't solve polynomial of degree: %d\n",Degree);
   }
   for(int i=0;i<rCount;i++){
     if(fabs(r[i][1])<=EPS){
       roots.push_back(r[i][0]);
       //printf("%d] %f\t%f\n",i,r[i][0],(*this)(r[i][0])-c);
     }
   }
 }
开发者ID:hitsjt,项目名称:StanfordPCL,代码行数:27,代码来源:polynomial.hpp

示例6: Factor

void HAK::construct() {
    // Create outer beliefs
    if( props.verbose >= 3 )
        cerr << "Constructing outer beliefs" << endl;
    _Qa.clear();
    _Qa.reserve(nrORs());
    for( size_t alpha = 0; alpha < nrORs(); alpha++ )
        _Qa.push_back( Factor( OR(alpha) ) );

    // Create inner beliefs
    if( props.verbose >= 3 )
        cerr << "Constructing inner beliefs" << endl;
    _Qb.clear();
    _Qb.reserve(nrIRs());
    for( size_t beta = 0; beta < nrIRs(); beta++ )
        _Qb.push_back( Factor( IR(beta) ) );

    // Create messages
    if( props.verbose >= 3 )
        cerr << "Constructing messages" << endl;
    _muab.clear();
    _muab.reserve( nrORs() );
    _muba.clear();
    _muba.reserve( nrORs() );
    for( size_t alpha = 0; alpha < nrORs(); alpha++ ) {
        _muab.push_back( vector<Factor>() );
        _muba.push_back( vector<Factor>() );
        _muab[alpha].reserve( nbOR(alpha).size() );
        _muba[alpha].reserve( nbOR(alpha).size() );
        foreach( const Neighbor &beta, nbOR(alpha) ) {
            _muab[alpha].push_back( Factor( IR(beta) ) );
            _muba[alpha].push_back( Factor( IR(beta) ) );
        }
    }
开发者ID:Nick11,项目名称:V3DSfMToolkit,代码行数:34,代码来源:hak.cpp

示例7: print

bool syntaxparser::TermPrime(){
	bool bTermPrime = false;
	if (lexeme == "*"){
		print();
		cout<<endl;
		Lexer();
		if(displayFlag){
			cout << "<TermPrime> ::= *<Factor><TermPrime>" << endl;
			printproduction("<TermPrime> ::= *<Factor><TermPrime>");
		}
		Factor();
		project3.gen_inst("MUL","-999");

		string type1, type2;

			type1 = project3.returnSymbolType(2);
			type2 = project3.returnSymbolType(3);

			if(type1 == "boolean")
				error("Cannot perform '*' on boolean");
			if (type2 == "boolean")
				error("Cannot perform '*' on boolean");

		TermPrime();	
		bTermPrime = true;		
	}
	else if (lexeme == "/"){
		print();
		cout<<endl;
		Lexer();
		if(displayFlag){
			cout << "<TermPrime> ::= /<Term><FactorPrime>" << endl;
			printproduction("<TermPrime> ::= /<Term><FactorPrime>");
		}
		bTermPrime = true;
		Factor();
		project3.gen_inst("DIV", "-999");

		string type1, type2;

			type1 = project3.returnSymbolType(2);
			type2 = project3.returnSymbolType(3);

			if(type1 == "boolean")
				error("Cannot perform '/' on boolean");
			if (type2 == "boolean")
				error("Cannot perform '/' on boolean");

		TermPrime();
	}
	else{
		bTermPrime = true;
		if(displayFlag){
			cout << "<TermPrime> ::= epsilon" << endl;
			printproduction("<TermPrime> ::= epsilon");
		}
	}
	return bTermPrime;
}
开发者ID:fullerton323,项目名称:compiler,代码行数:59,代码来源:syntaxparser.cpp

示例8: Factor

// Solution taken from: http://mathworld.wolfram.com/QuarticEquation.html
// and http://www.csit.fsu.edu/~burkardt/f_src/subpak/subpak.f90
int Factor(double a4,double a3,double a2,double a1,double a0,double roots[4][2],const double& EPS){
	double R[2],D[2],E[2],R2[2];

	if(fabs(a4)<EPS){return Factor(a3,a2,a1,a0,roots,EPS);}
	a3/=a4;
	a2/=a4;
	a1/=a4;
	a0/=a4;

	Factor(1.0,-a2,a3*a1-4.0*a0,-a3*a3*a0+4.0*a2*a0-a1*a1,roots,EPS);

	R2[0]=a3*a3/4.0-a2+roots[0][0];
	R2[1]=0;
	Sqrt(R2,R);
	if(fabs(R[0])>10e-8){
		double temp1[2],temp2[2];
		double p1[2],p2[2];

		p1[0]=a3*a3*0.75-2.0*a2-R2[0];
		p1[1]=0;

		temp2[0]=((4.0*a3*a2-8.0*a1-a3*a3*a3)/4.0);
		temp2[1]=0;
		Divide(temp2,R,p2);

		Add     (p1,p2,temp1);
		Subtract(p1,p2,temp2);

		Sqrt(temp1,D);
		Sqrt(temp2,E);
	}
	else{
		R[0]=R[1]=0;
		double temp1[2],temp2[2];
		temp1[0]=roots[0][0]*roots[0][0]-4.0*a0;
		temp1[1]=0;
		Sqrt(temp1,temp2);
		temp1[0]=a3*a3*0.75-2.0*a2+2.0*temp2[0];
		temp1[1]=                  2.0*temp2[1];
		Sqrt(temp1,D);
		temp1[0]=a3*a3*0.75-2.0*a2-2.0*temp2[0];
		temp1[1]=                 -2.0*temp2[1];
		Sqrt(temp1,E);
	}

	roots[0][0]=-a3/4.0+R[0]/2.0+D[0]/2.0;
	roots[0][1]=        R[1]/2.0+D[1]/2.0;

	roots[1][0]=-a3/4.0+R[0]/2.0-D[0]/2.0;
	roots[1][1]=        R[1]/2.0-D[1]/2.0;

	roots[2][0]=-a3/4.0-R[0]/2.0+E[0]/2.0;
	roots[2][1]=       -R[1]/2.0+E[1]/2.0;

	roots[3][0]=-a3/4.0-R[0]/2.0-E[0]/2.0;
	roots[3][1]=       -R[1]/2.0-E[1]/2.0;
	return 4;
}
开发者ID:Benzlxs,项目名称:PRSM,代码行数:60,代码来源:Factor.cpp

示例9: Term

void Term()
{
	Factor();
	while(!strcmp(string[TokenCounter],"*"))
	{
		MulOp();
		Factor();
	}
}
开发者ID:fadyfares7,项目名称:TinyLanguage_Scanner_And_Parser-,代码行数:9,代码来源:parser.c

示例10: Factor

Factor LC::belief (const VarSet &ns) const {
    if( ns.size() == 0 )
        return Factor();
    else if( ns.size() == 1 )
        return beliefV( findVar( *(ns.begin()) ) );
    else {
        DAI_THROW(BELIEF_NOT_AVAILABLE);
        return Factor();
    }
}
开发者ID:afbarnard,项目名称:libdai,代码行数:10,代码来源:lc.cpp

示例11: Factor

void Parser::Term(int &type) {
    int type1, op;
    Factor(type);
    while (la->kind == 7 || la->kind == 8) {
        MulOp(op);
        Factor(type1);
        if (type != integer || type1 != integer)
            Err(L"integer type expected");
        gen->Emit(op);
    }
}
开发者ID:Newky,项目名称:3rdYear,代码行数:11,代码来源:Parser.cpp

示例12: FirstFactor

void FirstFactor() {
  switch(Look) {
    case '+': 
      Match('+');
      Factor();
      break;
    case '-':
      NegFactor();
      break;
    default: Factor();
  }
}
开发者ID:A-deLuna,项目名称:crenshaw-c-x86_64-compiler,代码行数:12,代码来源:main.c

示例13: Weight

// This code has been copied from bp.cpp, except where comments indicate TRWBP-specific behaviour
Prob TRWBP::calcIncomingMessageProduct( size_t I, bool without_i, size_t i ) const {
    Real c_I = Weight(I); // TRWBP: c_I

    Factor Fprod( factor(I) );
    Prob &prod = Fprod.p();
    if( props.logdomain ) {
        prod.takeLog();
        prod /= c_I; // TRWBP
    } else
        prod ^= (1.0 / c_I); // TRWBP

    // Calculate product of incoming messages and factor I
    bforeach( const Neighbor &j, nbF(I) )
        if( !(without_i && (j == i)) ) {
            const Var &v_j = var(j);
            // prod_j will be the product of messages coming into j
            // TRWBP: corresponds to messages n_jI
            Prob prod_j( v_j.states(), props.logdomain ? 0.0 : 1.0 );
            bforeach( const Neighbor &J, nbV(j) ) {
                Real c_J = Weight(J);  // TRWBP
                if( J != I ) { // for all J in nb(j) \ I
                    if( props.logdomain )
                        prod_j += message( j, J.iter ) * c_J;
                    else
                        prod_j *= message( j, J.iter ) ^ c_J;
                } else if( c_J != 1.0 ) { // TRWBP: multiply by m_Ij^(c_I-1)
                    if( props.logdomain )
                        prod_j += message( j, J.iter ) * (c_J - 1.0);
                    else
                        prod_j *= message( j, J.iter ) ^ (c_J - 1.0);
                }
            }

            // multiply prod with prod_j
            if( !DAI_TRWBP_FAST ) {
                // UNOPTIMIZED (SIMPLE TO READ, BUT SLOW) VERSION
                if( props.logdomain )
                    Fprod += Factor( v_j, prod_j );
                else
                    Fprod *= Factor( v_j, prod_j );
            } else {
                // OPTIMIZED VERSION
                size_t _I = j.dual;
                // ind is the precalculated IndexFor(j,I) i.e. to x_I == k corresponds x_j == ind[k]
                const ind_t &ind = index(j, _I);

                for( size_t r = 0; r < prod.size(); ++r )
                    if( props.logdomain )
                        prod.set( r, prod[r] + prod_j[ind[r]] );
                    else
                        prod.set( r, prod[r] * prod_j[ind[r]] );
            }
        }
开发者ID:DerThorsten,项目名称:libdai,代码行数:54,代码来源:trwbp.cpp

示例14: switch

Expr *TermPrimed(Expr *du)
{
   switch (Symb.type) {
   case TIMES:
      Symb = readLexem();
      return TermPrimed(new Bop(Times, du, Factor()));
   case DIVIDE:
      Symb = readLexem();
      return ExpressionPrimed(new Bop(Divide, du, Factor()));
   default:
      return du;
   }
}
开发者ID:kkthx,项目名称:bi-pjp-sfe,代码行数:13,代码来源:parser.cpp

示例15: Factor

void CParser::Term2()
{
	Factor();
	while (true)
	{
		switch (mLookahead)
		{
			case RAISE: Match(RAISE); Factor(); AddToken(opRaise); break;
			case '^': Match('^'); Factor(); AddToken(opRaise); break;
			default: return;
		}
	}
} // CParser::Term2
开发者ID:ModeenF,项目名称:OpenSumIt,代码行数:13,代码来源:parser.cpp


注:本文中的Factor函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。