Exemple #1
0
        public static void Main(string[] args)
        {
            foreach (string arg in args)
                if (IsLocalAddress(arg))
                    ProcessLocalAddress(arg);
                else
                    ProcessRemoteAddress(arg);

            foreach (IHost host in remotehosts)
            {
                Parser parser = new Parser("PrintLine(\"Hello, world\");");
                ICommand cmd = parser.ParseCommand();
                host.Execute(cmd);

                parser = new Parser("new DynamicObject()");
                IObject result = (IObject)host.Evaluate(parser.ParseExpression());
                host.Invoke(result, "SetValue", new object[] { "Print", new Function(null, cmd) });
                object func = host.Invoke(result, "GetValue", new object[] { "Print" });
                host.Invoke(result, "Print", null);

                // Function function = new Function(null, cmd);
                // result.SetValue("Print", function);
                // result.Invoke("Print", null);
            }

            Console.ReadLine();
        }
        private object EvaluateExpression(string text)
        {
            Parser parser = new Parser(text);

            IExpression expression = parser.ParseExpression();

            return this.host.Evaluate(expression);
        }
Exemple #3
0
        public object Invoke(IBindingEnvironment environment, object[] arguments)
        {
            if (arguments == null || arguments.Length != 1)
                throw new InvalidOperationException("Invalid number of parameters");

            string text = (string)arguments[0];

            Parser parser = new Parser(text);

            IExpression expression = parser.ParseExpression();

            return expression.Evaluate(environment);
        }
Exemple #4
0
        public object Invoke(IBindingEnvironment environment, object[] arguments)
        {
            if (arguments == null || arguments.Length != 1)
                throw new InvalidOperationException("Invalid number of parameters");

            string text = (string)arguments[0];

            Parser parser = new Parser(text);

            ICommand command;

            while ((command = parser.ParseCommand()) != null)
                command.Execute(environment);

            return null;
        }
        public override void Execute(string commandtext)
        {
            Machine current = Machine.Current;

            try
            {
                Machine.SetCurrent(this.Machine);
                Parser parser = new Parser(commandtext);

                ICommand command;

                while ((command = parser.ParseCommand()) != null)
                    command.Execute(this.Machine.Environment);
            }
            finally
            {
                Machine.SetCurrent(current);
            }
        }
 private IExpression GetExpression(string expressiontext)
 {
     Parser parser = new Parser(expressiontext);
     return parser.ParseExpression();
 }
 private IExpression ProcessExpression(string expressiontext)
 {
     Parser parser = new Parser(expressiontext);
     IExpression expression = parser.ParseExpression();
     return (IExpression)this.SerializeDeserialize(expression);
 }
 private ICommand ProcessCommand(string commandtext)
 {
     Parser parser = new Parser(commandtext);
     ICommand command = parser.ParseCommand();
     return (ICommand)this.SerializeDeserialize(command);
 }
Exemple #9
0
        public static void Main(string[] args)
        {
            // According http://msdn.microsoft.com/en-us/magazine/cc300474.aspx
            LifetimeServices.LeaseTime = TimeSpan.FromMinutes(10);
            LifetimeServices.RenewOnCallTime = TimeSpan.FromMinutes(15);
            LifetimeServices.SponsorshipTimeout = TimeSpan.FromMinutes(1);

            AjSharpMachine machine = new AjSharpMachine();
            Parser parser;
            ICommand command;

            foreach (string filename in args)
            {
                try
                {
                    parser = new Parser(System.IO.File.ReadAllText(filename));

                    while ((command = parser.ParseCommand()) != null)
                        command.Execute(machine.Environment);
                }
                catch (ExitException)
                {
                    return;
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        Console.Error.WriteLine(ex.InnerException.Message);
                        Console.Error.WriteLine(ex.InnerException.StackTrace);
                    }

                    Console.Error.WriteLine(ex.Message);
                    Console.Error.WriteLine(ex.StackTrace);
                }
            }

            try
            {
                parser = new Parser(machine.In);

                command = parser.ParseCommand();

                while (command != null)
                {
                    command.Execute(machine.Environment);
                    command = parser.ParseCommand();
                }
            }
            catch (ExitException)
            {
                return;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Console.Error.WriteLine(ex.InnerException.Message);
                    Console.Error.WriteLine(ex.InnerException.StackTrace);
                }

                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                Console.ReadLine();
            }
        }
Exemple #10
0
        private static IExpression ParseExpression(string text)
        {
            Parser parser = new Parser(text);

            IExpression expression = parser.ParseExpression();

            Assert.IsNull(parser.ParseExpression());

            return expression;
        }
