update lex for '.'
authoryu.dongliang <18588496441@163.com>
Sat, 28 Sep 2024 13:10:19 +0000 (21:10 +0800)
committeryu.dongliang <18588496441@163.com>
Sat, 28 Sep 2024 13:10:19 +0000 (21:10 +0800)
examples/number.c [new file with mode: 0644]
lex/scf_lex.c
lex/scf_lex.h
lex/scf_lex_util.c
parse/scf_dfa.c
parse/scf_dfa_block.c
util/scf_def.h
util/scf_string.c

diff --git a/examples/number.c b/examples/number.c
new file mode 100644 (file)
index 0000000..001937f
--- /dev/null
@@ -0,0 +1,9 @@
+int printf(const char* fmt, ...);
+
+int main()
+{
+       printf("0: %d, 10: %d, double: %lg, %lg, %lg, base16: %#lx, base8: %d, base2: %#lx\n",
+                       0, 1234, 3.14, .5, 1.1e-4, 0x7f1a, 0016, 0b110);
+
+       return 0;
+}
index 7b34b47af742bb373331ace6734ee240938f88db..71d8391a83116b7e2de4b202692760e4a0a32d64 100644 (file)
@@ -265,156 +265,75 @@ static int _lex_minus(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
        return 0;
 }
 
