Esempio n. 1
0
        private IExpression ParseMatchExpression()
        {
            IExpression expression = this.ParseSimpleExpression();

            Token token = this.NextToken();

            if (expression == null)
            {
                if (token == null)
                {
                    return(null);
                }
                else
                {
                    throw new ParserException(string.Format("Unexpected '{0}'", token.Value));
                }
            }

            if (token != null && token.Type == TokenType.Operator && token.Value == "=")
            {
                expression = new MatchExpression(expression, this.ParseSimpleExpression());
                return(expression);
            }
            else if (token != null && token.Type == TokenType.Operator && token.Value == "!")
            {
                expression = new SendExpression(expression, this.ParseSimpleExpression());
                return(expression);
            }
            else
            {
                this.PushToken(token);
            }

            return(expression);
        }
Esempio n. 2
0
        public void SendMessageToProcessWithVariableExpression()
        {
            Context context = new Context();
            Process process = new Process();

            context.SetValue("X", 1);

            SendExpression expr = new SendExpression(new ConstantExpression(process), new VariableExpression(new Variable("X")));

            Assert.IsNotNull(expr.ProcessExpression);
            Assert.IsInstanceOfType(expr.ProcessExpression, typeof(ConstantExpression));
            Assert.IsNotNull(expr.MessageExpression);
            Assert.IsInstanceOfType(expr.MessageExpression, typeof(VariableExpression));

            Assert.IsTrue(expr.HasVariable());
            Assert.AreEqual(1, expr.Evaluate(context));
            Assert.AreEqual(1, process.GetMessage());
        }