removed obsolete incomplete lemon sql parser code

This commit is contained in:
Pedro 2014-11-03 23:03:49 +01:00
parent 195f9f46eb
commit ae44960bad
12 changed files with 9 additions and 157 deletions

View File

@ -1,10 +1,7 @@
# Makefile # Makefile
# define which parser to use. Either bison or lemon LIB_FILES = parser/bison_parser.cpp parser/flex_lexer.cpp parser/SQLParser.cpp lib/Expr.cpp lib/sqlhelper.cpp
PARSER = bison
LIB_FILES = $(PARSER)/$(PARSER)_parser.cpp $(PARSER)/flex_lexer.cpp $(PARSER)/SQLParser.cpp lib/Expr.cpp lib/sqlhelper.cpp
TESTS_MAIN = sql_tests.cpp TESTS_MAIN = sql_tests.cpp
TESTS_BIN = bin/tests TESTS_BIN = bin/tests
@ -13,16 +10,16 @@ EXECUTION_MAIN = sql_execution.cpp
EXECUTION_BIN = bin/sql_execution EXECUTION_BIN = bin/sql_execution
CC = g++ 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 # release build is always using bison
build: clean build: clean
make -C bison make -C parser/
mkdir build/ mkdir build/
cp lib/* build/ cp lib/* build/
cp bison/*.h build/ cp parser/*.h build/
cp bison/*.cpp build/ cp parser/*.cpp build/
execution: $(LIB_FILES) $(EXECUTION_MAIN) execution: $(LIB_FILES) $(EXECUTION_MAIN)
@ -33,15 +30,10 @@ tests: $(LIB_FILES) $(TESTS_MAIN)
$(CC) $(CFLAGS) $(LIB_FILES) $(TESTS_MAIN) -o $(TESTS_BIN) $(CC) $(CFLAGS) $(LIB_FILES) $(TESTS_MAIN) -o $(TESTS_BIN)
bison/bison_parser.cpp: parser/bison_parser.cpp:
make -C bison/ make -C parser/
lemon/lemon_parser.cpp:
make -C lemon/
clean: clean:
rm -f *.o *~ $(EXECUTION_BIN) $(TESTS_BIN) rm -f *.o *~ $(EXECUTION_BIN) $(TESTS_BIN)
make clean -C bison/ make clean -C parser/
make clean -C lemon/

View File

@ -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

View File

@ -1,37 +0,0 @@
#include "SQLParser.h"
#include "lemon_parser.h"
#include "flex_lexer.h"
#include <stdio.h>
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;
}

View File

@ -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

View File

@ -1,52 +0,0 @@
%{
/**
* flex_lexer.l file
*/
#include "lemon_parser.h"
#include <stdlib.h>
#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;
}

View File

@ -1,24 +0,0 @@
%include {
#include <assert.h>
#include <cstdlib>
#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; }

View File