tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit f28365aa84469fb7d5292c4fc1c794e4684f6bbc
parent d9f8f0e9046426baf3c4fac1acdca5dc95c858f5
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Thu, 27 Dec 2018 15:27:32 -0800

Error on no closing parenthesis

Diffstat:
tisp.c | 18++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tisp.c b/tisp.c @@ -137,6 +137,13 @@ issym(char c) } static int +isnum(char *str) +{ + return isdigit(*str) || (*str == '.' && isdigit(str[1])) || + ((*str == '-' || *str == '+') && (isdigit(str[1]) || str[1] == '.')); +} + +static int vals_eq(Val a, Val b) { if (a->t != b->t) @@ -493,7 +500,9 @@ read_list(Env env, Str str) Val *a = emalloc(sizeof(Val)), b; str->d++; skip_ws(str); - while (*str->d && *str->d != ')') { + while (*str->d != ')') { + if (!str->d[1]) + warn("reached end before closing ')'"); a = erealloc(a, (n+1) * sizeof(Val)); /* TODO realloc less */ if (!(a[n++] = tisp_read(env, str))) return NULL; @@ -506,13 +515,6 @@ read_list(Env env, Str str) return b; } -static int -isnum(char *str) -{ - return isdigit(*str) || (*str == '.' && isdigit(str[1])) || - ((*str == '-' || *str == '+') && (isdigit(str[1]) || str[1] == '.')); -} - Val tisp_read(Env env, Str str) {