diff --git a/src/Makefile b/src/Makefile index fd54de5..8ee7922 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,10 +1,7 @@ + # Makefile -# define which parser to use. Either bison or lemon -PARSER = bison - - -LIB_FILES = $(PARSER)/$(PARSER)_parser.cpp $(PARSER)/flex_lexer.cpp $(PARSER)/SQLParser.cpp lib/Expr.cpp lib/sqlhelper.cpp +LIB_FILES = parser/bison_parser.cpp parser/flex_lexer.cpp parser/SQLParser.cpp lib/Expr.cpp lib/sqlhelper.cpp TESTS_MAIN = sql_tests.cpp TESTS_BIN = bin/tests @@ -13,16 +10,16 @@ EXECUTION_MAIN = sql_execution.cpp EXECUTION_BIN = bin/sql_execution CC = g++ -CFLAGS = -g -O3 -Ilib/ -I./ -I$(PARSER)/ -std=c++11 -pthread +CFLAGS = -g -O3 -Ilib/ -I./ -Iparser/ -std=c++11 -pthread # release build is always using bison build: clean - make -C bison + make -C parser/ mkdir build/ cp lib/* build/ - cp bison/*.h build/ - cp bison/*.cpp build/ + cp parser/*.h build/ + cp parser/*.cpp build/ execution: $(LIB_FILES) $(EXECUTION_MAIN) @@ -33,15 +30,10 @@ tests: $(LIB_FILES) $(TESTS_MAIN) $(CC) $(CFLAGS) $(LIB_FILES) $(TESTS_MAIN) -o $(TESTS_BIN) -bison/bison_parser.cpp: - make -C bison/ - - -lemon/lemon_parser.cpp: - make -C lemon/ +parser/bison_parser.cpp: + make -C parser/ clean: rm -f *.o *~ $(EXECUTION_BIN) $(TESTS_BIN) - make clean -C bison/ - make clean -C lemon/ + make clean -C parser/ diff --git a/src/lemon/Makefile b/src/lemon/Makefile deleted file mode 100644 index 7fe7234..0000000 --- a/src/lemon/Makefile +++ /dev/null @@ -1,11 +0,0 @@ - -all: lemon_parser.c flex_lexer.c - -lemon_parser.c: lemon_parser.y - lemon lemon_parser.y - -flex_lexer.c: flex_lexer.l - flex --outfile=flex_lexer.c --header-file=flex_lexer.h flex_lexer.l - -clean: - rm -f lemon_parser.c flex_lexer.c lemon_parser.h flex_lexer.h lemon_parser.out \ No newline at end of file diff --git a/src/lemon/SQLParser.cpp b/src/lemon/SQLParser.cpp deleted file mode 100644 index 34f86bd..0000000 --- a/src/lemon/SQLParser.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "SQLParser.h" -#include "lemon_parser.h" -#include "flex_lexer.h" -#include - - - -void *ParseAlloc(void *(*mallocProc)(size_t)); -void ParseFree(void *p, void (*freeProc)(void*)); -void Parse(void *yyp, int yymajor, const char* text, Statement**); - - -SQLParser::SQLParser() { - fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n"); -} - - -Statement* SQLParser::parseSQLString(const char *text) { - yyscan_t scanner; - yylex_init(&scanner); - - // Scan the provided string - YY_BUFFER_STATE state = yy_scan_string(text, scanner); - - void* lemonParser = ParseAlloc(malloc); - int tokenCode; - Statement* result; - do { - tokenCode = yylex(scanner); - Parse(lemonParser, tokenCode, yyget_text(scanner), &result); - // printf("Token %d\n", tokenCode); - } while (tokenCode > 0); - - yy_delete_buffer(state, scanner); - yylex_destroy(scanner); - return result; -} \ No newline at end of file diff --git a/src/lemon/SQLParser.h b/src/lemon/SQLParser.h deleted file mode 100644 index 79b0156..0000000 --- a/src/lemon/SQLParser.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __SQLPARSER_H_ -#define __SQLPARSER_H_ - -#include "Statement.h" - -class SQLParser { -public: - static Statement* parseSQLString(const char* sql); - -private: - SQLParser(); -}; - - - -#endif \ No newline at end of file diff --git a/src/lemon/flex_lexer.l b/src/lemon/flex_lexer.l deleted file mode 100644 index a498aed..0000000 --- a/src/lemon/flex_lexer.l +++ /dev/null @@ -1,52 +0,0 @@ -%{ -/** - * flex_lexer.l file - */ - -#include "lemon_parser.h" -#include - -#define TOK(name) { return name; } -%} - - -%option reentrant -%option noyywrap - -%% - -[ \t\n]+ ; /* skip whitespace */ - -SELECT TOK(SELECT) -FROM TOK(FROM) -GROUP TOK(GROUP) -BY TOK(BY) -WHERE TOK(WHERE) -NOT TOK(NOT) -AND TOK(AND) -OR TOK(OR) - -"=" | -"<>" | -"<" | -">" | -"<=" | -">=" TOK(COMPARISON) - - -[-+*/(),.;] TOK(yytext[0]) - -[0-9]+ | -[0-9]+"."[0-9]* | -"."[0-9]* TOK(INTNUM) - -[A-Za-z][A-Za-z0-9_]* TOK(NAME) - - -'[^'\n]*' TOK(STRING) - -%% - -int yyerror(const char *msg) { - fprintf(stderr,"Error:%s\n",msg); return 0; -} \ No newline at end of file diff --git a/src/lemon/lemon_parser.y b/src/lemon/lemon_parser.y deleted file mode 100644 index 82e2bd0..0000000 --- a/src/lemon/lemon_parser.y +++ /dev/null @@ -1,24 +0,0 @@ -%include { - #include - #include - #include "lib/Statement.h" -} -%syntax_error { printf("Lemon syntax error\n"); } - -%extra_argument { Statement** result } -%token_type {const char*} -%type expr {Statement*} - -%left PLUS MINUS . - - -start ::= prog. - -prog ::= prog print NL . -prog ::= prog print . -prog ::= . - -print ::= expr(a) . { *result = a; } - -expr(a) ::= NUMBER . { a = new Statement(eSelect); } -expr(a) ::= expr(b) PLUS expr . { a = b; } diff --git a/src/lemon/token_def.h b/src/lemon/token_def.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/bison/Makefile b/src/parser/Makefile similarity index 100% rename from src/bison/Makefile rename to src/parser/Makefile diff --git a/src/bison/SQLParser.cpp b/src/parser/SQLParser.cpp similarity index 100% rename from src/bison/SQLParser.cpp rename to src/parser/SQLParser.cpp diff --git a/src/bison/SQLParser.h b/src/parser/SQLParser.h similarity index 100% rename from src/bison/SQLParser.h rename to src/parser/SQLParser.h diff --git a/src/bison/bison_parser.y b/src/parser/bison_parser.y similarity index 100% rename from src/bison/bison_parser.y rename to src/parser/bison_parser.y diff --git a/src/bison/flex_lexer.l b/src/parser/flex_lexer.l similarity index 100% rename from src/bison/flex_lexer.l rename to src/parser/flex_lexer.l