From: nishi Date: Tue, 4 Jun 2024 12:02:08 +0000 (+0000) Subject: bison sucks, byacc supremacy X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=ee6fb0504b453704fb42e86854758ec1834fd053;p=dataworks.git bison sucks, byacc supremacy git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@147 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Grammar/dw.y b/Grammar/dw.y index 8026ad4..1222225 100644 --- a/Grammar/dw.y +++ b/Grammar/dw.y @@ -44,6 +44,7 @@ %{ void parser_process(struct Node* node); +char* __dw_strdup(const char* a); %} %% @@ -81,8 +82,8 @@ arguments $$.nodes[0]->nodes = NULL; $$.nodes[0]->ident = NULL; $$.nodes[0]->string = NULL; - if($1.ident != NULL) $$.nodes[0]->ident = strdup($1.ident); - if($1.string != NULL) $$.nodes[0]->string = strdup($1.string); + if($1.ident != NULL) $$.nodes[0]->ident = __dw_strdup($1.ident); + if($1.string != NULL) $$.nodes[0]->string = __dw_strdup($1.string); if($1.nodes != NULL) $$.nodes[0]->nodes = $1.nodes; $$.nodes[1] = NULL; } @@ -96,8 +97,8 @@ arguments $$.nodes[i]->nodes = NULL; $$.nodes[i]->ident = NULL; $$.nodes[i]->string = NULL; - if($3.ident != NULL) $$.nodes[i]->ident = strdup($3.ident); - if($3.string != NULL) $$.nodes[i]->string = strdup($3.string); + if($3.ident != NULL) $$.nodes[i]->ident = __dw_strdup($3.ident); + if($3.string != NULL) $$.nodes[i]->string = __dw_strdup($3.string); if($3.nodes != NULL) $$.nodes[i]->nodes = $3.nodes; $$.nodes[i + 1] = NULL; free(old_nodes); @@ -123,6 +124,7 @@ command #if defined(YYBISON) const char* yaccver = "GNU Bison " YYBISON_VERSION; +#error "GNU Bison does not work. Use Berkeley Yacc." #elif defined(YYBYACC) #define XSTR(x) #x #define STR(x) XSTR(x) diff --git a/Library/dw_parser.h b/Library/dw_parser.h index 0cf57d2..7bdd7a7 100644 --- a/Library/dw_parser.h +++ b/Library/dw_parser.h @@ -42,7 +42,9 @@ extern "C" { #include -int __dw_parser_parse(const char* str, bool top); +#include "../Grammar/dw.tab.h" + +struct Node* __dw_parser_parse(const char* str, bool top); #ifdef __cplusplus } diff --git a/Library/exec.c b/Library/exec.c index 2b49b09..46a59ea 100644 --- a/Library/exec.c +++ b/Library/exec.c @@ -40,10 +40,10 @@ struct dataworks_db_result* dataworks_database_execute_code(struct dataworks_db* r->error = false; r->value = NULL; - int err; - if((err = __dw_parser_parse(code, dolog)) != DW_ERR_SUCCESS) { + struct Node* node; + if((node = __dw_parser_parse(code, dolog)) == NULL) { r->error = true; - r->errnum = err; + r->errnum = DW_ERR_PARSER_FAIL; } return r; diff --git a/Library/parser.c b/Library/parser.c index cba1b29..31160f1 100644 --- a/Library/parser.c +++ b/Library/parser.c @@ -67,7 +67,8 @@ void parser_process(struct Node* node) { } } -int __dw_parser_parse(const char* str, bool top) { +struct Node* __dw_parser_parse(const char* str, bool top) { + extern YYSTYPE yyval; #ifdef PARSER_DEBUG yydebug = 1; #endif @@ -75,12 +76,10 @@ int __dw_parser_parse(const char* str, bool top) { void* buf = yy_scan_string(str); if(yyparse() != 0) { yy_delete_buffer(buf); - return DW_ERR_PARSER_FAIL; - } else { - extern YYSTYPE yyval; - parser_process(&yyval.node); + return NULL; } + parser_process(&yyval.node); yy_delete_buffer(buf); - return DW_ERR_SUCCESS; + return &yyval.node; } diff --git a/common-decl.mk b/common-decl.mk index 73166eb..23e9eef 100644 --- a/common-decl.mk +++ b/common-decl.mk @@ -10,7 +10,7 @@ RANLIB = ranlib WINDRES = windres CFLAGS = -g -std=c99 -D_DEFAULT_SOURCE $(DEBUGFLAGS) LDFLAGS = -L`pwd`/Library -YFLAGS = -d -t +YFLAGS = -d -t -y LFLAGS = LIBS = LIB_PREFIX = lib