Exemple #1
0
        public SqlStatement ParseCreateTableStatement()
        {
            CreateTableStatatement StatementCreate = new CreateTableStatatement();
            Token token = lexer.Get_Token();
            Error error = new Error();

            if (!(token.TokenType == TokenType.Keyword && token.Lexem == "CREATE"))
            {
                error.expected = "DROP";
                error.str      = "Create value expected";
                error.type     = "Keyword";
                result.Errors.Add(error);
            }

            token = lexer.Get_Token();
            if (!(token.TokenType == TokenType.Keyword && token.Lexem == "TABLE"))
            {
                error.expected = "TABLE";
                error.str      = "Table value expected";
                error.type     = "Keyword";
                result.Errors.Add(error);
            }

            token = lexer.Get_Token();
            if (token.TokenType != TokenType.ID)
            {
                error.expected = "Table name";
                error.str      = "Table title expected";
                error.type     = "ID";
                result.Errors.Add(error);
            }
            StatementCreate.TableName = token.Lexem;
            token = lexer.Get_Token();
            if (token.TokenType == TokenType.ID && token.Lexem != "(")
            {
                error.expected = "(";
                error.str      = "Expected (";
                error.type     = "Bracket";
                result.Errors.Add(error);
            }

            token = lexer.Get_Token();
            while (true)
            {
                if (token.TokenType != TokenType.ID)
                {
                    error.expected = "Column name";
                    error.str      = "Expected column name";
                    error.type     = "ID";
                    result.Errors.Add(error);
                }
                ColumnDef columnDef;
                columnDef.ColumnName = token.Lexem;
                token = lexer.Get_Token();
                if (token.TokenType != TokenType.TypeName)
                {
                    error.expected = "column type";
                    error.str      = "Expected column type";
                    error.type     = "TypeName";
                    result.Errors.Add(error);
                }
                columnDef.TypeName_or_value = token.Lexem;
                StatementCreate.set_columns(columnDef);
                token = lexer.Get_Token();
                if (token.TokenType == TokenType.Bracket)
                {
                    break;
                }
                token = lexer.Get_Token();
            }
            token = lexer.Get_Token();
            if (token.TokenType != TokenType.Semicolon)
            {
                error.expected = ";";
                error.str      = "Expected ;";
                error.type     = "Semicolon";
                result.Errors.Add(error);
            }
            return(StatementCreate);
        }
Exemple #2
0
 public abstract void visit(ref CreateTableStatatement CreateStatement);
 public override void visit(ref CreateTableStatatement CreateStatement)
 {
     CreateStatement.write_data();
 }
        public override void Accept(ref ExecuteVisitor visitor)
        {
            CreateTableStatatement createTableStatatement = this;

            visitor.visit(ref createTableStatatement);
        }