コード例 #1
0
ファイル: Parser.cs プロジェクト: ajlopez/ErlSharp
        private IExpression ParseBinaryExpression(int level)
        {
            if (level >= binaryoperators.Length)
                return this.ParseTerm();

            IExpression expr = this.ParseBinaryExpression(level + 1);

            if (expr == null)
                return null;

            Token token;

            for (token = this.lexer.NextToken(); token != null && this.IsBinaryOperator(level, token); token = this.lexer.NextToken())
            {
                if (token.Value == "=:=")
                    expr = new StrictEqualExpression(expr, this.ParseBinaryExpression(level + 1));
                else if (token.Value == "==")
                    expr = new EqualExpression(expr, this.ParseBinaryExpression(level + 1));
                else if (token.Value == "+")
                    expr = new AddExpression(expr, this.ParseBinaryExpression(level + 1));
                else if (token.Value == "-")
                    expr = new SubtractExpression(expr, this.ParseBinaryExpression(level + 1));
                else if (token.Value == "*")
                    expr = new MultiplyExpression(expr, this.ParseBinaryExpression(level + 1));
                else if (token.Value == "/")
                    expr = new DivideExpression(expr, this.ParseBinaryExpression(level + 1));
                else if (token.Value == "div")
                    expr = new DivExpression(expr, this.ParseBinaryExpression(level + 1));
                else if (token.Value == "rem")
                    expr = new RemExpression(expr, this.ParseBinaryExpression(level + 1));
            }

            if (token != null)
                this.lexer.PushToken(token);

            return expr;
        }
コード例 #2
0
        public void CompareOneWithTwo()
        {
            StrictEqualExpression expr = new StrictEqualExpression(new ConstantExpression(1), new ConstantExpression(2));

            Assert.AreEqual(false, expr.Evaluate(null));
        }
コード例 #3
0
        public void CompareNullWithNull()
        {
            StrictEqualExpression expr = new StrictEqualExpression(new ConstantExpression(null), new ConstantExpression(null));

            Assert.AreEqual(true, expr.Evaluate(null));
        }
コード例 #4
0
        public void CompareNullWithBar()
        {
            StrictEqualExpression expr = new StrictEqualExpression(new ConstantExpression(null), new ConstantExpression("bar"));

            Assert.AreEqual(false, expr.Evaluate(null));
        }
コード例 #5
0
        public void CompareIntegerOneWithRealOne()
        {
            StrictEqualExpression expr = new StrictEqualExpression(new ConstantExpression(1), new ConstantExpression(1.0));

            Assert.AreEqual(false, expr.Evaluate(null));
        }
コード例 #6
0
        public void CompareFooWithFoo()
        {
            StrictEqualExpression expr = new StrictEqualExpression(new ConstantExpression("foo"), new ConstantExpression("foo"));

            Assert.AreEqual(true, expr.Evaluate(null));
        }