minor changes. and extended token list
This commit is contained in:
parent
e886ae1644
commit
3c520b7aa4
|
@ -11,7 +11,7 @@ SQLParser::SQLParser() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Statement* SQLParser::parseSQL(const char *text) {
|
Statement* SQLParser::parseSQLString(const char *text) {
|
||||||
Statement* stmt;
|
Statement* stmt;
|
||||||
yyscan_t scanner;
|
yyscan_t scanner;
|
||||||
YY_BUFFER_STATE state;
|
YY_BUFFER_STATE state;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
class SQLParser {
|
class SQLParser {
|
||||||
public:
|
public:
|
||||||
static Statement* parseSQL(const char* sql);
|
static Statement* parseSQLString(const char* sql);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SQLParser();
|
SQLParser();
|
||||||
|
|
|
@ -78,7 +78,10 @@ typedef void* yyscan_t;
|
||||||
/*********************************
|
/*********************************
|
||||||
** Token Definition
|
** Token Definition
|
||||||
*********************************/
|
*********************************/
|
||||||
%token SELECT FROM GROUP BY WHERE NOT AND OR
|
%token SELECT FROM WHERE GROUP BY HAVING
|
||||||
|
%token JOIN ON INNER OUTER LEFT RIGHT CROSS USING NATURAL
|
||||||
|
%token CREATE TABLE DATABASE INDEX
|
||||||
|
%token AS NOT AND OR NULL
|
||||||
%token <sval> NAME STRING COMPARISON
|
%token <sval> NAME STRING COMPARISON
|
||||||
%token <number> FLOAT
|
%token <number> FLOAT
|
||||||
%token <uintnum> EQUALS NOTEQUALS LESS GREATER LESSEQ GREATEREQ
|
%token <uintnum> EQUALS NOTEQUALS LESS GREATER LESSEQ GREATEREQ
|
||||||
|
|
|
@ -15,7 +15,7 @@ SQLParser::SQLParser() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Statement* SQLParser::parseSQL(const char *text) {
|
Statement* SQLParser::parseSQLString(const char *text) {
|
||||||
yyscan_t scanner;
|
yyscan_t scanner;
|
||||||
yylex_init(&scanner);
|
yylex_init(&scanner);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
class SQLParser {
|
class SQLParser {
|
||||||
public:
|
public:
|
||||||
static Statement* parseSQL(const char* sql);
|
static Statement* parseSQLString(const char* sql);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SQLParser();
|
SQLParser();
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// TODO: try to replace the List wrapper by directly using std::vector
|
||||||
|
|
||||||
template <typename _T>
|
template <typename _T>
|
||||||
class List {
|
class List {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -19,7 +19,7 @@ int main(int argc, char *argv[]) {
|
||||||
char* sql = argv[n];
|
char* sql = argv[n];
|
||||||
|
|
||||||
printf("\nEvaluating Statement \"%s\"\n", sql);
|
printf("\nEvaluating Statement \"%s\"\n", sql);
|
||||||
Statement* stmt = SQLParser::parseSQL(sql);
|
Statement* stmt = SQLParser::parseSQLString(sql);
|
||||||
|
|
||||||
if (stmt == NULL) {
|
if (stmt == NULL) {
|
||||||
fprintf(stderr, "Parsing of \"%s\" failed!\n", sql);
|
fprintf(stderr, "Parsing of \"%s\" failed!\n", sql);
|
||||||
|
|
|
@ -19,7 +19,7 @@ void SelectTest1() {
|
||||||
printf("Test: SelectTest1... "); fflush(stdout);
|
printf("Test: SelectTest1... "); fflush(stdout);
|
||||||
|
|
||||||
const char* sql = "SELECT age, name, address from table WHERE age < 12.5;";
|
const char* sql = "SELECT age, name, address from table WHERE age < 12.5;";
|
||||||
Statement* sqlStatement = SQLParser::parseSQL(sql);
|
Statement* sqlStatement = SQLParser::parseSQLString(sql);
|
||||||
ASSERT(sqlStatement != NULL);
|
ASSERT(sqlStatement != NULL);
|
||||||
ASSERT(sqlStatement->type == eSelect);
|
ASSERT(sqlStatement->type == eSelect);
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ void SelectTest2() {
|
||||||
printf("Test: SelectTest2... "); fflush(stdout);
|
printf("Test: SelectTest2... "); fflush(stdout);
|
||||||
|
|
||||||
const char* sql = "SELECT * FROM (SELECT age FROM table, table2);";
|
const char* sql = "SELECT * FROM (SELECT age FROM table, table2);";
|
||||||
Statement* stmt = SQLParser::parseSQL(sql);
|
Statement* stmt = SQLParser::parseSQLString(sql);
|
||||||
ASSERT(stmt != NULL);
|
ASSERT(stmt != NULL);
|
||||||
ASSERT(stmt->type == eSelect);
|
ASSERT(stmt->type == eSelect);
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ void SelectTest3(bool print) {
|
||||||
const char* sql = "SELECT name, AVG(age) FROM table GROUP BY name";
|
const char* sql = "SELECT name, AVG(age) FROM table GROUP BY name";
|
||||||
parse_count++;
|
parse_count++;
|
||||||
|
|
||||||
Statement* stmt = SQLParser::parseSQL(sql);
|
Statement* stmt = SQLParser::parseSQLString(sql);
|
||||||
|
|
||||||
if (parse_count != 1) conflicts++;
|
if (parse_count != 1) conflicts++;
|
||||||
parse_count--;
|
parse_count--;
|
||||||
|
@ -131,7 +131,7 @@ void Benchmark1(uint numRuns) {
|
||||||
|
|
||||||
start = clock();
|
start = clock();
|
||||||
for (uint n = 0; n < numRuns; ++n) {
|
for (uint n = 0; n < numRuns; ++n) {
|
||||||
Statement* stmt = SQLParser::parseSQL(sql);
|
Statement* stmt = SQLParser::parseSQLString(sql);
|
||||||
}
|
}
|
||||||
end = clock();
|
end = clock();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue