Esempio n. 1
0
void parser::parse()
{
    //int counter;
    unsigned int pos;
    bool redo;
    string temp;
    items.clear();
    ops.clear();
    while(line.size())
    {
        pos = 0;
        redo = true;
        while(redo)
        {
            redo = false;
            pos = line.find_first_not_of("0123456789 ", pos);
            if(pos < string::npos)
                switch(line[pos])
                {
                    case '(' : ops.push_back(line.substr(pos,1));
                               line.erase(pos,2);
                               // counter++;
                               break;
                    case '*' :
                    case '/' :
                    case '-' :
                    case '+' : binaryOp(pos,redo);

                                break;
                    case ')' : items.push_back(line.substr(0,pos));                 // If the character is a ), push the line up to the ) (a number) onto the output stack
                               // if (counter == 0)
                               //     cout<< "Missing parenthesis." << endl;
                               // else{
                                   while( ops.back() != "(")                        // While the top of the operator stack is not (
                                   {                                                // Pop the top of the operator stack and push onto the output stack
                                       items.push_back(ops.back());                 // When the top of the stack
                                       ops.pop_back();
                                   }                                                // Once the top of the stack is (, the loop will exit
                                   ops.pop_back();                                  // Pop the ( from the stack, do not store (discard)
                                   line.erase(0,pos+1);
                                   //counter--;
                                    //}
                                break;
                    default: cout << "Illegal operation. Progam exiting." << endl; // Default is error message of none of the operator characters are found.
                               exit(1);
                }
            else
            {
                items.push_back(line);                                          // Pushes final number onto output stack
                line = "";
                //counter = 0;                                                     // Clears the line
                while ( !ops.empty() )                                          // Pops all operators off the operator stack onto the output stack
                      {
                      items.push_back(ops.back());
                      ops.pop_back();
                      }
            }
        }
    }
}
Esempio n. 2
0
template <class BinaryFunction> inline void
binaryOp(CoinPackedVector& retVal,
	 double value, const CoinPackedVectorBase& op2,
	 BinaryFunction bf)
{
   binaryOp(retVal, op2, value, bf);
}
Esempio n. 3
0
/// Return the element-wise ratio of two packed vectors
inline CoinPackedVector operator/(const CoinPackedVectorBase& op1,
				  const CoinPackedVectorBase& op2)
{
   CoinPackedVector retVal;
   retVal.setTestForDuplicateIndex(true);
   binaryOp(retVal, op1, op2, std::divides<double>());
   return retVal;
}
Esempio n. 4
0
template <class BinaryFunction> CoinPackedVector
binaryOp(const CoinPackedVectorBase& op1, const CoinPackedVectorBase& op2,
	 BinaryFunction bf)
{
   CoinPackedVector retVal;
   retVal.setTestForDuplicateIndex(true);
   binaryOp(retVal, op1, op2, bf);
   return retVal;
}