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


C++ ListIterator::token方法代码示例

本文整理汇总了C++中ListIterator::token方法的典型用法代码示例。如果您正苦于以下问题:C++ ListIterator::token方法的具体用法?C++ ListIterator::token怎么用?C++ ListIterator::token使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ListIterator的用法示例。


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

示例1: doSum

void doSum(ListIterator &i, TokenList *pf)
{
  char oper;       // For holding the operator


  doProduct(i, pf); // Sum = product + product


  if(!i.ended())
    oper = i.token().tokenChar(); // Grab an operator, only if current != NULL
    
  while(((oper == '+') || (oper == '-')) && !i.ended() ) 
    {
      i.advance(); // Move to next token, an int or a '('
      doProduct(i, pf); 
    
      Token t(oper);
      pf->push_back(t); // Add the operator the the expression
      
      if(!i.ended())
	oper = i.token().tokenChar(); // Grab the next operator
	
    }

}
开发者ID:ghortiz-pena,项目名称:CS-122,代码行数:25,代码来源:evaluate.cpp

示例2: doAssign

void doAssign(ListIterator &i, ExprNode *&node)
{
  ExprNode *left, *right;
  string eq;
  ListIterator temp = i;

  node = new Variable(i.token().tokenChar());
  if(!i.ended())
    i.advance();
  if(!i.ended())
    eq = i.token().tokenChar();
    
  if(eq == "=" && !i.ended())
    {
      while(eq == "=" && !i.ended())
	{
	  if(!i.ended())
	    i.advance();
	  if(!i.ended())
	    doSum(i, right);
	  node = new Operation(node, eq, right);
	  if(!i.ended())
	    eq = i.token().tokenChar();
	  else
	    eq = "Done";
	}
    }
  else if(!i.ended() && (i.token().tokenChar() != "("))
    i = temp;
  else if(!i.ended() && (i.token().tokenChar() == "("))
    {
      i = temp;
      doCall(i, node);
    }
}
开发者ID:ghortiz-pena,项目名称:CS-122,代码行数:35,代码来源:evaluate.cpp

示例3: evaluate

int evaluate(const char str[], VarTree &vars, FunctionDef &fmap)
{
  TokenList l(str); // Declare and construct our linked list
  ExprNode *root;
  static int ans = 0;   // For handling previous answers
  
  ListIterator i = l.begin();
  
  if((!i.token().isInteger()) && (i.token().isOperator())) 
    { 
      Token newHead(ans);
      l.push_front(newHead);
      i = l.begin();
    }

  
  if(i.token().tokenChar() == "deffn")
    {
      doDefine(i, fmap);
      root = new Value(0);
    }
  else
    doCompare(i, root);          // Here begins the Conversion
  
  cout << *root << endl;
  
  return root->evaluate(vars, fmap);
}
开发者ID:ghortiz-pena,项目名称:CS-122,代码行数:28,代码来源:evaluate.cpp

示例4: doCall

void doCall(ListIterator &i, ExprNode *&node)
{
  string name;
  ExprNode *parameters[10];
  int p = 0;

  if(!i.ended())
    name = i.token().tokenChar();
  i.advance();
    if(!i.ended())
    doCompare(i, node);
  parameters[p] = node;
  p++;
  if(!i.ended()){
    while(!i.ended() && i.token().tokenChar() != ")")
      {
	if(!i.ended())
	  doCompare(i, node);
	parameters[p] = node;
	p++;
      }
  }

  for(; p < 10; p++)
    parameters[p] = NULL;
  node = new Function(name, parameters);
}
开发者ID:ghortiz-pena,项目名称:CS-122,代码行数:27,代码来源:evaluate.cpp

示例5: addOp