+
 static int _lex_number(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
 {
-       lex->pos++;
-
-       if ('0' == c0->c) {
-               scf_char_t* c1 = _lex_pop_char(lex);
-
-               if ('x' == c1->c || 'X' == c1->c) {
-                       // base 16
-                       scf_string_t* s = scf_string_cstr_len(c0->utf8, 1);
-
-                       scf_string_cat_cstr_len(s, c1->utf8, 1);
-                       lex->pos += 2;
-
-                       free(c1);
-                       free(c0);
-                       c1 = NULL;
-                       c0 = NULL;
+       scf_lex_word_t* w  = NULL;
+       scf_string_t*   s  = NULL;
+       scf_char_t*     c1 = NULL;
+       scf_char_t*     c2 = NULL;
 
-                       return _lex_number_base_16(lex, pword, s);
+       int ret = 0;
 
-               } else if ('.' == c1->c) {
-                       // double
-                       scf_string_t* s = scf_string_cstr_len(c0->utf8, 1);
+       if ('0' == c0->c) {
+               s = scf_string_cstr_len(c0->utf8, 1);
+               lex->pos++;
 
-                       scf_string_cat_cstr_len(s, c1->utf8, 1);
-                       lex->pos += 2;
+               free(c0);
+               c0 = NULL;
 
-                       free(c1);
-                       free(c0);
-                       c1 = NULL;
-                       c0 = NULL;
+               c1 = _lex_pop_char(lex);
 
-                       while (1) {
-                               scf_char_t* c2 = _lex_pop_char(lex);
+               scf_string_cat_cstr_len(s, c1->utf8, 1);
+               lex->pos++;
 
-                               if (c2->c >= '0' && c2->c <= '9') {
-                                       scf_string_cat_cstr_len(s, c2->utf8, 1);
-                                       lex->pos++;
+               switch (c1->c) {
+                       case 'x':
+                       case 'X': // base 16
+                               ret = _lex_number_base_16(lex, pword, s);
+                               break;
 
-                                       free(c2);
-                                       c2 = NULL;
+                       case 'b': // base 2
+                               ret = _lex_number_base_2(lex, pword, s);
+                               break;
 
-                               } else if ('.' == c2->c) {
-                                       scf_loge("too many '.' for number in file: %s, line: %d\n", lex->file->data, lex->nb_lines);
+                       case '.': // double
+                               ret = _lex_double(lex, pword, s);
+                               break;
 
-                                       free(c2);
-                                       c2 = NULL;
-                                       return -1;
+                       default:
+                               lex->pos--;
+                               s->data[--s->len] = '\0';
 
-                               } else {
-                                       _lex_push_char(lex, c2);
-                                       c2 = NULL;
+                               _lex_push_char(lex, c1);
 
-                                       scf_lex_word_t* w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_DOUBLE);
-                                       w->data.d = atof(s->data);
+                               if (c1->c < '0' || c1->c > '9') { // is 0
+                                       w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_INT);
+                                       w->data.u64 = atoi(s->data);
 
                                        w->text = s;
-                                       s = NULL;
-
-                                       *pword = w;
+                                       *pword  = w;
                                        return 0;
                                }
-                       }
-               } else {
-                       scf_string_t* s = scf_string_cstr_len(c0->utf8, 1);
-
-                       if (c1->c < '0' || c1->c > '9') {
-                               // is 0
-                               _lex_push_char(lex, c1);
-                               c1 = NULL;
-
-                               scf_lex_word_t* w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_INT);
-                               w->data.u64 = atoi(s->data);
-
-                               w->text = s;
-                               s = NULL;
-                               lex->pos++;
-
-                               *pword = w;
-                               return 0;
-                       }
-
-                       // base 8
-                       _lex_push_char(lex, c1);
-                       c1 = NULL;
-
-                       lex->pos++;
-
-                       return _lex_number_base_8(lex, pword, s);
-               }
-       } else {
-               // base 10
-               scf_string_t* s  = scf_string_cstr_len(c0->utf8, 1);
 
-               uint64_t value   = c0->c - '0';
-               int      nb_dots = 0;
-
-               free(c0);
-               c0 = NULL;
-
-               while (1) {
-                       scf_char_t* c1 = _lex_pop_char(lex);
-
-                       if (c1->c >= '0' && c1->c <= '9') {
-
-                               value = value * 10 + c1->c - '0';
-
-                               scf_string_cat_cstr_len(s, c1->utf8, 1);
-                               lex->pos++;
-
-                               free(c1);
-                               c1 = NULL;
-
-                       } else if ('.' == c1->c) {
-                               scf_string_cat_cstr_len(s, c1->utf8, 1);
-                               lex->pos++;
-
-                               free(c1);
+                               // base 8
                                c1 = NULL;
+                               return _lex_number_base_8(lex, pword, s);
+                               break;
+               };
 
-                               if (++nb_dots > 1) {
-                                       scf_loge("too many '.' for number in file: %s, line: %d\n", lex->file->data, lex->nb_lines);
-                                       return -1;
-                               }
-                       } else {
-                               _lex_push_char(lex, c1);
-                               c1 = NULL;
+               free(c1);
+               c1 = NULL;
+               return ret;
+       }
 
-                               scf_lex_word_t* w = NULL;
-
-                               if (nb_dots > 0) {
-                                       w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_DOUBLE);
-                                       w->data.d = atof(s->data);
-                               } else {
-                                       if (value & ~0xffffffffULL)
-                                               w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_I64);
-                                       else
-                                               w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_INT);
-                                       w->data.i64 = value;
-                               }
+       // base 10
+       s = scf_string_alloc();
 
-                               w->text = s;
-                               s = NULL;
+       _lex_push_char(lex, c0);
+       c0 = NULL;
 
