예제 #1
0
        public static void Main()
        {
            var ep = new ExpressionProcessor();

            ep.Variables.Add('x', 5);

            System.Console.WriteLine(ep.Calculate("1"));
            System.Console.WriteLine(ep.Calculate("1+2"));
            System.Console.WriteLine(ep.Calculate("1+x"));
            System.Console.WriteLine(ep.Calculate("1+xy"));
        }
예제 #2
0
        static void Main(string[] args)
        {
            var expression = "32+a-52+a";
            var dict       = new Dictionary <char, int>();

            dict.Add('a', 2);
            var lexer  = new Lexer(expression, dict);
            var tokens = lexer.Lex();

            foreach (var token in tokens)
            {
                Console.WriteLine($"{token.Type}, {token.Value}");
            }

            var variables = new Dictionary <char, int>();

            variables.Add('a', 2);

            var processor = new ExpressionProcessor(variables);

            Console.WriteLine($"The sum of {expression} is {processor.Calculate(expression)}");
        }
예제 #3
0
 public void Init()
 {
     sut = new ExpressionProcessor();
 }