-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.h
More file actions
77 lines (69 loc) · 2.3 KB
/
parser.h
File metadata and controls
77 lines (69 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Created by Administrator on 2020/11/12.
//
// 描述: parser从用户处获取命令,对其进行解析,然后调用SM或QL组件方法来执行该命令
#ifndef MYDATABASE_PARSER_H
#define MYDATABASE_PARSER_H
#include <iostream>
using namespace std;
// 属性信息
struct AttrInfo {
char *attrName; // 属性名
AttrType attrType; // 属性类型
int attrLength; // 属性的长度
};
// 属性值
struct Value {
void *value;
AttrType type;
// 输出自身信息
friend std::ostream &operator<<(std::ostream &s, const Value &value) {
// 修改bug: 强转后输出字符串不需要再取地址
switch (value.type) {
case INT:
s << "int: " << *static_cast<int*>(value.value) << '\n';
break;
case FLOAT:
s << "float: " << *static_cast<float *>(value.value) << '\n';
break;
case STRING:
s << "string: " << static_cast<char*>(value.value) << '\n';
break;
case VARCHAR:
s << "varchar: " << (char*)value.value << '\n';
break;
default:
s << "unknown type" << '\n';
}
return s;
}
};
struct RelAttr {
char *relName; // relation name (may be NULL)
char *attrName; // attribute name
friend ostream &operator<<(ostream &s, const RelAttr &ra) {
return s << "relname: " << ra.relName << "\n"
<< "attrname: "<< ra.attrName << "\n";
}
};
struct Condition {
RelAttr lhsAttr; // left-hand side
CompOp op; // comparison operator
int bRhsIsAttr; // TRUE if right-hand side is an attribute
// and not a value
RelAttr rhsAttr; // right-hand side attribute if bRhsIsAttr = TRUE
Value rhsValue; // right-hand side value if bRhsIsAttr = FALSE
friend ostream &operator<<(ostream &s, const Condition &c) {
if(c.bRhsIsAttr) {
return s << c.lhsAttr << "\n"
<< c.op << "\n"
<< c.rhsAttr << "\n";
}
else {
return s << c.lhsAttr << "\n"
<< c.op << "\n"
<< c.rhsValue << "\n";
}
}
};
#endif //MYDATABASE_PARSER_H