Allow whitespace at end of expression.

This commit is contained in:
Lewis Van Winkle
2016-08-22 19:09:21 -05:00
parent 4c1015ab7f
commit ec7dc3a28a
2 changed files with 6 additions and 5 deletions

1
test.c
View File

@@ -37,6 +37,7 @@ typedef struct {
void test_results() { void test_results() {
test_case cases[] = { test_case cases[] = {
{"1", 1},
{"1 ", 1}, {"1 ", 1},
{"(1)", 1}, {"(1)", 1},

View File

@@ -172,13 +172,13 @@ static double comma(double a, double b) {return b;}
void next_token(state *s) { void next_token(state *s) {
s->type = TOK_NULL; s->type = TOK_NULL;
do {
if (!*s->next){ if (!*s->next){
s->type = TOK_END; s->type = TOK_END;
return; return;
} }
do {
/* Try reading a number. */ /* Try reading a number. */
if ((s->next[0] >= '0' && s->next[0] <= '9') || s->next[0] == '.') { if ((s->next[0] >= '0' && s->next[0] <= '9') || s->next[0] == '.') {
s->value = strtod(s->next, (char**)&s->next); s->value = strtod(s->next, (char**)&s->next);