-                               *pword = w;
-                               return 0;
-                       }
-               }
-       }
+       return _lex_number_base_10(lex, pword, s);
 }
 
 static int _lex_identity(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
@@ -486,60 +405,54 @@ static int _lex_identity(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
 
 static int _lex_char(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
 {
-       scf_lex_word_t* w = NULL;
-       scf_string_t*   s = scf_string_cstr_len(c0->utf8, 1);
-
-       scf_char_t* c1 = _lex_pop_char(lex);
+       scf_string_t*   s  = NULL;
+       scf_lex_word_t* w  = NULL;
+       scf_char_t*     c1 = _lex_pop_char(lex);
+       scf_char_t*     c2 = _lex_pop_char(lex);
+       scf_char_t*     c3;
 
        if ('\\' == c1->c) {
-               scf_char_t* c2 = _lex_pop_char(lex);
-               scf_char_t* c3 = _lex_pop_char(lex);
+               c3 = _lex_pop_char(lex);
 
                if ('\'' == c3->c) {
+                       s = scf_string_cstr_len(c0->utf8, 1);
+
                        scf_string_cat_cstr_len(s, c1->utf8, 1);
                        scf_string_cat_cstr_len(s, c2->utf8, c2->len);
                        scf_string_cat_cstr_len(s, c3->utf8, 1);
 
                        w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_CHAR);
-                       w->data.i64 = _find_escape_char(c2->c);
-                       lex->pos += 3 + c2->len;
 
-                       free(c3);
-                       free(c2);
-                       c3 = NULL;
-                       c2 = NULL;
-               } else {
+                       w->data.i64 = _find_escape_char(c2->c);
+                       lex->pos   += c2->len + 3;
+               } else
                        scf_loge("const char lost 2nd ' in file: %s, line: %d\n", lex->file->data, lex->nb_lines);
-                       return -1;
-               }
 
-       } else {
-               scf_char_t* c2 = _lex_pop_char(lex);
+               free(c3);
+               c3 = NULL;
 
-               if ('\'' == c2->c) {
-                       scf_string_cat_cstr_len(s, c1->utf8, c1->len);
-                       scf_string_cat_cstr_len(s, c2->utf8, 1);
+       } else if ('\'' == c2->c) {
+               s = scf_string_cstr_len(c0->utf8, 1);
 
-                       w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_CHAR);
-                       w->data.i64 = c1->c;
-                       lex->pos += 2 + c1->len;
+               scf_string_cat_cstr_len(s, c1->utf8, c1->len);
+               scf_string_cat_cstr_len(s, c2->utf8, 1);
 
-                       free(c2);
-                       c2 = NULL;
-               } else {
-                       scf_loge("const char lost 2nd ' in file: %s, line: %d\n", lex->file->data, lex->nb_lines);
-                       return -1;
-               }
-       }
+               w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_CHAR);
 
-       w->text = s;
-       s = NULL;
-       *pword = w;
+               w->data.i64 = c1->c;
+               lex->pos   += c1->len + 2;
+       } else
+               scf_loge("const char lost 2nd ' in file: %s, line: %d\n", lex->file->data, lex->nb_lines);
 
-       free(c1);
        free(c0);
-       c1 = NULL;
-       c0 = NULL;
+       free(c1);
+       free(c2);
+
+       if (!w)
+               return -1;
+
+       w->text = s;
+       *pword  = w;
        return 0;
 }
 
@@ -669,7 +582,44 @@ static int _lex_macro(scf_lex_t* lex)
        return 0;
 }
 