Exemple #11
0
        private static ICommand ParseCommand(string text)
        {
            Parser parser = new Parser(text);

            ICommand command = parser.ParseCommand();

            Assert.IsNull(parser.ParseCommand());

            return command;
        }
Exemple #12
0
        public static void Main(string[] args)
        {
            foreach (string address in args)
            {
                if (address[0] == '-')
                    continue;

                servers.Add(new WcfHostServer(address));
            }

            foreach (WcfHostServer server in servers)
                server.Open();

            foreach (string address in args)
            {
                if (address[0] != '-')
                    continue;

                channels.Add(new WcfHostClient(address.Substring(1)));
            }

            try
            {
                Parser parser = new Parser("new DynamicObject()");

                IExpression expression = parser.ParseExpression();

                if (channels.Count > 0)
                {
                    object result = channels[0].Evaluate(expression);
                }

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

                ICommand command = parser.ParseCommand();

                while (command != null)
                {
                    channels[0].Execute(command);
                    command = parser.ParseCommand();
                }
            }
            catch (ExitException)
            {
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Console.Error.WriteLine(ex.InnerException.Message);
                    Console.Error.WriteLine(ex.InnerException.StackTrace);
                }

                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                Console.ReadLine();
            }

            foreach (WcfHostServer server in servers)
                server.Close();
        }
Exemple #13
0
        private void ExecuteCommand(string text)
        {
            Parser parser = new Parser(text);

            ICommand command = parser.ParseCommand();

            this.host.Execute(command);
        }
Exemple #14
0
        private IExpression ParseSimpleTermExpression()
        {
            if (this.TryParse(TokenType.Name, "default"))
            {
                if (this.TryParse(TokenType.Name, "function") || this.TryParse(TokenType.Name, "sub"))
                    return this.ParseFunctionExpression(true);

                throw new UnexpectedTokenException(this.lexer.NextToken());
            }

            if (this.TryParse(TokenType.Name, "function") || this.TryParse(TokenType.Name, "sub"))
                return this.ParseFunctionExpression(false);

            Token token = this.lexer.NextToken();

            if (token == null)
                return null;

            switch (token.TokenType)
            {
                case TokenType.Separator:
                    if (token.Value == "(")
                    {
                        IExpression expr = this.ParseExpression();
                        this.Parse(TokenType.Separator, ")");
                        return expr;
                    }

                    break;
                case TokenType.Boolean:
                    bool booleanValue = Convert.ToBoolean(token.Value);
                    return new ConstantExpression(booleanValue);
                case TokenType.Integer:
                    int intValue = Int32.Parse(token.Value, System.Globalization.CultureInfo.InvariantCulture);
                    return new ConstantExpression(intValue);
                case TokenType.Real:
                    double realValue = Double.Parse(token.Value, System.Globalization.CultureInfo.InvariantCulture);
                    return new ConstantExpression(realValue);
                case TokenType.String:
                    IList<string> parts = StringUtilities.SplitText(token.Value);

                    if (parts.Count == 1)
                        return new ConstantExpression(token.Value);

                    IExpression strexpr = new ConstantExpression(parts[0]);

                    for (int k = 1; k < parts.Count; k++)
                        if ((k % 2) == 0)
                            strexpr = new ConcatenateExpression(strexpr, new ConstantExpression(parts[k]));
                        else
                        {
                            Parser parser = new Parser(parts[k]);
                            strexpr = new ConcatenateExpression(strexpr, parser.ParseExpression());
                        }

                    return strexpr;
                case TokenType.Name:
                    if (this.TryParse(TokenType.Separator, "("))
                    {
                        List<IExpression> arguments = this.ParseArgumentList();
                        return new InvokeExpression(token.Value, arguments);
                    }

                    if (this.TryParse(TokenType.Operator, "..."))
                    {
                        this.lexer.NextToken();

                        return new VariableVariableExpression(token.Value);
                    }

                    return new VariableExpression(token.Value);
            }

            throw new UnexpectedTokenException(token);
        }
Exemple #15
0
        private void ExecuteCommand(string text)
        {
            Parser parser = new Parser(text);

            ICommand command = parser.ParseCommand();

            command.Execute(this.machine.Environment);
        }
Exemple #16
0
        private object EvaluateExpression(string text)
        {
            Parser parser = new Parser(text);

            IExpression expression = parser.ParseExpression();

            return expression.Evaluate(this.machine.Environment);
        }