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 {
    Operator, // >, >=, ==, !=, <, <=
    Identifier, // t1, a, b

So, Token is also updated.

pub enum Token {

    // ...

    /* Operator */
    LT, // <
    LE, // <=
    EQ, // ==
    NE, // !=
    GT, // >
    GE, // >=