-static int __lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
+static void _lex_drop_to(scf_lex_t* lex, int c0, int c1)
+{
+       scf_char_t* c = NULL;
+
+       while (1) {
+               if (!c)
+                       c = _lex_pop_char(lex);
+
+               if (EOF == c->c) {
+                       _lex_push_char(lex, c);
+                       break;
+               }
+
+               int tmp = c->c;
+               free(c);
+               c = NULL;
+
+               if ('\n' == tmp) {
+                       lex->nb_lines++;
+                       lex->pos = 0;
+               }
+
+               if (c0 == tmp) {
+                       if (c1 < 0)
+                               break;
+
+                       c = _lex_pop_char(lex);
+
+                       if (c1 == c->c) {
+                               free(c);
+                               c = NULL;
+                               break;
+                       }
+               }
+       }
+}
+
+int __lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
 {
        scf_list_t*             l = NULL;
        scf_char_t*     c = NULL;
@@ -688,21 +638,18 @@ static int __lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
        while ('\n' == c->c || '\r' == c->c || '\t' == c->c || ' ' == c->c) {
 
                if ('\n' == c->c) {
+                       lex->nb_lines++;
+                       lex->pos = 0;
+
                        if (SCF_UTF8_LF == c->flag) {
                                w       = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_LF);
                                w->text = scf_string_cstr("LF");
                                *pword  = w;
 
-                               lex->nb_lines++;
-                               lex->pos = 0;
-
                                free(c);
                                c = NULL;
                                return 0;
                        }
-
-                       lex->nb_lines++;
-                       lex->pos = 0;
                } else
                        lex->pos++;
 
@@ -734,85 +681,32 @@ static int __lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
        }
 
        if ('/' == c->c) {
+               char c1 = '=';
+               int  t1 = SCF_LEX_WORD_DIV_ASSIGN;
 
                scf_char_t* c2 = _lex_pop_char(lex);
 
-               if ('/' == c2->c) {
-                       free(c);
-                       free(c2);
-                       c  = NULL;
-                       c2 = NULL;
-
-                       while (1) {
-                               c2 = _lex_pop_char(lex);
-
-                               if (EOF == c2->c) {
-                                       _lex_push_char(lex, c2);
-                                       break;
-                               }
-
-                               int tmp = c2->c;
-                               free(c2);
-                               c2 = NULL;
-
-                               if ('\n' == tmp) {
-                                       lex->nb_lines++;
-                                       lex->pos = 0;
-                                       break;
-                               }
-                       }
-
-                       return __lex_pop_word(lex, pword);
-
-               } else if ('*' == c2->c) {
-                       free(c);
-                       free(c2);
-                       c  = NULL;
-                       c2 = NULL;
-
-                       while (1) {
-                               c2 = _lex_pop_char(lex);
-
-                               if (EOF == c2->c) {
-                                       _lex_push_char(lex, c2);
-                                       break;
-                               }
-
-                               int tmp = c2->c;
-                               free(c2);
-                               c2 = NULL;
-
-                               if ('\n' == tmp) {
-                                       lex->nb_lines++;
-                                       lex->pos = 0;
-                                       continue;
-                               }
-
-                               if ('*' == tmp) {
-                                       c2  = _lex_pop_char(lex);
-
-                                       if ('/' == c2->c) {
-                                               free(c2);
-                                               c2 = NULL;
-                                               break;
-                                       }
-
-                                       _lex_push_char(lex, c2);
-                                       c2 = NULL;
-                               }
-                       }
+               switch (c2->c) {
+                       case '/':
+                               _lex_drop_to(lex, '\n', -1);
+                               break;
 
-                       return __lex_pop_word(lex, pword);
+                       case '*':
+                               _lex_drop_to(lex, '*', '/');
+                               break;
 
-               } else {
-                       _lex_push_char(lex, c2);
-                       c2 = NULL;
-               }
+                       default:
+                               _lex_push_char(lex, c2);
 
-               char c1 = '=';
-               int  t1 = SCF_LEX_WORD_DIV_ASSIGN;
+                               return _lex_op2_ll1(lex, pword, c, SCF_LEX_WORD_DIV, &c1, &t1, 1);
+                               break;
+               };
 
-               return _lex_op2_ll1(lex, pword, c, SCF_LEX_WORD_DIV, &c1, &t1, 1);
+               free(c);
+               free(c2);
+               c  = NULL;
+               c2 = NULL;
+               return __lex_pop_word(lex, pword);
        }
 
        if ('%' == c->c) {
index bdcf53926e7982800c65fe7fb461bf0fa45b25bf..ebb946af8ca3d805d6db3128b46d93c1a452900d 100644 (file)
@@ -55,11 +55,13 @@ int  scf_lex_close(scf_lex_t*   lex);
 void scf_lex_push_word(scf_lex_t* lex, scf_lex_word_t*   word);
 int  scf_lex_pop_word (scf_lex_t* lex, scf_lex_word_t** pword);
 
+int    __lex_pop_word (scf_lex_t* lex, scf_lex_word_t** pword);
 
 int _lex_number_base_16(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s);
 int _lex_number_base_10(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s);
 int _lex_number_base_8 (scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s);
 int _lex_number_base_2 (scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s);
+int _lex_double        (scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s);
 
 int _lex_dot    (scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0);
 
index edc2ede952472b776e54d53f4cf2d5e1b598177b..25a3aed3c445ab688d182400e97953f22ee5a589 100644 (file)
@@ -105,10 +105,12 @@ int _lex_op1_ll1(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0, int typ
 int _lex_op2_ll1(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0,
                int type0, char* chs, int* types, int n)
 {
+       scf_lex_word_t* w  = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, type0);
        scf_string_t*   s  = scf_string_cstr_len(c0->utf8, c0->len);
-       scf_lex_word_t* w  = NULL;
        scf_char_t*     c1 = _lex_pop_char(lex);
 
+       lex->pos += c0->len;
+
        int i;
        for (i = 0; i < n; i++) {
                if (chs[i] == c1->c)
@@ -117,18 +119,14 @@ int _lex_op2_ll1(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0,
 
        if (i < n) {
                scf_string_cat_cstr_len(s, c1->utf8, c1->len);
-               w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, types[i]);
-               lex->pos += c0->len + c1->len;
 
-               free(c1);
-               c1 = NULL;
+               w->type   = types[i];
+               lex->pos += c1->len;
 
-       } else {
+               free(c1);
+       } else
                _lex_push_char(lex, c1);
-               c1 = NULL;
-               w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, type0);
-               lex->pos += c0->len;
-       }
+       c1 = NULL;
 
        w->text = s;
        s = NULL;
@@ -459,11 +457,50 @@ int _lex_number_base_2(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s)
        }
 }
 
