minor changes. and extended token list

This commit is contained in:
Pedro 2014-10-23 11:41:44 +02:00
parent e886ae1644
commit 3c520b7aa4
8 changed files with 15 additions and 10 deletions

View File

@ -11,7 +11,7 @@ SQLParser::SQLParser() {
}
Statement* SQLParser::parseSQL(const char *text) {
Statement* SQLParser::parseSQLString(const char *text) {
Statement* stmt;
yyscan_t scanner;
YY_BUFFER_STATE state;

View File

@ -6,7 +6,7 @@
class SQLParser {
public:
static Statement* parseSQL(const char* sql);
static Statement* parseSQLString(const char* sql);
private:
SQLParser();

View File

@ -78,7 +78,10 @@ typedef void* yyscan_t;
/*********************************
** 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 <number> FLOAT
%token <uintnum> EQUALS NOTEQUALS LESS GREATER LESSEQ GREATEREQ

View File

@ -15,7 +15,7 @@ SQLParser::SQLParser() {
}
Statement* SQLParser::parseSQL(const char *text) {
Statement* SQLParser::parseSQLString(const char *text) {
yyscan_t scanner;
yylex_init(&scanner);

View File

@ -5,7 +5,7 @@
class SQLParser {
public:
static Statement* parseSQL(const char* sql);
static Statement* parseSQLString(const char* sql);
private:
SQLParser();

View File

@ -4,6 +4,8 @@
#include <vector>
#include <stdlib.h>
// TODO: try to replace the List wrapper by directly using std::vector
template <typename _T>
class List {
public:

View File

@ -19,7 +19,7 @@ int main(int argc, char *argv[]) {
char* sql = argv[n];
printf("\nEvaluating Statement \"%s\"\n", sql);
Statement* stmt = SQLParser::parseSQL(sql);
Statement* stmt = SQLParser::parseSQLString(sql);
if (stmt == NULL) {
fprintf(stderr, "Parsing of \"%s\" failed!\n", sql);

View File

@ -19,7 +19,7 @@ void SelectTest1() {
printf("Test: SelectTest1... "); fflush(stdout);
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->type == eSelect);
@ -49,7 +49,7 @@ void SelectTest2() {
printf("Test: SelectTest2... "); fflush(stdout);
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->type == eSelect);
@ -76,7 +76,7 @@ void SelectTest3(bool print) {
const char* sql = "SELECT name, AVG(age) FROM table GROUP BY name";
parse_count++;
Statement* stmt = SQLParser::parseSQL(sql);
Statement* stmt = SQLParser::parseSQLString(sql);
if (parse_count != 1) conflicts++;
parse_count--;
@ -131,7 +131,7 @@ void Benchmark1(uint numRuns) {
start = clock();
for (uint n = 0; n < numRuns; ++n) {
Statement* stmt = SQLParser::parseSQL(sql);
Statement* stmt = SQLParser::parseSQLString(sql);
}
end = clock();