From e2b32aafb915323f8febc95cd8f87bdbe62a63b1 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Tue, 19 May 2015 16:26:52 +0000 Subject: [PATCH] improved symbol tokenization --- stix/lib/comp.c | 23 +++++++++++++++-------- stix/lib/main.c | 7 ++++--- stix/lib/memo.txt | 5 +++++ stix/lib/stix-prv.h | 1 + 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/stix/lib/comp.c b/stix/lib/comp.c index 40fd328..ee9860b 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -204,12 +204,8 @@ static STIX_INLINE int add_token_str (stix_t* stix, const stix_uch_t* ptr, stix_ i = STIX_ALIGN(i, TOKEN_NAME_ALIGN); - tmp = STIX_MMGR_REALLOC (stix->mmgr, stix->c->tok.name.ptr, STIX_SIZEOF(*ptr) * (i + 1)); - if (!tmp) - { - stix->errnum = STIX_ENOERR; - return -1; - } + tmp = stix_reallocmem (stix, stix->c->tok.name.ptr, STIX_SIZEOF(*ptr) * (i + 1)); + if (!tmp) return -1; stix->c->tok.name.ptr = tmp; stix->c->tok.name_capa = i; @@ -642,7 +638,9 @@ retry: } else if (is_alphachar(c)) { - keyword: + int colon_required = 0; + + nextword: do { ADD_TOKEN_CHAR (stix, c); @@ -655,7 +653,16 @@ retry: ADD_TOKEN_CHAR (stix, c); GET_CHAR_TO (stix, c); - if (is_alphachar(c)) goto keyword; + if (is_alphachar(c)) + { + colon_required =1; + goto nextword; + } + } + else if (colon_required) + { + set_syntax_error (stix, STIX_SYNERR_CLNMS, &stix->c->lxc.l, STIX_NULL); + return -1; } } else diff --git a/stix/lib/main.c b/stix/lib/main.c index 70192d1..d6aaed6 100644 --- a/stix/lib/main.c +++ b/stix/lib/main.c @@ -105,7 +105,7 @@ static STIX_INLINE stix_ssize_t read_input (stix_t* stix, stix_ioarg_t* arg) n = fread (&xtn->bchar_buf[xtn->bchar_len], STIX_SIZEOF(xtn->bchar_buf[0]), STIX_COUNTOF(xtn->bchar_buf) - xtn->bchar_len, arg->handle); if (n == 0) { - if (ferror(arg->handle)) + if (ferror((FILE*)arg->handle)) { stix_seterrnum (stix, STIX_EIOERR); return -1; @@ -131,7 +131,7 @@ static STIX_INLINE stix_ssize_t read_input (stix_t* stix, stix_ioarg_t* arg) static STIX_INLINE stix_ssize_t close_input (stix_t* stix, stix_ioarg_t* arg) { STIX_ASSERT (arg->handle != STIX_NULL); - fclose (arg->handle); + fclose ((FILE*)arg->handle); return 0; } @@ -186,7 +186,8 @@ static char* syntax_error_msg[] = "comment not closed", "string not closed", "no character after $", - "no valid character after #" + "no valid character after #", + "missing colon" }; int main (int argc, char* argv[]) diff --git a/stix/lib/memo.txt b/stix/lib/memo.txt index 1fdded5..d93362a 100644 --- a/stix/lib/memo.txt +++ b/stix/lib/memo.txt @@ -516,6 +516,11 @@ class Association -> revisit the Association class defined previsously. Revisiti ## function(#instance) ## instance method ## function ## instance method +## dcl(#class) a, b, c. ## short form +## dcl(#classinst) a, b, c +## fun(#class) + + ## var and fun are not keywords. they can be a method name or a variable name. ## Casing is not used to differentiate variable kinds like global local temporary etc. diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index 999fc1d..5f2925e 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -253,6 +253,7 @@ enum stix_synerrnum_t STIX_SYNERR_STRNC, /* string not closed */ STIX_SYNERR_CLTNT, /* character literal not terminated */ STIX_SYNERR_HLTNT, /* hased literal not terminated */ + STIX_SYNERR_CLNMS, /* colon missing */ }; typedef enum stix_synerrnum_t stix_synerrnum_t;