+int _lex_double(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s)
+{
+       scf_lex_word_t* w;
+       scf_char_t*     c2;
+
+       while (1) {
+               c2 = _lex_pop_char(lex);
+
+               if (c2->c >= '0' && c2->c <= '9') {
+                       scf_string_cat_cstr_len(s, c2->utf8, 1);
+                       lex->pos++;
+
+                       free(c2);
+                       c2 = NULL;
+
+               } else if ('.' == c2->c) {
+                       scf_loge("too many '.' for number in file: %s, line: %d\n", lex->file->data, lex->nb_lines);
+
+                       free(c2);
+                       c2 = NULL;
+                       return -1;
+
+               } else {
+                       _lex_push_char(lex, c2);
+                       c2 = NULL;
+                       break;
+               }
+       }
+
+       w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_DOUBLE);
+       w->data.d = atof(s->data);
+
+       w->text = s;
+       *pword  = w;
+       return 0;
+}
+
 int _lex_dot(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
 {
        scf_char_t*     c1 = _lex_pop_char(lex);
        scf_char_t*     c2 = NULL;
        scf_lex_word_t* w  = NULL;
+       scf_lex_word_t* w1 = NULL;
+       scf_lex_word_t* w2 = NULL;
        scf_string_t*   s  = scf_string_cstr_len(c0->utf8, c0->len);
 
        lex->pos += c0->len;
@@ -472,90 +509,77 @@ int _lex_dot(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
        c0 = NULL;
 
        if ('.' == c1->c) {
-               assert(1 == c1->len);
+               scf_string_cat_cstr_len(s, c1->utf8, 1);
+               lex->pos++;
+
+               free(c1);
+               c1 = NULL;
 
                c2 = _lex_pop_char(lex);
 
                if ('.' == c2->c) {
-                       assert(1 == c2->len);
-                       scf_string_cat_cstr_len(s, c1->utf8, 1);
                        scf_string_cat_cstr_len(s, c2->utf8, 1);
-                       lex->pos += 2;
+                       lex->pos++;
 
-                       free(c1);
                        free(c2);
-                       c1 = NULL;
                        c2 = NULL;
 
                        w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_VAR_ARGS);
-
                        w->text = s;
-                       *pword  = w;
-                       return 0;
-               }
-
-               _lex_push_char(lex, c2);
-               c2 = NULL;
-
-               scf_string_cat_cstr_len(s, c1->utf8, 1);
-               lex->pos++;
-
-               free(c1);
-               c1 = NULL;
+                       s = NULL;
+               } else {
+                       w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_RANGE);
+                       w->text = s;
+                       s = NULL;
 
-               w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_RANGE);
+                       _lex_push_char(lex, c2);
+                       c2 = NULL;
+               }
 
