Exemplo n.º 1
0
        public Calculator()
        {
            _scanner = new Scanner();
            _scanner.AddOperators("+", "-", "*", "/", "%", "(", ")", "=", ",");

            _parser = new Parser(_scanner);
            _parser.AddFunction(GenericFunctions.TrigFunction("sin", Math.Sin));
            _parser.AddFunction(GenericFunctions.TrigFunction("cos", Math.Cos));
            _parser.AddFunction(GenericFunctions.TrigFunction("tan", Math.Tan));

            _parser.AddFunction(GenericFunctions.StandardFunction("sqrt", Math.Sqrt));
            _parser.AddFunction(GenericFunctions.StandardFunction("abs", Math.Abs));
            _parser.AddFunction(GenericFunctions.StandardFunction("log", Math.Log10));
            _parser.AddFunction(GenericFunctions.StandardFunction("ln", (Func<double, double>)Math.Log));
            _parser.AddFunction(GenericFunctions.StandardFunction("exp", Math.Exp));

            _parser.AddFunction(GenericFunctions.InverseTrigFunction("asin", Math.Asin));
            _parser.AddFunction(GenericFunctions.InverseTrigFunction("acos", Math.Acos));
            _parser.AddFunction(GenericFunctions.InverseTrigFunction("atan", Math.Atan));

            _parser.AddFunction(GenericFunctions.StandardFunction("pow", Math.Pow));
            _parser.AddFunction(GenericFunctions.StandardFunction("max", Math.Max));
            _parser.AddFunction(GenericFunctions.StandardFunction("min", Math.Min));

            _parser.AddVariable(new Variable("pi", Math.PI) { IsConstant = true });
            _parser.AddVariable(new Variable("e", Math.E) { IsConstant = true });
            _parser.AddVariable(new Variable("ans"));
        }
Exemplo n.º 2
0
 public Parser(Scanner scanner)
 {
     _scanner = scanner;
 }
Exemplo n.º 3
0
 public Parser(Scanner scanner)
 {
     this.scanner = scanner;
 }