improved symbol tokenization

This commit is contained in:
hyunghwan.chung 2015-05-19 16:26:52 +00:00
parent 3db3a02a7a
commit e2b32aafb9
4 changed files with 25 additions and 11 deletions

View File

@ -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

View File

@ -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[])

View File

@ -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.

View File

@ -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;