tisp

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

commit a9a8fc00f773543bcd569ba40f843d728b84d637
parent f5e7aa1f1e1d2f98a75bf61b1e24aeeeb1106b2e
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Thu, 12 Apr 2018 18:34:48 -0700

Add + prefix to indicate positive numbers

Diffstat:
t/simple/self.expect | 2++
t/simple/self.tsp | 2++
tisp.c | 12++++++++----
3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/t/simple/self.expect b/t/simple/self.expect @@ -6,6 +6,8 @@ -4 -83 0 +4 +123 "foo" "foo bar" t diff --git a/t/simple/self.tsp b/t/simple/self.tsp @@ -6,6 +6,8 @@ -4 -083 -0 ++4 ++123 "foo" "foo bar" t diff --git a/tisp.c b/tisp.c @@ -24,7 +24,8 @@ skip_spaces(Str str) static int issym(char c) { - return BETWEEN(c, 'a', 'z') || strchr("+-*/=?", c); + return BETWEEN(c, 'a', 'z') || BETWEEN(c, 'A', 'Z') || + BETWEEN(c, '0', '9') || strchr("+-*/=?", c); } static int @@ -274,9 +275,12 @@ mk_list(int n, Val *a) static int read_int(Str str) { int ret, sign = 1; - if (*str->d == '-') { - str->d++; + switch (*str->d) { + case '-': sign = -1; + case '+': + str->d++; + break; } for (ret = 0; isdigit(*str->d); str->d++) ret = ret * 10 + *str->d - '0'; @@ -343,7 +347,7 @@ Val tisp_read(Str str) { skip_spaces(str); - if (isdigit(*str->d) || (*str->d == '-' && isdigit(str->d[1]))) + if (isdigit(*str->d) || ((*str->d == '-' || *str->d == '+') && isdigit(str->d[1]))) return read_num(str); if (*str->d == '"') return read_str(str);