From: nishi Date: Tue, 4 Jun 2024 03:16:37 +0000 (+0000) Subject: fix yacc X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=cb2446c44234ec7fc72d4525780e490038dcff69;p=dataworks.git fix yacc git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@141 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Grammar/dw.y b/Grammar/dw.y index 2f1a505..7f48ad5 100644 --- a/Grammar/dw.y +++ b/Grammar/dw.y @@ -59,6 +59,8 @@ single_argument arguments : single_argument | arguments ',' single_argument + | SPACE + | ; ; command diff --git a/Library/database.c b/Library/database.c index 5f77c7e..b0770a4 100644 --- a/Library/database.c +++ b/Library/database.c @@ -38,7 +38,7 @@ const char sig[3] = {0x7f, 'D', 'W'}; -const char* dw_errors[] = {"Success", "Used already", "File open fail", "Invalid signature", "Invalid version", "Parser returned NULL", "Cannot call non-method", "Unknown method", "Insufficient arguments", "Too many arguments", "Not used", "Too many tables", "Database not selected"}; +const char* dw_errors[] = {"Success", "Used already", "File open fail", "Invalid signature", "Invalid version", "Parser returned NULL", "Cannot call non-method", "Unknown method", "Insufficient arguments", "Too many arguments", "Not used", "Too many tables", "Database not selected", "Parser fail"}; #ifdef M_I86 #define BUFSIZE 128 diff --git a/Library/dataworks.c b/Library/dataworks.c index 4058122..dd6e7a0 100644 --- a/Library/dataworks.c +++ b/Library/dataworks.c @@ -29,6 +29,7 @@ #include "dataworks.h" #include +#include const char* dataworks_version = "0.0.0"; const char* dataworks_compile_date = __DATE__; @@ -70,7 +71,7 @@ const char* dataworks_get_copyright(void) { return dataworks_copyright; } int yywrap() { return 1; } -int yyerror(const char* err) { return 0; } +int yyerror(const char* err) { fprintf(stderr, "Parser error: %s\n", err); return 0; } bool dataworks_get_if_supported(void) { #ifdef SUPPORTED diff --git a/Library/dw_database.h b/Library/dw_database.h index 52c8b2e..906436b 100644 --- a/Library/dw_database.h +++ b/Library/dw_database.h @@ -163,6 +163,13 @@ enum DW_ERRORS { * */ DW_ERR_DATABASE_NOT_SELECTED, + + /** + * @~english + * @brief Parser fail + * + */ + DW_ERR_PARSER_FAIL, }; /** diff --git a/Library/exec.c b/Library/exec.c index 4509696..deb1e51 100644 --- a/Library/exec.c +++ b/Library/exec.c @@ -40,7 +40,11 @@ struct dataworks_db_result* dataworks_database_execute_code(struct dataworks_db* r->error = false; r->value = NULL; - __dw_parser_parse(code, dolog); + int err; + if((err = __dw_parser_parse(code, dolog)) != DW_ERR_SUCCESS){ + r->error = true; + r->errnum = err; + } return r; } diff --git a/Library/parser.c b/Library/parser.c index 866dcea..20d7701 100644 --- a/Library/parser.c +++ b/Library/parser.c @@ -43,6 +43,11 @@ extern void yy_delete_buffer(void* buffer); int __dw_parser_parse(const char* str, bool top) { void* buf = yy_scan_string(str); - yyparse(); + if(yyparse() != 0){ + yy_delete_buffer(buf); + return DW_ERR_PARSER_FAIL; + } yy_delete_buffer(buf); + + return DW_ERR_SUCCESS; }