예제 #1
0
파일: Program.cs 프로젝트: ajlopez/AjSharp
        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();
        }
예제 #2
0
        private object EvaluateExpression(string text)
        {
            Parser parser = new Parser(text);

            IExpression expression = parser.ParseExpression();

            return this.host.Evaluate(expression);
        }
예제 #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);
        }
예제 #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;
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
 private IExpression GetExpression(string expressiontext)
 {
     Parser parser = new Parser(expressiontext);
     return parser.ParseExpression();
 }
예제 #7
0
 private IExpression ProcessExpression(string expressiontext)
 {
     Parser parser = new Parser(expressiontext);
     IExpression expression = parser.ParseExpression();
     return (IExpression)this.SerializeDeserialize(expression);
 }
예제 #8
0
 private ICommand ProcessCommand(string commandtext)
 {
     Parser parser = new Parser(commandtext);
     ICommand command = parser.ParseCommand();
     return (ICommand)this.SerializeDeserialize(command);
 }
예제 #9
0
파일: Program.cs 프로젝트: ajlopez/AjSharp
        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();
            }
        }
예제 #10
0
        private static IExpression ParseExpression(string text)
        {
            Parser parser = new Parser(text);

            IExpression expression = parser.ParseExpression();

            Assert.IsNull(parser.ParseExpression());

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

            ICommand command = parser.ParseCommand();

            Assert.IsNull(parser.ParseCommand());

            return command;
        }
예제 #12
0
파일: Program.cs 프로젝트: ajlopez/AjSharp
        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();
        }
예제 #13
0
        private void ExecuteCommand(string text)
        {
            Parser parser = new Parser(text);

            ICommand command = parser.ParseCommand();

            this.host.Execute(command);
        }
예제 #14
0
파일: Parser.cs 프로젝트: ajlopez/AjSharp
        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);
        }
예제 #15
0
        private void ExecuteCommand(string text)
        {
            Parser parser = new Parser(text);

            ICommand command = parser.ParseCommand();

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

            IExpression expression = parser.ParseExpression();

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