Пример #1
0
        public static void Main(string[] args)
        {
            PythonSharp.Machine machine = new PythonSharp.Machine();

            if (args != null && args.Length > 0)
            {
                if (ProcessFiles(args, machine))
                {
                    return;
                }
            }

            PrintIntro();

            Parser parser = new Parser(System.Console.In);

            while (true)
            {
                try
                {
                    ICommand command = parser.CompileCommand();

                    if (command == null)
                    {
                        break;
                    }

                    if (command is ExpressionCommand)
                    {
                        IExpression expr  = ((ExpressionCommand)command).Expression;
                        var         value = expr.Evaluate(machine.Environment);

                        if (value != null)
                        {
                            Console.WriteLine(ValueUtilities.AsPrintString(value));
                        }
                    }
                    else
                    {
                        command.Execute(machine.Environment);
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                }
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            PythonSharp.Machine machine = new PythonSharp.Machine();

            if (args != null && args.Length > 0)
                if (ProcessFiles(args, machine))
                    return;

            PrintIntro();

            Parser parser = new Parser(System.Console.In);

            while (true)
            {
                try
                {
                    ICommand command = parser.CompileCommand();

                    if (command == null)
                        break;

                    if (command is ExpressionCommand)
                    {
                        IExpression expr = ((ExpressionCommand)command).Expression;
                        var value = expr.Evaluate(machine.Environment);

                        if (value != null)
                            Console.WriteLine(ValueUtilities.AsPrintString(value));
                    }
                    else
                        command.Execute(machine.Environment);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                }
            }
        }