Ejemplo n.º 1
0
        // Parse an sequence of AND on any higher priority terms.
        Node ParseBinaryMultiplication()
        {
            // Parse the left hand side for unary operations.
            var lhs = ParseUnaryNegation();

            while (true)
            {
                Func <bool, bool, bool> op = null;
                if (_tokenizer.Token == Token.AND)
                {
                    op = (a, b) => a & b;
                }

                // Return when binary operator is not found.
                if (op == null)
                {
                    return(lhs);
                }

                _tokenizer.NextToken();

                // Parse the right hand side for unary operations.
                var rhs = ParseUnaryNegation();

                // Create a binary node and use it as the left-hand side from now on
                lhs = new NodeBinary(lhs, rhs, op);
            }
        }
Ejemplo n.º 2
0
        // Parse an sequence of OR, XOR on any higher priority terms.
        Node ParseBinaryAddition()
        {
            // Parse the left hand side for higher priority operators.
            var lhs = ParseBinaryMultiplication();

            while (true)
            {
                Func <bool, bool, bool> op = null;
                if (_tokenizer.Token == Token.OR)
                {
                    op = (a, b) => a | b;
                }
                else if (_tokenizer.Token == Token.XOR)
                {
                    op = (a, b) => a ^ b;
                }

                // Return when binary operator is not found.
                if (op == null)
                {
                    return(lhs);
                }

                _tokenizer.NextToken();

                // Parse the right hand side of the expression
                var rhs = ParseBinaryMultiplication();

                // Create a binary node and use it as the left-hand side from now on
                lhs = new NodeBinary(lhs, rhs, op);
            }
        }