WIP - introducing the BINOP token
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
48e6df233b
commit
d99a514278
@ -178,6 +178,7 @@ enum hcl_tok_type_t
|
||||
HCL_TOK_SELF,
|
||||
HCL_TOK_SUPER,
|
||||
|
||||
HCL_TOK_BINOP,
|
||||
HCL_TOK_IDENT,
|
||||
HCL_TOK_IDENT_DOTTED,
|
||||
HCL_TOK_IDENT_DOTTED_CLA,
|
||||
@ -628,6 +629,12 @@ struct hcl_flx_pi_t
|
||||
int is_cla; /* class-level accrssor. prefixed with self/super */
|
||||
};
|
||||
|
||||
typedef struct hcl_flx_binop_t hcl_flx_binop_t;
|
||||
struct hcl_flx_binop_t
|
||||
{
|
||||
hcl_oow_t _not_used;
|
||||
};
|
||||
|
||||
typedef struct hcl_flx_pn_t hcl_flx_pn_t;
|
||||
struct hcl_flx_pn_t
|
||||
{
|
||||
@ -685,6 +692,7 @@ enum hcl_flx_state_t
|
||||
HCL_FLX_HMARKED_IDENT, /* hash-marked identifier like #include, etc */
|
||||
HCL_FLX_HMARKED_NUMBER, /* hash-marked number - radixed number like #xABCD */
|
||||
HCL_FLX_PLAIN_IDENT, /* plain identifier */
|
||||
HCL_FLX_BINOP, /* binary operator */
|
||||
HCL_FLX_PLAIN_NUMBER, /* plain number */
|
||||
HCL_FLX_QUOTED_TOKEN, /* string, character */
|
||||
HCL_FLX_SIGNED_TOKEN, /* prefixed with + or - */
|
||||
@ -776,6 +784,7 @@ struct hcl_compiler_t
|
||||
hcl_flx_hb_t hb; /* #b ... */
|
||||
hcl_flx_hn_t hn; /* hash-marked number - radixed number */
|
||||
hcl_flx_pi_t pi; /* plain identifier */
|
||||
hcl_flx_binop_t binop; /* binary operator */
|
||||
hcl_flx_pn_t pn; /* plain number */
|
||||
hcl_flx_qt_t qt; /* quoted token */
|
||||
hcl_flx_st_t st; /* signed token */
|
||||
|
64
lib/read.c
64
lib/read.c
@ -181,12 +181,6 @@ static HCL_INLINE int is_linebreak (hcl_ooci_t c)
|
||||
return c == '\n'; /* make sure this is one of the space chars in is_spacechar() */
|
||||
}
|
||||
|
||||
static HCL_INLINE int is_alphachar (hcl_ooci_t c)
|
||||
{
|
||||
/* TODO: support full unicode */
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
static HCL_INLINE int is_digitchar (hcl_ooci_t c)
|
||||
{
|
||||
/* TODO: support full unicode */
|
||||
@ -199,11 +193,20 @@ static HCL_INLINE int is_xdigitchar (hcl_ooci_t c)
|
||||
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');
|
||||
}
|
||||
|
||||
#if 0
|
||||
static HCL_INLINE int is_alphachar (hcl_ooci_t c)
|
||||
{
|
||||
/* TODO: support full unicode */
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
|
||||
static HCL_INLINE int is_alnumchar (hcl_ooci_t c)
|
||||
{
|
||||
/* TODO: support full unicode */
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
|
||||
}
|
||||
#endif
|
||||
|
||||
static HCL_INLINE int is_delimchar (hcl_ooci_t c)
|
||||
{
|
||||
@ -213,6 +216,12 @@ static HCL_INLINE int is_delimchar (hcl_ooci_t c)
|
||||
c == '#' || c == '\"' || c == '\'' || c == '\\' || is_spacechar(c) || c == HCL_OOCI_EOF;
|
||||
}
|
||||
|
||||
static HCL_INLINE int is_binopchar (hcl_ooci_t c)
|
||||
{
|
||||
return c == '&' || c == '*' || c == '+' || c == '-' || c == '/' || c == '%' ||
|
||||
c == '<' || c == '>' || c == '=' || c == '@' || c == '|' || c == '~';
|
||||
}
|
||||
|
||||
/* TODO: remove this use the one in comp.c */
|
||||
static int copy_string_to (hcl_t* hcl, const hcl_oocs_t* src, hcl_oocs_t* dst, hcl_oow_t* dst_capa, int append, hcl_ooch_t add_delim)
|
||||
{
|
||||
@ -1526,6 +1535,7 @@ static int feed_process_token (hcl_t* hcl)
|
||||
frd->obj = hcl_makecnodebstrlit(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||
goto auto_xlist;
|
||||
|
||||
case HCL_TOK_BINOP: /* TODO: handle this specially as a binary operator */
|
||||
case HCL_TOK_IDENT:
|
||||
frd->obj = hcl_makecnodesymbol(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||
goto auto_xlist;
|
||||
@ -1747,6 +1757,7 @@ static int feed_continue_with_char (hcl_t* hcl, hcl_ooci_t c, hcl_flx_state_t st
|
||||
#define FLX_HB(hcl) (&((hcl)->c->feed.lx.u.hb))
|
||||
#define FLX_HN(hcl) (&((hcl)->c->feed.lx.u.hn))
|
||||
#define FLX_PI(hcl) (&((hcl)->c->feed.lx.u.pi))
|
||||
#define FLX_BINOP(hcl) (&((hcl)->c->feed.lx.u.binop))
|
||||
#define FLX_PN(hcl) (&((hcl)->c->feed.lx.u.pn))
|
||||
#define FLX_QT(hcl) (&((hcl)->c->feed.lx.u.qt))
|
||||
#define FLX_ST(hcl) (&((hcl)->c->feed.lx.u.st))
|
||||
@ -1793,6 +1804,11 @@ static HCL_INLINE void init_flx_pi (hcl_flx_pi_t* pi)
|
||||
HCL_MEMSET (pi, 0, HCL_SIZEOF(*pi));
|
||||
}
|
||||
|
||||
static HCL_INLINE void init_flx_binop (hcl_flx_binop_t* binop)
|
||||
{
|
||||
HCL_MEMSET (binop, 0, HCL_SIZEOF(*binop));
|
||||
}
|
||||
|
||||
static HCL_INLINE void init_flx_pn (hcl_flx_pn_t* pn)
|
||||
{
|
||||
HCL_MEMSET (pn, 0, HCL_SIZEOF(*pn));
|
||||
@ -1906,9 +1922,16 @@ static int flx_start (hcl_t* hcl, hcl_ooci_t c)
|
||||
goto consumed;
|
||||
|
||||
default:
|
||||
/* TODO: limit the identifier characters and cause syntax error for other characters.. */
|
||||
init_flx_pi (FLX_PI(hcl));
|
||||
FEED_CONTINUE (hcl, HCL_FLX_PLAIN_IDENT);
|
||||
if (is_binopchar(c))
|
||||
{
|
||||
init_flx_binop (FLX_BINOP(hcl));
|
||||
FEED_CONTINUE (hcl, HCL_FLX_BINOP);
|
||||
}
|
||||
else
|
||||
{
|
||||
init_flx_pi (FLX_PI(hcl));
|
||||
FEED_CONTINUE (hcl, HCL_FLX_PLAIN_IDENT);
|
||||
}
|
||||
goto not_consumed;
|
||||
}
|
||||
|
||||
@ -2377,6 +2400,28 @@ not_consumed:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int flx_binop (hcl_t* hcl, hcl_ooci_t c) /* identifier */
|
||||
{
|
||||
hcl_flx_binop_t* binop = FLX_BINOP(hcl);
|
||||
|
||||
if (is_binopchar(c))
|
||||
{
|
||||
ADD_TOKEN_CHAR (hcl, c);
|
||||
goto consumed;
|
||||
}
|
||||
else
|
||||
{
|
||||
FEED_WRAP_UP (hcl, HCL_TOK_BINOP);
|
||||
goto not_consumed;
|
||||
}
|
||||
|
||||
consumed:
|
||||
return 1;
|
||||
|
||||
not_consumed:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int flx_plain_number (hcl_t* hcl, hcl_ooci_t c) /* number */
|
||||
{
|
||||
hcl_flx_pn_t* pn = FLX_PN(hcl);
|
||||
@ -2729,6 +2774,7 @@ static int feed_char (hcl_t* hcl, hcl_ooci_t c)
|
||||
case HCL_FLX_HMARKED_IDENT: return flx_hmarked_ident(hcl, c);
|
||||
case HCL_FLX_HMARKED_NUMBER: return flx_hmarked_number(hcl, c);
|
||||
case HCL_FLX_PLAIN_IDENT: return flx_plain_ident(hcl, c);
|
||||
case HCL_FLX_BINOP: return flx_binop(hcl, c);
|
||||
case HCL_FLX_PLAIN_NUMBER: return flx_plain_number(hcl, c);
|
||||
case HCL_FLX_QUOTED_TOKEN: return flx_quoted_token(hcl, c);
|
||||
case HCL_FLX_SIGNED_TOKEN: return flx_signed_token(hcl, c);
|
||||
|
@ -22,6 +22,8 @@ check_ERRORS = \
|
||||
feed-5005.err \
|
||||
feed-5006.err \
|
||||
feed-5007.err \
|
||||
feed-5008.err \
|
||||
feed-5009.err \
|
||||
mlist-5001.err \
|
||||
var-5001.err \
|
||||
var-5002.err \
|
||||
|
@ -493,6 +493,8 @@ check_ERRORS = \
|
||||
feed-5005.err \
|
||||
feed-5006.err \
|
||||
feed-5007.err \
|
||||
feed-5008.err \
|
||||
feed-5009.err \
|
||||
mlist-5001.err \
|
||||
var-5001.err \
|
||||
var-5002.err \
|
||||
|
3
t/feed-5008.err
Normal file
3
t/feed-5008.err
Normal file
@ -0,0 +1,3 @@
|
||||
defun :: fun1() { ##ERROR: syntax error - function name not symbol in defun
|
||||
return 10;
|
||||
};
|
3
t/feed-5009.err
Normal file
3
t/feed-5009.err
Normal file
@ -0,0 +1,3 @@
|
||||
defun :* fun1() { ##ERROR: syntax error - function name not symbol in defun
|
||||
return 10;
|
||||
};
|
Loading…
Reference in New Issue
Block a user