예제 #1
0
        private GenericExpressionNode BooleanTermPrime(string expression, GenericExpressionNode lhs)
        {
            if (this._lexer.IsNext(Token.TokenType.EndOfInput))
            {
                return(lhs);
            }
            else if (Same(expression, Token.TokenType.And))
            {
                GenericExpressionNode rhs = RelationalExpr(expression);
                if (null == rhs)
                {
                    this.errorPosition = this._lexer.GetErrorPosition();
                }

                OperatorExpressionNode andNode = new AndExpressionNode();
                andNode.LeftChild  = lhs;
                andNode.RightChild = rhs;
                return(BooleanTermPrime(expression, andNode));
            }
            else
            {
                // Should this be error case?
                return(lhs);
            }
        }
예제 #2
0
        private GenericExpressionNode Factor(string expression)
        {
            // Checks for TokenTypes String, Numeric, Property, ItemMetadata, and ItemList.
            GenericExpressionNode arg = this.Arg(expression);

            // If it's one of those, return it.
            if (arg != null)
            {
                return(arg);
            }

            // If it's not one of those, check for other TokenTypes.
            Token current = this._lexer.CurrentToken;

            if (Same(expression, Token.TokenType.Function))
            {
                if (!Same(expression, Token.TokenType.LeftParenthesis))
                {
                    this.errorPosition = this._lexer.GetErrorPosition();
                    return(null);
                }
                var arglist = new List <GenericExpressionNode>();
                Arglist(expression, arglist);
                if (!Same(expression, Token.TokenType.RightParenthesis))
                {
                    this.errorPosition = this._lexer.GetErrorPosition();
                    return(null);
                }
                return(new FunctionCallExpressionNode(current.String, arglist));
            }
            else if (Same(expression, Token.TokenType.LeftParenthesis))
            {
                GenericExpressionNode child = Expr(expression);
                if (Same(expression, Token.TokenType.RightParenthesis))
                {
                    return(child);
                }
                else
                {
                    this.errorPosition = this._lexer.GetErrorPosition();
                }
            }
            else if (Same(expression, Token.TokenType.Not))
            {
                OperatorExpressionNode notNode = new NotExpressionNode();
                GenericExpressionNode  expr    = Factor(expression);
                if (expr == null)
                {
                    this.errorPosition = this._lexer.GetErrorPosition();
                }
                notNode.LeftChild = expr;
                return(notNode);
            }
            else
            {
                this.errorPosition = this._lexer.GetErrorPosition();
            }
            return(null);
        }
예제 #3
0
        private void Args(string expression, List <GenericExpressionNode> arglist)
        {
            GenericExpressionNode arg = Arg(expression);

            arglist.Add(arg);
            if (Same(expression, Token.TokenType.Comma))
            {
                Args(expression, arglist);
            }
        }
예제 #4
0
        //
        // Top node of grammar
        //    See grammar for how the following methods relate to each
        //    other.
        //
        private GenericExpressionNode Expr(string expression)
        {
            GenericExpressionNode node = BooleanTerm(expression);

            if (!this._lexer.IsNext(Token.TokenType.EndOfInput))
            {
                node = ExprPrime(expression, node);
            }

            return(node);
        }
예제 #5
0
        private GenericExpressionNode BooleanTerm(string expression)
        {
            GenericExpressionNode node = RelationalExpr(expression);

            if (null == node)
            {
                this.errorPosition = this._lexer.GetErrorPosition();
            }

            if (!this._lexer.IsNext(Token.TokenType.EndOfInput))
            {
                node = BooleanTermPrime(expression, node);
            }
            return(node);
        }
예제 #6
0
        private GenericExpressionNode RelationalExpr(string expression)
        {
            {
                GenericExpressionNode lhs = Factor(expression);
                if (null == lhs)
                {
                    this.errorPosition = this._lexer.GetErrorPosition();
                }

                OperatorExpressionNode node = RelationalOperation(expression);
                if (node == null)
                {
                    return(lhs);
                }
                GenericExpressionNode rhs = Factor(expression);
                node.LeftChild  = lhs;
                node.RightChild = rhs;
                return(node);
            }
        }
예제 #7
0
 private GenericExpressionNode ExprPrime(string expression, GenericExpressionNode lhs)
 {
     if (Same(expression, Token.TokenType.EndOfInput))
     {
         return(lhs);
     }
     else if (Same(expression, Token.TokenType.Or))
     {
         OperatorExpressionNode orNode = new OrExpressionNode();
         GenericExpressionNode  rhs    = BooleanTerm(expression);
         orNode.LeftChild  = lhs;
         orNode.RightChild = rhs;
         return(ExprPrime(expression, orNode));
     }
     else
     {
         // I think this is ok.  ExprPrime always shows up at
         // the rightmost side of the grammar rhs, the EndOfInput case
         // takes care of things
         return(lhs);
     }
 }
예제 #8
0
        //
        // Main entry point for parser.
        // You pass in the expression you want to parse, and you get an
        // ExpressionTree out the back end.
        //
        public GenericExpressionNode Parse(string expression, ParserOptions optionSettings)
        {
            // We currently have no support (and no scenarios) for disallowing property references
            // in Conditions.
            ErrorUtilities.VerifyThrow(0 != (optionSettings & ParserOptions.AllowProperties),
                                       "Properties should always be allowed.");

            this._options = optionSettings;

            this._lexer = new Scanner(expression, this._options);
            if (!this._lexer.Advance())
            {
                this.errorPosition = this._lexer.GetErrorPosition();
            }
            GenericExpressionNode node = Expr(expression);

            if (!this._lexer.IsNext(Token.TokenType.EndOfInput))
            {
                this.errorPosition = this._lexer.GetErrorPosition();
            }
            return(node);
        }