diff --git a/hawk/lib/parse.c b/hawk/lib/parse.c index 565712d9..722ef9d7 100644 --- a/hawk/lib/parse.c +++ b/hawk/lib/parse.c @@ -153,6 +153,7 @@ enum tok_t /* == end reserved words == */ TOK_IDENT, + TOK_CHAR, TOK_INT, TOK_FLT, 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); } +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) { 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: return parse_primary_ident(hawk, xloc); + case TOK_CHAR: + return parse_primary_char(hawk, xloc); + case TOK_INT: return parse_primary_int(hawk, xloc); @@ -6833,12 +6862,16 @@ retry: SET_TOKEN_TYPE (hawk, tok, TOK_STR); 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 { try_get_symbols: diff --git a/hawk/lib/tree.c b/hawk/lib/tree.c index e4e37739..1e36744f 100644 --- a/hawk/lib/tree.c +++ b/hawk/lib/tree.c @@ -1383,6 +1383,12 @@ void hawk_clrpt (hawk_t* hawk, hawk_nde_t* tree) break; } + case HAWK_NDE_CHAR: + { + hawk_freemem (hawk, p); + break; + } + case HAWK_NDE_INT: { if (((hawk_nde_int_t*)p)->str)