2018/10/28
It's recommended to read on Gitbook
I am confused in these days about how to implement the parser. PhD candidate Yushan Lin suggest me to see how VanillaDB implement, which is a DBMS developed by his lab.
There are many document about VanillaDB
in its official website, including the parser one. It is worth and enlightening to read the parser slide, because it is professional but not complicated.
The most important part is that VanillaDB
adopt recursive descent parser. You can check out more via google the keyword. I decide to use this method to implement grammar rule parser.
A recursive-descent parser has a method for each grammar rule, and calls these methods recursively to traverse the parse tree in prefix order.
In the end, let's update the status of the previous code. In order to lexically scan messages, I add another types in Group
, which are Operator
, Number
, and Identifier
.
pub enum Group {
DataType,
DoubleKeyword,
MultiKeyword,
Function,
Keyword,
Operator, // >, >=, ==, !=, <, <=
Number,
Identifier, // t1, a, b
}
So, Token
is also updated.
pub enum Token {
// ...
/* Operator */
LT, // <
LE, // <=
EQ, // ==
NE, // !=
GT, // >
GE, // >=
}
Quick Link
1.StellarSQL Repository
2.Gitbook of this seriesAuthor
Liu, An-Chi (劉安齊). A software engineer, who loves writing code and promoting CS to people. Welcome to follow me at Facebook Page. More information on Personal Site and Github.