Exemplo n.º 1
0
        public ObjectNode IdentObject(ObjectNode objectNode)
        {
            Match(TokenType.IDENT);
            var currentToken = CurrentToken();

            if (!symbolTable.ContainsKey(objectNode.Name))
            {
                symbolTable.Add(objectNode.Name, objectNode);
            }
            currentToken = CurrentToken();
            if (currentToken.Type_ == TokenType.IDENT)
            {
                objectNode.PropertyName = currentToken.Text;
                Match(TokenType.IDENT);
            }
            else if (currentToken.Type_ == TokenType.FILTER)
            {
                FilterNode filterNode = Filter(currentToken.Text);
                objectNode.Filter = filterNode;
            }
            ConsumeNextToken();
            currentToken = CurrentToken();
            if (currentToken.Type_ == TokenType.POINT)
            {
                Match(TokenType.POINT);
                currentToken = CurrentToken();
            }
            if (currentToken.Type_ == TokenType.FILTER)
            {
                FilterNode filterNode = Filter(currentToken.Text);
                objectNode.Filter = filterNode;
                currentToken      = CurrentToken();
            }
            if (currentToken.Type_ == TokenType.POINT)
            {
                Match(TokenType.POINT);
                currentToken = CurrentToken();
            }
            if (currentToken.Type_ == TokenType.AVERAGE)
            {
                objectNode.AggregateFunction = new AggregateAverageNode();
                Match(TokenType.AVERAGE);
            }
            else if (currentToken.Type_ == TokenType.SUM)
            {
                objectNode.AggregateFunction = new AggregateSumNode();
                Match(TokenType.SUM);
            }
            else if (currentToken.Type_ == TokenType.COUNT)
            {
                objectNode.AggregateFunction = new AggregateCountNode();
                Match(TokenType.COUNT);
            }
            else if (currentToken.Type_ == TokenType.MIN)
            {
                objectNode.AggregateFunction = new AggregateMinNode();
                Match(TokenType.MIN);
            }
            else if (currentToken.Type_ == TokenType.MAX)
            {
                objectNode.AggregateFunction = new AggregateMaxNode();
                Match(TokenType.MAX);
            }
            return(objectNode);
        }
Exemplo n.º 2
0
 public AbstractSyntaxTreeNode BuildAST(DynamicBaseClass[] objectValues)
 {
     if (lookahead[lookaheadIndex].Type_ == TokenType.EQUAL)
     {
         return(Equal());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.UNEQUAL)
     {
         return(Unequal());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.SMALLERTHEN)
     {
         return(Smaller());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.SMALLERTHENOREQUAL)
     {
         return(Smallerequal());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.GREATERTHEN)
     {
         return(Greater());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.GREATERTHENOREQUAL)
     {
         return(Greaterequal());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.OPENBRACKET)
     {
         return(OpenBracket());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.CLOSEBRACKET)
     {
         return(CloseBracket());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.OPENSQUAREBRACKET)
     {
         return(OpenSquareBracket());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.CLOSESQUAREBRACKET)
     {
         return(CloseSquareBracket());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.PLUS)
     {
         return(Plus());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.MINUS)
     {
         return(Minus());
     }
     //else if (lookahead[lookaheadIndex].Type_ == TokenType.POINT)
     //{
     //    return Point();
     //}
     else if (lookahead[lookaheadIndex].Type_ == TokenType.MUL)
     {
         return(Mulibly());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.DIV)
     {
         return(Divide());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.MOD)
     {
         return(Modulo());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.IDENT)
     {
         var methodCall = CheckMethodCall(lookahead[lookaheadIndex].Text);
         if (methodCall.Item1)
         {
             return(methodCall.Item2);
         }
         var        foundObject = false;
         ObjectNode objectNode  = null;
         foreach (var objectValue in objectValues)
         {
             if (objectValue.ReferenceName == lookahead[lookaheadIndex].Text)
             {
                 objectNode = new ObjectNode()
                 {
                     Name = lookahead[lookaheadIndex].Text, ObjectValue = objectValue
                 };
                 foundObject = true;
                 break;
             }
         }
         if (foundObject)
         {
             return(IdentObject(objectNode));
         }
         return(Ident(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.SET)
     {
         return(Set(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.THEN)
     {
         return(Then(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.ELSE)
     {
         return(Else(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.IS)
     {
         return(Is(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.IN)
     {
         return(In(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.NOTIN)
     {
         return(NotIn(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.AVERAGE)
     {
         return(Average(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.SUM)
     {
         return(Sum(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.COUNT)
     {
         return(Count(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.MIN)
     {
         return(Min(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.MAX)
     {
         return(Max(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.FIELD)
     {
         return(Field(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.COLLECTION)
     {
         return(Collection(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.FILTER)
     {
         return(Collection(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.LIKE)
     {
         return(Like(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.NULL)
     {
         return(Null(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.INTEGER)
     {
         return(Integer(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.DOUBLE)
     {
         return(Double(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.BOOL)
     {
         return(Bool(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.STRING)
     {
         return(String(lookahead[lookaheadIndex].Text));
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.OR)
     {
         return(Or());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.AND)
     {
         return(And());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.COMMA)
     {
         return(Comma());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.LOWER)
     {
         return(Lower());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.UPPER)
     {
         return(Upper());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.LENGTH)
     {
         return(Lenght());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.TRIM)
     {
         return(Trim());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.LEFTTRIM)
     {
         return(LeftTrim());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.RIGHTTRIM)
     {
         return(RightTrim());
     }
     else if (lookahead[lookaheadIndex].Type_ == TokenType.POINT)
     {
         return(Point());
     }
     return(null);
 }