예제 #1
0
        public static void Main(string[] args)
        {
            if (args.Length == 0 || args.Length > 1)
            {
                Console.WriteLine("Usage : Expr \"<expr>\" \n");
                Console.WriteLine(" eg:- Expr \"2*3+4\" \n");
                Console.WriteLine(" Expr \"-2-3\" \n");
                return;
            }

            try {
                RDParser parser = new RDParser(args[0]);
                double   nd     = parser.CallExpr();
                Console.WriteLine("The Evaluated Value is {0} \n", nd);
            }
            catch (Exception e) {
                Console.WriteLine("Error Evaluating Expression\n");
                Console.WriteLine(e);
                return;
            }
        }
//////////////////////////////////////////////////////////////////
//
// Entry point for the Test Driver
//
//
//
        public static void Main(string[] args)
        {
            if (args.Length == 0 || args.Length > 1)
            {
                Console.WriteLine("Usage : Expr \"<expr>\" \n");
                Console.WriteLine(" eg:- Expr \"2*3+4\" \n");
                Console.WriteLine(" Expr \"-2-3\" \n");
                return;
            }



            try {
                RDParser parser = new RDParser(args[0]);
                Expr     nd     = parser.CallExpr();
                Console.WriteLine("The Evaluated Value is {0} \n", nd);

                double n = nd.accept(new TreeEvaluatorVisitor());
                Console.WriteLine(n);
                nd.accept(new ReversePolishEvaluator());
                Console.WriteLine();
                StackEvaluator s = new StackEvaluator();
                nd.accept(s);
                Console.WriteLine(s.get_value());
                Console.WriteLine();

                nd.FlattenExprToList();


                Console.Read();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error Evaluating Expression\n");
                Console.WriteLine(e);
                return;
            }
        }