Пример #1
0
        protected Top GetTop()
        {
            Tokenizer.ExpectToken(Constants.Top);

            Top top;
            if (Tokenizer.IsNextToken(Constants.OpenBracket))
            {
                using (Tokenizer.ExpectBrackets())
                {
                    var parser = new ExpressionParser(Tokenizer);
                    var expression = parser.Execute();
                    if (expression == null)
                        throw new SyntaxException("TOP clause requires an expression");

                    var brackets = new NestedExpression(null);
                    brackets.Expression = expression;
                    top = new Top(brackets);
                }
            }
            else
            {
                if (Tokenizer.Current.Type != TokenType.Numeric || Tokenizer.Current.Value.Contains("."))
                    throw new SyntaxException(String.Format("Expected integer but found: '{0}'", Tokenizer.Current.Value));

                top = new Top(new StringExpression(Tokenizer.Current.Value, null));
                ReadNextToken();
            }

            if (Tokenizer.TokenEquals(Constants.Percent))
                top.Percent = true;

            return top;
        }
Пример #2
0
        private Expression GetNestedExpression( Expression parent )
        {
            Expression result;
            using ( Tokenizer.ExpectBrackets() )
            {
                result = ReadCriteriaList( parent );
                if ( Tokenizer.IsNextToken( Constants.Comma ) )
                {
                    var list = new ExpressionList();
                    list.Identifiers.Add( result );

                    do
                    {
                        Tokenizer.ExpectToken( Constants.Comma );

                        result = ReadCriteriaList( parent );
                        list.Identifiers.Add( result );

                    } while ( Tokenizer.IsNextToken( Constants.Comma ) );

                    result = list;
                }
            }

            NestedExpression nestedExpression = new NestedExpression( parent ) { Expression = result };
            result.Parent = nestedExpression;
            return nestedExpression;
        }