예제 #1
0
        private Node AndExpressionRest(Node node)
        {
            Node result;

            if (lex.Token == Token.And)
            {
                lex.Next();
                Node right = LogicalOrExpression();

                result = new BinaryNode { Left = node, Operator = BinaryOperator.And, Right = right };
                result = AndExpressionRest(result);
            }
            else
            {
                result = node;
            }

            return result;
        }
예제 #2
0
 public void Visit(BinaryNode node)
 {
     Debug.WriteLine("Visiting " + node.GetType().Name);
 }
예제 #3
0
 public void Visit(BinaryNode node)
 {
     Debug.Write("(");
     node.Left.Accept(this);
     Debug.Write(" " + node.Operator + " ");
     node.Right.Accept(this);
     Debug.Write(")");
 }
예제 #4
0
        private Node BooleanCompareExpressionExpressionRest(Node node)
        {
            Node result;

            BinaryOperator op;
            switch (lex.Token)
            {
                case Token.Less:
                    op = BinaryOperator.IsLess;
                    break;
                case Token.Greater:
                    op = BinaryOperator.IsGreater;
                    break;
                case Token.LessOrEqual:
                    op = BinaryOperator.IsLessOrEqual;
                    break;
                case Token.GreaterOrEqual:
                    op = BinaryOperator.IsGreaterOrEqual;
                    break;
                default:
                    op = BinaryOperator.Undefined;
                    break;
            }

            if (op != BinaryOperator.Undefined)
            {
                lex.Next();
                Node right = TermExpression();

                result = new BinaryNode { Left = node, Operator = op, Right = right };
                result = BooleanCompareExpressionExpressionRest(result);
            }
            else
            {
                result = node;
            }

            return result;
        }
예제 #5
0
        private Node TermExpressionRest(Node node)
        {
            Node result;

            BinaryOperator op = BinaryOperator.Undefined;

            if (lex.Token == Token.Plus)
            {
                op = BinaryOperator.Add;
            }
            else if (lex.Token == Token.Minus)
            {
                op = BinaryOperator.Subtract;
            }

            if (op != BinaryOperator.Undefined)
            {
                lex.Next();
                Node right = FactorExpression();

                result = new BinaryNode { Left = node, Operator = op, Right = right };
                result = TermExpressionRest(result);
            }
            else
            {
                result = node;
            }

            return result;
        }
예제 #6
0
        private Node MemberExpressionRest(Node node)
        {
            Node result;

            if (lex.Token == Token.Dot)
            {
                lex.Next();
                Node right = LateBindingIdentifierExpression();

                result = new BinaryNode { Left = node, Operator = BinaryOperator.InvokeMember, Right = right };
                result = MemberExpressionRest(result);
            }
            else
            {
                result = node;
            }

            return result;
        }
예제 #7
0
        private Node LogicalAndExpressionRest(Node node)
        {
            Node result;

            if (lex.Token == Token.BitwiseAnd)
            {
                lex.Next();
                Node right = BooleanEqualityExpression();

                result = new BinaryNode { Left = node, Operator = BinaryOperator.BitwiseAnd, Right = right };
                result = LogicalAndExpressionRest(result);
            }
            else
            {
                result = node;
            }

            return result;
        }
예제 #8
0
        private Node FactorExpressionRest(Node node)
        {
            Node result;

            BinaryOperator op;
            switch (lex.Token)
            {
                case Token.Multiply:
                    op = BinaryOperator.Multiply;
                    break;
                case Token.Divide:
                    op = BinaryOperator.Divide;
                    break;
                case Token.Modulus:
                    op = BinaryOperator.Modulus;
                    break;
                case Token.Power:
                    op = BinaryOperator.Power;
                    break;
                default:
                    op = BinaryOperator.Undefined;
                    break;
            }

            if (op != BinaryOperator.Undefined)
            {
                lex.Next();
                Node right = NotExpression();

                result = new BinaryNode { Left = node, Operator = op, Right = right };
                result = FactorExpressionRest(result);
            }
            else
            {
                result = node;
            }

            return result;
        }
예제 #9
0
        private Node BooleanEqualityExpressionRest(Node node)
        {
            Node result;

            BinaryOperator op = BinaryOperator.Undefined;

            if (lex.Token == Token.Equal)
            {
                op = BinaryOperator.IsEqual;
            }
            else if (lex.Token == Token.NotEqual)
            {
                op = BinaryOperator.IsNotEqual;
            }

            if (op != BinaryOperator.Undefined)
            {
                lex.Next();
                Node right = BooleanCompareExpression();

                result = new BinaryNode { Left = node, Operator = op, Right = right };
                result = BooleanEqualityExpressionRest(result);
            }
            else
            {
                result = node;
            }

            return result;
        }
예제 #10
0
파일: Evaluator.cs 프로젝트: helgihaf/Alpha
        public void Visit(BinaryNode node)
        {
            node.Left.Accept(this);
            node.Right.Accept(this);

            switch (node.Operator)
            {
                case BinaryOperator.Or:
                    valueStack.Or();
                    break;
                case BinaryOperator.And:
                    valueStack.And();
                    break;
                case BinaryOperator.BitwiseOr:
                    valueStack.BitwiseOr();
                    break;
                case BinaryOperator.BitwiseAnd:
                    valueStack.BitwiseAnd();
                    break;
                case BinaryOperator.IsEqual:
                    valueStack.IsEqual();
                    break;
                case BinaryOperator.IsNotEqual:
                    valueStack.IsNotEqual();
                    break;
                case BinaryOperator.IsLess:
                    valueStack.IsLess();
                    break;
                case BinaryOperator.IsGreater:
                    valueStack.IsGreater();
                    break;
                case BinaryOperator.IsLessOrEqual:
                    valueStack.IsLessOrEqual();
                    break;
                case BinaryOperator.IsGreaterOrEqual:
                    valueStack.IsGreaterOrEqual();
                    break;
                case BinaryOperator.Add:
                    valueStack.Add();
                    break;
                case BinaryOperator.Subtract:
                    valueStack.Subtract();
                    break;
                case BinaryOperator.Multiply:
                    valueStack.Multiply();
                    break;
                case BinaryOperator.Divide:
                    valueStack.Divide();
                    break;
                case BinaryOperator.Modulus:
                    valueStack.Modulus();
                    break;
                case BinaryOperator.Power:
                    valueStack.Power();
                    break;
                case BinaryOperator.InvokeMember:
                    InvokeMember();
                    break;
                default:
                    throw new NotImplementedException("Implementation mission for BinaryOperator." + node.Operator.ToString());
            }
        }