From: nishi Date: Wed, 19 Jun 2024 00:44:47 +0000 (+0000) Subject: fixed grammar X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=df6452bc213f635b1db0e5bde3101e1f39743ab0;p=dataworks.git fixed grammar git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@356 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Grammar/dw.l b/Grammar/dw.l index 51f960a..9d50a46 100644 --- a/Grammar/dw.l +++ b/Grammar/dw.l @@ -36,25 +36,59 @@ extern YYSTYPE yylval; double __dw_atof(const char* str); +char* __dw_strcat(const char* a, const char* b); +char* str = NULL; %} -%% +%x DQ SQ -["][^"]*["] { - yylval.node.string = strdup(yytext + 1); - yylval.node.string[strlen(yylval.node.string) - 1] = 0; +%% +\" { + str = malloc(1); + str[0] = 0; + BEGIN(DQ); +} +[^"] { + char* tmp = str; + str = __dw_strcat(tmp, yytext); + free(tmp); +} +\\\" { + char* tmp = str; + str = __dw_strcat(tmp, yytext + 1); + free(tmp); +} +\" { + yylval.node.string = strdup(str); yylval.node.nodes = NULL; yylval.node.ident = NULL; - yylval.node.number = 123123; yylval.node.type = 'S'; + BEGIN(INITIAL); + free(str); return (STRING); } -['][^']*['] { - yylval.node.string = strdup(yytext + 1); - yylval.node.string[strlen(yylval.node.string) - 1] = 0; +\' { + str = malloc(1); + str[0] = 0; + BEGIN(SQ); +} +[^'] { + char* tmp = str; + str = __dw_strcat(tmp, yytext); + free(tmp); +} +\\\' { + char* tmp = str; + str = __dw_strcat(tmp, yytext + 1); + free(tmp); +} +\' { + yylval.node.string = strdup(str); yylval.node.nodes = NULL; yylval.node.ident = NULL; yylval.node.type = 'S'; + BEGIN(INITIAL); + free(str); return (STRING); } [ \t]*#.* { return (COMMENT); } diff --git a/Library/parser.c b/Library/parser.c index 8d5a963..4aca253 100644 --- a/Library/parser.c +++ b/Library/parser.c @@ -107,7 +107,15 @@ bool __dw_print_node(struct Node* node, bool top) { fflush(stdout); return true; } else if(node->string != NULL) { - printf("\"%s\"", node->string); + printf("\""); + fflush(stdout); + int i; + for(i = 0; node->string[i] != 0; i++){ + if(node->string[i] == '"') printf("\\"); + printf("%c", node->string[i]); + fflush(stdout); + } + printf("\""); fflush(stdout); return true; } else if(node->ident != NULL) {