+       } else {
+               w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_DOT);
                w->text = s;
-               *pword  = w;
-               return 0;
-       }
+               s = NULL;
 
-       _lex_push_char(lex, c1);
-       c1 = NULL;
+               _lex_push_char(lex, c1);
+               c1 = NULL;
 
-       int numbers = 0;
-       int dots    = 1;
+               int ret = __lex_pop_word(lex, &w1);
+               if (ret < 0) {
+                       scf_lex_word_free(w);
+                       return ret;
+               }
 
-       while (1) {
-               c1 = _lex_pop_char(lex);
+               if (scf_lex_is_const(w1)) {
 
-               if ('0' <= c1->c && '9' >= c1->c)
-                       numbers++;
+                       ret = __lex_pop_word(lex, &w2);
+                       if (ret < 0) {
+                               scf_lex_word_free(w);
+                               scf_lex_word_free(w1);
+                               return ret;
+                       }
 
-               else if ('.' == c1->c)
-                       dots++;
-               else {
-                       _lex_push_char(lex, c1);
-                       c1 = NULL;
-                       break;
-               }
+                       scf_lex_push_word(lex, w2);
 
-               scf_string_cat_cstr_len(s, c1->utf8, 1);
-               lex->pos++;
+                       if (w2->type != SCF_LEX_WORD_ASSIGN) {
+                               w->type   = SCF_LEX_WORD_CONST_DOUBLE;
 
-               free(c1);
-               c1 = NULL;
-       }
+                               ret = scf_string_cat(w->text, w1->text);
+                               scf_lex_word_free(w1);
+                               w1 = NULL;
 
-       if (numbers  > 0) {
-               if (dots > 1) {
-                       scf_loge("\n");
-                       return -1;
-               }
+                               if (ret < 0) {
+                                       scf_lex_word_free(w);
+                                       return ret;
+                               }
 
-               w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_DOUBLE);
-               w->data.d = atof(s->data);
-
-       } else if (1 == dots) // dot .
-               w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_DOT);
-       else {
-               scf_loge("\n");
-               return -1;
+                               w->data.d = atof(w->text->data);
+                       } else
+                               scf_lex_push_word(lex, w1);
+               } else
+                       scf_lex_push_word(lex, w1);
        }
 
-       w->text = s;
-       s = NULL;
-
        *pword = w;
        return 0;
 }
