/// <summary>
        /// Gets the command for the function called in the specified source tree.
        /// </summary>
        /// <param name="source">The source Antlr tree representing a function call..</param>
        /// <returns>The parsed AstFunctionNode.</returns>
        /// <exception cref="NoViableAltException"><c>NoViableAltException</c>.</exception>
        private static PostfixMathCommand GetCommandForOperator( ITree source )
        {
            PostfixMathCommand command;
            switch ( source.Type )
            {
                case TokenTypes.OP_ADD:
                    command = new Add();
                    break;

                case TokenTypes.OP_SUBTRACT:
                    command = new Subtract();
                    break;

                case TokenTypes.OP_MULTIPLY:
                    command = new Multiply();
                    break;

                case TokenTypes.OP_DIVIDE:
                    command = new Divide();
                    break;

                default:
                    throw new NoViableAltException();
            }
            return command;
        }
Пример #2
0
 /// <summary>
 /// Static function to create a default FunctionSet. This may be called by any
 /// object at any time if it needs the standard functions.
 /// </summary>
 internal static FunctionSet GetDefaultFunctionSet()
 {
     var fs = new FunctionSet();
     fs["+"] = new Add();
     fs["-"] = new Subtract();
     fs["*"] = new Multiply();
     fs["/"] = new Divide();
     fs["="] = new Comparator( ComparatorType.EQ );
     fs["=="] = new Comparator( ComparatorType.EQ );
     fs["<"] = new Comparator( ComparatorType.LT );
     fs["<="] = new Comparator( ComparatorType.LE );
     fs[">"] = new Comparator( ComparatorType.GT );
     fs[">="] = new Comparator( ComparatorType.GE );
     fs["!="] = new Comparator( ComparatorType.NE );
     fs["<>"] = new Comparator( ComparatorType.NE );
     fs["and"] = new And();
     fs["or"] = new Or();
     fs["not"] = new Not();
     fs["if"] = new Conditional();
     fs["round"] = new Round();
     fs["floor"] = new Floor();
     fs["sum"] = new Sum();
     fs["min"] = new Min();
     fs["max"] = new Max();
     fs["avg"] = new Average();
     fs["count"] = new Count();
     return fs;
 }