Beispiel #1
0
 public void Visit(FunctionalExpression s)
 {
     foreach (var arg in s._arguments)
     {
         arg.Accept(this);
     }
 }
Beispiel #2
0
        public void AddIntegersFunctionalExpression()
        {
            var expr = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { new IntegerExpression(1), new IntegerExpression(2) });

            Assert.AreEqual(new IntegerExpression(3), expr.Reduce());
            Assert.AreSame(IntegerType.Instance, expr.Type);
        }
Beispiel #3
0
        public void MatchWithFunctionalExpression()
        {
            var expr  = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { new IntegerExpression(1), new IntegerExpression(2) });
            var expr1 = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { new IntegerExpression(1), new IntegerExpression(2) });
            var expr2 = new FunctionalExpression(new SubtractIntegersFunction(), new IExpression[] { new IntegerExpression(1), new IntegerExpression(2) });
            var expr3 = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { new IntegerExpression(2), new IntegerExpression(3) });

            Assert.IsTrue(expr.Match(expr, null));
            Assert.IsTrue(expr.Match(expr1, null));
            Assert.IsFalse(expr.Match(expr2, null));
            Assert.IsFalse(expr.Match(expr3, null));
        }
Beispiel #4
0
        private FunctionalExpression Function()
        {
            var name = Consume(TokenType.WORD).Text;

            Consume(TokenType.LPAREN);
            var function = new FunctionalExpression(name);

            while (!Match(TokenType.RPAREN))
            {
                function.AddArgument(Expression());
                Match(TokenType.COMMA);
            }
            return(function);
        }
Beispiel #5
0
        public void MatchVariableInFunctionalExpression()
        {
            var one   = new IntegerExpression(1);
            var two   = new IntegerExpression(2);
            var expr  = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { new NameExpression("a"), new NameExpression("b") });
            var expr1 = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { one, two });

            Context <IExpression> ctx = new Context <IExpression>();

            Assert.IsTrue(expr.Match(expr1, ctx));

            Assert.AreSame(one, ctx.GetValue("a"));
            Assert.AreSame(two, ctx.GetValue("b"));
        }
Beispiel #6
0
        private FunctionalExpression function()
        {
            string name = consume(TokenType.WORD).getText();

            consume(TokenType.LPAREN);
            FunctionalExpression function = new FunctionalExpression(name);

            // добавление аргументов для функции
            while (!match(TokenType.RPAREN))
            {
                function.AddArgument(expression());
                match(TokenType.COMMA);
            }
            return(function);
        }
 public FunctionStatement(FunctionalExpression function)
 {
     _function = function;
 }