more code to support the character literal

This commit is contained in:
hyung-hwan 2020-12-05 18:55:05 +00:00
parent 342e01f5b4
commit dfb7b2aa2d
2 changed files with 43 additions and 4 deletions

View File

@ -153,6 +153,7 @@ enum tok_t
/* == end reserved words == */ /* == end reserved words == */
TOK_IDENT, TOK_IDENT,
TOK_CHAR,
TOK_INT, TOK_INT,
TOK_FLT, TOK_FLT,
TOK_STR, TOK_STR,
@ -4660,6 +4661,31 @@ static HAWK_INLINE int isfnname (hawk_t* hawk, const hawk_oocs_t* name)
return isfunname(hawk, name, HAWK_NULL); return isfunname(hawk, name, HAWK_NULL);
} }
static hawk_nde_t* parse_primary_char (hawk_t* hawk, const hawk_loc_t* xloc)
{
hawk_nde_char_t* nde;
nde = (hawk_nde_char_t*)hawk_callocmem (hawk, HAWK_SIZEOF(*nde));
if (HAWK_UNLIKELY(!nde))
{
ADJERR_LOC (hawk, xloc);
return HAWK_NULL;
}
nde->type = HAWK_NDE_CHAR;
nde->loc = *xloc;
nde->val = HAWK_OOECS_CHAR(hawk->tok.name, 0);
if (get_token(hawk) <= -1) goto oops;
return (hawk_nde_t*)nde;
oops:
HAWK_ASSERT (nde != HAWK_NULL);
hawk_freemem (hawk, nde);
return HAWK_NULL;
}
static hawk_nde_t* parse_primary_int (hawk_t* hawk, const hawk_loc_t* xloc) static hawk_nde_t* parse_primary_int (hawk_t* hawk, const hawk_loc_t* xloc)
{ {
hawk_nde_int_t* nde; hawk_nde_int_t* nde;
@ -5093,6 +5119,9 @@ static hawk_nde_t* parse_primary_nopipe (hawk_t* hawk, const hawk_loc_t* xloc)
case TOK_IDENT: case TOK_IDENT:
return parse_primary_ident(hawk, xloc); return parse_primary_ident(hawk, xloc);
case TOK_CHAR:
return parse_primary_char(hawk, xloc);
case TOK_INT: case TOK_INT:
return parse_primary_int(hawk, xloc); return parse_primary_int(hawk, xloc);
@ -6833,12 +6862,16 @@ retry:
SET_TOKEN_TYPE (hawk, tok, TOK_STR); SET_TOKEN_TYPE (hawk, tok, TOK_STR);
if (get_string(hawk, c, '\\', 0, 0, 0, tok) <= -1) return -1; if (get_string(hawk, c, '\\', 0, 0, 0, tok) <= -1) return -1;
} }
#if 0 else if (c == '\'')
else if (c == '\''))
{ {
/* TODO: character literal */ SET_TOKEN_TYPE (hawk, tok, TOK_CHAR);
if (get_string(hawk, c, '\\', 0, 0, 0, tok) <= -1) return -1;
if (HAWK_OOECS_LEN(tok->name) != 1)
{
hawk_seterrfmt (hawk, &tok->loc, HAWK_ELXCHR, HAWK_T("invalid character token"));
return -1;
}
} }
#endif
else else
{ {
try_get_symbols: try_get_symbols:

View File

@ -1383,6 +1383,12 @@ void hawk_clrpt (hawk_t* hawk, hawk_nde_t* tree)
break; break;
} }
case HAWK_NDE_CHAR:
{
hawk_freemem (hawk, p);
break;
}
case HAWK_NDE_INT: case HAWK_NDE_INT:
{ {
if (((hawk_nde_int_t*)p)->str) if (((hawk_nde_int_t*)p)->str)