//This function takes in the iterator, and rewrite both sides of the sum expression in postFix
//Pre- The position is at a symbol +,-,*,/,%
//Post- It will change postFix and the iterator
void addOp(ListIterator &iter, TokenList &postFix)
{
	int pos;
	Token saveToken;
	bool solved = false;

	while(solved == false)
	{
		if (iter.tokenChar() == '*' || iter.tokenChar() == '/' || iter.tokenChar() == '%')
		{
			//This means that a product operation was encountered immediately so the prgoram can finish the expression and return without
			multOp(iter, postFix);
		}
		else if (iter.tokenChar() == '+' || iter.tokenChar() == '-')
		{
			//We advance to save the next number and then again to check the next character
			saveToken = iter.token();
			iter.advance();
			getValue(iter, postFix);
			iter.advance();
			if (iter.tokenChar() == '*' || iter.tokenChar() == '/' || iter.tokenChar() == '%')
			{
				//If a product expression is found it will calculate the entirety of that
				multOp(iter, postFix);
			}
			postFix.push_back(saveToken);
		}
		else
		{
			solved = true;
		}
	}
}
开发者ID:Benderx,项目名称:scriptinglanguage,代码行数:36,代码来源:evaluate.cpp

示例6: tokenText

string tokenText(ListIterator& infix, TokenList& list)
{
    if (infix != list.end())
        return infix.token().tokenText();
    else
        return "";
}
开发者ID:evan1026,项目名称:CMPSC122---Homeworks,代码行数:7,代码来源:compile.cpp

示例7:

//  output operation
//  Display all of the tokens in the list
ostream& operator<<( ostream &stream, TokenList &t )
{
    for (ListIterator iter = t.begin(); iter != t.end(); iter.advance())
    {
	stream << iter.token() << " ";
    }
    return stream;
}
开发者ID:caschoener,项目名称:RISC,代码行数:10,代码来源:tokenlist.cpp

示例8: doCompare

void doCompare(ListIterator &i, ExprNode *&test)
{
  ExprNode *trueCase, *falseCase, *right;
  string comp;

  doSum(i, test);
  if(!i.ended())
    {
      if(i.token().tokenChar() == ")")
	i.advance();
    }
  if(!i.ended() && i.token().isOperator())
    {
      comp = i.token().tokenChar(); 
      i.advance();
      doSum(i, right);
      test = new Operation(test, comp, right);
    }
  if(!i.ended() && (i.token().tokenChar() == "?" || i.token().isOperator()))
    {
      i.advance();
      doSum(i, trueCase);
    }
  if(!i.ended() && (i.token().isOperator() || i.token().tokenChar() == ":"))
    {
      i.advance();
      doSum(i, falseCase);
      test = new Conditional(test, trueCase, falseCase);
    }

}
开发者ID:ghortiz-pena,项目名称:CS-122,代码行数:31,代码来源:evaluate.cpp

示例9: handleMultiplyLevelOperation

// handleMultiplyLevelOperation
// Handles *, /, and %
// Parameters:
//     iter  - the iterator for the list of tokens
//     postExpr - the postfix expression we are converting to
// Pre-condition:  iter.tokenChar() == '*' or '/' or '%'
// Post-condition: iter.tokenChar() == end of what was multiplied (last int/parenthesis)
//                 postExpr has both operands and the operator pushed to it
void handleMultiplyLevelOperation(ListIterator& iter, TokenList& postExpr)
{
    Token operation(iter.token());
    iter.advance();

    getValue(iter, postExpr, false); //Do not handle multiplication (see getValue())

    postExpr.push_back(operation);
}
开发者ID:evan1026,项目名称:CMPSC122---Homeworks,代码行数:17,代码来源:evaluate.cpp

示例10: handleAdditionLevelOperation

// handleMultiplyLevelOperation
// Handles + and -
// Parameters:
//     iter  - the iterator for the list of tokens
//     postExpr - the postfix expression we are converting to
// Pre-condition:  iter.tokenChar() == '+' or '-'
// Post-condition: iter.tokenChar() == end of what was added (last int/parenthesis)
//                 postExpr has both operands and the operator pushed to it
void handleAdditionLevelOperation(ListIterator& iter, TokenList& postExpr)
{
    Token operation(iter.token());
    iter.advance();

    getValue(iter, postExpr, true); //Do evaluate multiplication (see getValue())

    postExpr.push_back(operation);
}
开发者ID:evan1026,项目名称:CMPSC122---Homeworks,代码行数:17,代码来源:evaluate.cpp

