Exemple #1
0
        private static SubProduction AndRule()
        {
            return(new SubProduction
                   (
                       new List <ExpressionDefinition>
            {
                new NonTerminalExpressionDefinition {
                    Identifier = ParserConstants.BooleanExpression
                },
                new TerminalExpressionDefinition {
                    TokenType = TokenType.And
                },
                new NonTerminalExpressionDefinition {
                    Key = "BooleanExpression2", Identifier = ParserConstants.BooleanExpression
                },
                new SemanticActionDefinition((ParsingNode node) =>
                {
                    BooleanExpressionASTNode left = node.GetAttributeForKey <BooleanExpressionASTNode>(ParserConstants.BooleanExpression, ParserConstants.SyntaxTreeNode);
                    BooleanExpressionASTNode right = node.GetAttributeForKey <BooleanExpressionASTNode>("BooleanExpression2", ParserConstants.SyntaxTreeNode);

                    AndASTNode syntaxTreeNode = new AndASTNode(left, right);
                    node.Attributes.Add(ParserConstants.SyntaxTreeNode, syntaxTreeNode);
                })
            }
                   ));
        }
        private static SubProduction GetSelectRule()
        {
            return(new SubProduction
                   (
                       new List <ExpressionDefinition>
            {
                new TerminalExpressionDefinition {
                    TokenType = TokenType.Select
                },
                new NonTerminalExpressionDefinition {
                    Identifier = ParserConstants.Top
                },
                new NonTerminalExpressionDefinition {
                    Identifier = ParserConstants.SelectColumns
                },
                new TerminalExpressionDefinition {
                    TokenType = TokenType.From
                },
                new NonTerminalExpressionDefinition {
                    Identifier = ParserConstants.Identifier
                },
                new NonTerminalExpressionDefinition {
                    Identifier = ParserConstants.Join
                },
                new NonTerminalExpressionDefinition {
                    Identifier = ParserConstants.Where
                },
                new SemanticActionDefinition((ParsingNode node) =>
                {
                    IdentifierASTNode identifier = node.GetAttributeForKey <IdentifierASTNode>(ParserConstants.Identifier, ParserConstants.SyntaxTreeNode);

                    BooleanExpressionASTNode condition = node.GetAttributeForKey <BooleanExpressionASTNode>(ParserConstants.Where, ParserConstants.SyntaxTreeNode);
                    JoinASTNode join = node.GetAttributeForKey <JoinASTNode>(ParserConstants.Join, ParserConstants.SyntaxTreeNode);
                    TopASTNode top = node.GetAttributeForKey <TopASTNode>(ParserConstants.Top, ParserConstants.SyntaxTreeNode);

                    FromASTNode from = new FromASTNode()
                    {
                        Identifier = identifier
                    };

                    node.Attributes.Add(ParserConstants.SyntaxTreeNode, new SelectASTNode()
                    {
                        From = from,
                        Condition = condition,
                        Join = join,
                        Top = top,
                        SelectColumns = node.GetAttributeForKey <List <FactorASTNode> >(ParserConstants.SelectColumns, ParserConstants.SyntaxTreeNodes)
                    });
                })
            }
                   ));
        }
Exemple #3
0
        private Condition BooleanExpressionToCondition(TableDefinition mainTable, BooleanExpressionASTNode expr)
        {
            if (expr is AndASTNode andNode)
            {
                Condition c = new AndCondition()
                {
                    Left  = BooleanExpressionToCondition(mainTable, andNode.Left),
                    Right = BooleanExpressionToCondition(mainTable, andNode.Right),
                };

                return(c);
            }
            else if (expr is OrASTNode orNode)
            {
                Condition c = new OrCondition()
                {
                    Left  = BooleanExpressionToCondition(mainTable, orNode.Left),
                    Right = BooleanExpressionToCondition(mainTable, orNode.Right),
                };

                return(c);
            }
            else if (expr is RelOpASTNode relopNode)
            {
                AttributeDefinition attributeDefinition = null;

                if (relopNode.Left is IdentifierASTNode)
                {
                    attributeDefinition = GetColumnFromIdentifierNode(mainTable, (IdentifierASTNode)relopNode.Left);
                }
                else if (relopNode.Right is IdentifierASTNode)
                {
                    attributeDefinition = GetColumnFromIdentifierNode(mainTable, (IdentifierASTNode)relopNode.Right);
                }

                object value = GetValueFromConditionASTNode(relopNode.Right) ?? GetValueFromConditionASTNode(relopNode.Left);

                return(new LeafCondition
                {
                    Column = attributeDefinition,
                    Operation = relopNode.RelationOperator,
                    Value = value
                });
            }

            return(null);
        }
        private static SubProduction GetWhereRule()
        {
            return(new SubProduction
                   (
                       new List <ExpressionDefinition>
            {
                new TerminalExpressionDefinition {
                    TokenType = TokenType.Where
                },
                new NonTerminalExpressionDefinition {
                    Identifier = ParserConstants.BooleanExpression
                },
                new SemanticActionDefinition((ParsingNode node) =>
                {
                    BooleanExpressionASTNode condition = node.GetAttributeForKey <BooleanExpressionASTNode>(ParserConstants.BooleanExpression, ParserConstants.SyntaxTreeNode);

                    node.Attributes.Add(ParserConstants.SyntaxTreeNode, condition);
                })
            }
                   ));
        }