From 0f9d219bf2f9c24f24014499c3ef6ee50909e054 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sun, 16 Jan 2022 01:22:17 +0000 Subject: Add negative numbers to lexer and printer --- lexer.c | 6 +++++- print.c | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lexer.c b/lexer.c index 5318924..76cffc8 100644 --- a/lexer.c +++ b/lexer.c @@ -85,10 +85,14 @@ lexline(Rune *line) stmt->toks[stmt->ntoks].operator.dyadic = 1; stmt->toks[stmt->ntoks].operator.code = p-primdyadopnames; offset++; - }else if(isdigitrune(line[offset])){ + }else if(isdigitrune(line[offset]) || (line[offset] == L'¯' && isdigitrune(line[offset+1]))){ char buf[64]; char *p = buf; int floating = 0; + if(line[offset] == L'¯'){ + *p++ = '-'; + offset++; + } get_digits: while(isdigitrune(line[offset])) p += runetochar(p, &line[offset++]); diff --git a/print.c b/print.c index ae29a01..15e5f2a 100644 --- a/print.c +++ b/print.c @@ -93,6 +93,8 @@ pparray(Array *a) *p-- = 0; /* remove trailing 0's */ } } + if(elemstrs[i][0] == '-' && (a->type == AtypeInt || a->type == AtypeFloat)) + elemstrs[i][0] = L'¯'; } int lastdim = a->rank ? a->shape[a->rank-1] : 1; -- cgit v1.2.3