示例11: doDefine

void doDefine(ListIterator &i, FunctionDef &fmap)
{
  string n;
  string parameters[10];
  ExprNode *body;
  int p = 0;

  i.advance(); // i is now on the function name

  if(!i.ended())
    n = i.token().tokenChar(); 


  i.advance(); // i is now on open paren of parameters
  i.advance(); // i is now on the first parameter
  if(!i.ended())
    parameters[p] = i.token().tokenChar();
  p++;
  i.advance(); // i is now on comma separating parameters or close paren
  while(i.token().tokenChar() == "," && !i.ended())
    {
      i.advance(); // i is now on next parameter
      if(!i.ended())
	parameters[p] = i.token().tokenChar();
      p++;
      i.advance(); // i is on new comma or close paren
    }
  i.advance(); // i is now on "="
  i.advance();
  
  if(!i.ended())
    doCompare(i, body);

  fmap[n].name = n;
  for(int i = 0; i < p; i++)
    {
      fmap[n].parameter[i] = parameters[i];
    }
  fmap[n].functionBody = body;
  fmap[n].locals = new VarTree();

  cout << *fmap[n].functionBody << endl;
  
}
开发者ID:ghortiz-pena,项目名称:CS-122,代码行数:44,代码来源:evaluate.cpp

示例12: doProduct

void doProduct(ListIterator & i, ExprNode *&node)
{
  ExprNode *left, *right;
  string oper;

  doFactor(i, node);

  if(!i.ended())
    oper = i.token().tokenChar(); 
  while(oper == "*" || oper == "/" || oper == "%")
    {
      i.advance();
      doFactor(i, right);
      node = new Operation(node, oper, right);
      if(!i.ended())
	oper = i.token().tokenChar();
      else
	oper = "Done";
    }
}
开发者ID:ghortiz-pena,项目名称:CS-122,代码行数:20,代码来源:evaluate.cpp

示例13: doFactor

void doFactor(ListIterator &i, TokenList *pf) // Grabs a factor; evaluates if needed; return
{
  int left;
  // factor = int || factor = (int + int)

  if(i.token().tokenChar() == '(')
    {
      i.advance();     
      doSum(i, pf); 
    }
  else
    {
      left = i.token().integerValue(); // grab the factor
      Token t(left);
      pf->push_back(t);    // add it to the list
    }
  if(!i.ended())
    i.advance();

}
开发者ID:ghortiz-pena,项目名称:CS-122,代码行数:20,代码来源:evaluate.cpp

示例14: multOp

//This function takes in the iterator, and the TokeList, and will rewrite any product expressions
//Pre- The position will be on a operation symbol that is either *, /, %
//Post- It will rewrite the infix to postFix product expression
void multOp(ListIterator &iter, TokenList &postFix)
{
	Token saveToken;

	//This loop will run indefinately and rewrite to postFix until the product expression ends
	while (iter.tokenChar() == '*' || iter.tokenChar() == '/' || iter.tokenChar() == '%')
	{
		saveToken = iter.token();
		iter.advance();

		getValue(iter, postFix);
		iter.advance();

		postFix.push_back(saveToken);
	}
}
开发者ID:Benderx,项目名称:scriptinglanguage,代码行数:19,代码来源:evaluate.cpp

示例15: getValue

//The function takes in an iterator and TokenList and will rewrite numbers at the iterator's
//Pre- The position is located at a number or a parethesis
//Post- It will write to the postFix TokenList and update the iterator
void getValue(ListIterator &iter, TokenList &postFix)
{
	//If parethesis are found this else if will rewrite the parenthesis in postFix
	if (iter.tokenChar() == '(')
	{
		iter.advance();
		getValue(iter, postFix);
		iter.advance();
		assignOp(iter, postFix);
	}
	//If the current position is an integer
	else
	{
		postFix.push_back(iter.token());
	}
}
开发者ID:Benderx,项目名称:scriptinglanguage,代码行数:19,代码来源:evaluate.cpp


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