another ugly basic implementation

This commit is contained in:
2021-07-04 15:03:13 +02:00
parent b55115f7c3
commit b4711985b3
12 changed files with 417 additions and 60 deletions

View File

@@ -14,6 +14,13 @@ enum class ColumnType {
};
enum class NodeType {
true_node,
int_value,
float_value,
string_value,
database_value,
logical_operator,
relational_operator,
create_table,
insert_into,
select_from,
@@ -56,6 +63,59 @@ struct ColDefNode : Node {
Node(NodeType::column_def), name(col_name), type(col_type), order(col_order), length(col_len), null(nullable) {}
};
struct TrueNode : Node {
TrueNode() : Node(NodeType::true_node) {}
};
struct IntValueNode : Node {
int value;
IntValueNode(int value) : Node(NodeType::int_value), value(value) {}
};
struct FloatValueNode : Node {
double value;
FloatValueNode(double value) : Node(NodeType::float_value), value(value) {}
};
struct StringValueNode : Node {
std::string value;
StringValueNode(std::string value) : Node(NodeType::string_value), value(value) {}
};
struct DatabaseValueNode : Node {
std::string col_name;
DatabaseValueNode(std::string name) : Node(NodeType::database_value), col_name(name) {}
};
struct LogicalOperatorNode : Node {
// and_operator,
// or_operator,
// not_operator,
// and / or / not
std::unique_ptr<Node> left;
std::unique_ptr<Node> right;
};
enum class RelationalOperatorType {
equal,
greater
// =, !=, >, >=, <, <=, like
};
struct RelationalOperatorNode : Node {
RelationalOperatorType op;
std::unique_ptr<Node> left;
std::unique_ptr<Node> right;
RelationalOperatorNode(RelationalOperatorType op, std::unique_ptr<Node> left, std::unique_ptr<Node> right) :
Node(NodeType::relational_operator), op(op), left(std::move(left)), right(std::move(right)) {};
};
struct CreateTableNode : Node {
std::string table_name;
std::vector<ColDefNode> cols_defs;
@@ -76,10 +136,10 @@ struct InsertIntoTableNode : Node {
struct SelectFromTableNode : Node {
std::string table_name;
std::vector<ColNameNode> cols_names;
std::vector<Node> where;
std::unique_ptr<Node> where;
SelectFromTableNode(const std::string name, std::vector<ColNameNode> names, std::vector<Node> where_clause) :
Node(NodeType::select_from), table_name(name), cols_names(names), where(where_clause) {}
SelectFromTableNode(const std::string name, std::vector<ColNameNode> names, std::unique_ptr<Node> where_clause) :
Node(NodeType::select_from), table_name(name), cols_names(names), where(std::move(where_clause)) {}
};
struct UpdateTableNode : Node { };
@@ -101,6 +161,10 @@ private:
std::unique_ptr<Node> parse_insert_into_table();
std::unique_ptr<Node> parse_select_from_table();
std::unique_ptr<Node> parse_where_clause();
std::unique_ptr<Node> parse_operand_node();
RelationalOperatorType parse_operator();
private:
Lexer lexer;
};