index e9cbba651328cb4ab6152422f113dd6a01bb3eaf..8bc897b54e9e7dda8bb7095d2abadd8553450524 100644 (file)
@@ -299,7 +299,7 @@ static int _scf_dfa_node_parse_word(scf_dfa_t* dfa, scf_dfa_node_t* node, scf_ve
        int             ret = SCF_DFA_NEXT_WORD;
        scf_lex_word_t* w   = words->data[words->size - 1];
 
-       scf_logi("\033[32m%s->action(), w: %s, position: %d,%d\033[0m\n", node->name, w->text->data, w->line, w->pos);
+       scf_logi("\033[35m%s->action(), w: %s, position: %d,%d\033[0m\n", node->name, w->text->data, w->line, w->pos);
 
        if (node->action) {
 
@@ -320,13 +320,13 @@ static int _scf_dfa_node_parse_word(scf_dfa_t* dfa, scf_dfa_node_t* node, scf_ve
 #if 1
        scf_dfa_hook_t* h = dfa->hooks[SCF_DFA_HOOK_POST];
        while (h) {
-               scf_logd("\033[34m post hook: %s\033[0m\n", h->node->name);
+               scf_logd("\033[32m post hook: %s\033[0m\n", h->node->name);
                h = h->next;
        }
 
        h = dfa->hooks[SCF_DFA_HOOK_END];
        while (h) {
-               scf_logd("\033[36m end hook: %s\033[0m\n", h->node->name);
+               scf_logd("\033[32m end hook: %s\033[0m\n", h->node->name);
                h = h->next;
        }
        printf("\n");
@@ -339,14 +339,14 @@ static int _scf_dfa_node_parse_word(scf_dfa_t* dfa, scf_dfa_node_t* node, scf_ve
                scf_dfa_clear_hooks(&(dfa->hooks[SCF_DFA_HOOK_POST]), hook->next);
                hook = NULL;
 
-               scf_logi("\033[36m post hook: %s->action()\033[0m\n", hook_node->name);
+               scf_logi("\033[32m post hook: %s->action()\033[0m\n", hook_node->name);
 
                if (hook_node != node && hook_node->action) {
 
                        ret = hook_node->action(dfa, words, data);
 
                        if (SCF_DFA_SWITCH_TO == ret) {
-                               scf_logi("\033[36m post hook: switch to %s->%s\033[0m\n", node->name, hook_node->name);
+                               scf_logi("\033[32m post hook: switch to %s->%s\033[0m\n", node->name, hook_node->name);
 
                                node = hook_node;
                                ret = SCF_DFA_NEXT_WORD;
index 50b6432909119288c8769e66ce7a1613b1c66741..2afd08a2a670bf37a4c0890e6daa3bbfdf4f9457 100644 (file)
@@ -44,7 +44,7 @@ static int _block_action_entry(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _block_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse     = dfa->priv;
-       dfa_data_t* d         = data;
+       dfa_data_t*       d         = data;
        scf_stack_t*      s         = d->module_datas[dfa_module_block.index];
        dfa_block_data_t* bd        = scf_stack_top(s);
 
index d8dea71ed0ddf0b0620bf662b858b32899d1aa00..20b36da6364fe6005374ae108c71f82445c2d4fd 100644 (file)
@@ -60,16 +60,15 @@ static inline uint64_t scf_zero_extend(uint64_t src, int src_bits)
 
 #define scf_logi(fmt, ...) printf("%s(), %d, info: "fmt, __func__, __LINE__, ##__VA_ARGS__)
 
-#define scf_loge(fmt, ...) printf("%s(), %d, \033[31m error:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__)
-#define scf_logw(fmt, ...) printf("%s(), %d, \033[33m warning:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__)
+#define scf_loge(fmt, ...) printf("%s(), %d, \033[1;31m error:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__)
+#define scf_logw(fmt, ...) printf("%s(), %d, \033[1;33m warning:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__)
 
 #define SCF_CHECK_ERROR(cond, ret, fmt, ...) \
        do { \
                if (cond) { \
-                       printf("%s(), %d, \033[31m error:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__); \
+                       printf("%s(), %d, \033[1;31m error:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__); \
                        return ret; \
                } \
        } while (0)
 
 #endif
-
index d0ee3d0f1fff1982bc05377ce67cbb09bdb467ea..1da63667ab007305b07603df3b27d68921be1c1e 100644 (file)
@@ -2,7 +2,7 @@
 
 #define SCF_STRING_NUMBER_INC  4
 
-scf_string_t*  scf_string_alloc()
+scf_string_t* scf_string_alloc()
 {
        scf_string_t* s = malloc(sizeof(scf_string_t));
        if (!s)