]> Nishi Git Mirror - dataworks.git/commitdiff
fixed grammar
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 19 Jun 2024 00:44:47 +0000 (00:44 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 19 Jun 2024 00:44:47 +0000 (00:44 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@356 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

Grammar/dw.l
Library/parser.c

index 51f960a58ea8418cf6370481aef601f0c16491fe..9d50a466175dea17fc208f0ea486f47df1220889 100644 (file)
 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);
+}
+<DQ>[^"]                       {
+       char* tmp = str;
+       str = __dw_strcat(tmp, yytext);
+       free(tmp);
+}
+<DQ>\\\"                       {
+       char* tmp = str;
+       str = __dw_strcat(tmp, yytext + 1);
+       free(tmp);
+}
+<DQ>\"                         {
+       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);
+}
+<SQ>[^']                       {
+       char* tmp = str;
+       str = __dw_strcat(tmp, yytext);
+       free(tmp);
+}
+<SQ>\\\'                       {
+       char* tmp = str;
+       str = __dw_strcat(tmp, yytext + 1);
+       free(tmp);
+}
+<SQ>\'                         {
+       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); }
index 8d5a963cd6e11404a9f7c34a66284a86be656a15..4aca253a971b0efe8829e8a1240843c7d6af011b 100644 (file)
@@ -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) {