Exemplo n.º 1
0
        public static void DumpTokens(string mathCode)
        {
            var tokenizer = new MathTokenizer();

            using (var reader = new StringReader(mathCode))
            {
                var tokens = tokenizer.Tokenize(reader);
                while (tokens.MoveNext())
                    Console.WriteLine(tokens.Current);
            }
        }
Exemplo n.º 2
0
        public static void DumpTree(string mathCode)
        {
            Expression expression;

            var tokenizer = new MathTokenizer();
            var parser = new MathParser();

            using (var reader = new StringReader(mathCode))
            {
                var tokens = tokenizer.Tokenize(reader);
                expression = parser.Parse(tokens);
            }

            Console.WriteLine(expression.ToString());
        }
Exemplo n.º 3
0
        public static MathValue InterpretSingle(string mathCode)
        {
            Expression expression;

            var tokenizer = new MathTokenizer();
            var parser = new MathParser();

            using (var reader = new StringReader(mathCode))
            {
                var tokens = tokenizer.Tokenize(reader);
                expression = parser.Parse(tokens);
            }

            var context = CreateGlobalContext();
            var result = expression.Evaluate(context);

            return result;
        }