示例#1
0
void CodeWriter::RunList(char delimiter, const ast::NodeList& nodes) {
  CodeWriter self;

  if (nodes.size()) {
    RunButLast(delimiter, nodes);
    nodes.back()->Accept(&self);
  }
}
示例#2
0
void CodeWriter::RunButLast(char delimiter, const ast::NodeList& nodes) {
  CodeWriter self;

  if (nodes.size()) {
    for (uint i = 0; i < nodes.size() - 1; ++i) {
      nodes[i]->Accept(&self);
      get_pipe()(delimiter);
    }
  }
}
    //----------------------------------------------------------------------------
    void EvaluatorVisitor::visit( const AST::FunctionExpression* const node )
    {
        ScalarList evaluatedArgs;
        AST::NodeList params = node->getParameterList();

        for ( unsigned int i = 0; i < params.size(); ++i )
        {
            AST::INode* argNode = params[ i ];
            argNode->accept( this );
            evaluatedArgs.push_back( mBranchValue );
        }

        //process function
        mSymbolTable.evaluateFunction( mBranchValue, node->getName(), evaluatedArgs );
    }
    //----------------------------------------------------------------------------
    void EvaluatorVisitor::visit( const AST::ArithmeticExpression* const node )
    {
        AST::ArithmeticExpression::Operator op = node->getOperator();
        AST::NodeList operands = node->getOperands();
        AST::NodeList::iterator it;

        AST::ConstantExpression prevBranchValue;
        it = operands.begin();

        // evaluate first operand and set temporary branch value

        if ( it != operands.end() )
        {
            ( *it ) ->accept( this );
            ++it;
        }

        // evaluate other operands AND apply operation
        for ( ; it != operands.end(); ++it )
        {
            prevBranchValue = mBranchValue;
            ( *it ) ->accept( this );

            switch ( op )
            {

            case AST::ArithmeticExpression::ADD:
                mBranchValue = prevBranchValue + mBranchValue;
                break;

            case AST::ArithmeticExpression::SUB:
                mBranchValue = prevBranchValue - mBranchValue;
                break;

            case AST::ArithmeticExpression::MUL:
                mBranchValue = prevBranchValue * mBranchValue;
                break;

            case AST::ArithmeticExpression::DIV:
                mBranchValue = prevBranchValue / mBranchValue;
                break;

            default:
                //@todo: exception handling
                break;
            }
        }
    }