From 3f1d5d255303f828201908867fb12a09fdb0e288 Mon Sep 17 00:00:00 2001 From: Lewis Van Winkle Date: Tue, 23 Feb 2016 17:36:15 -0600 Subject: [PATCH 1/2] Renamed find functions for clarity. --- tinyexpr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tinyexpr.c b/tinyexpr.c index 4f3bee2..fb56ef8 100644 --- a/tinyexpr.c +++ b/tinyexpr.c @@ -94,7 +94,7 @@ static const te_variable functions[] = { }; -static const te_variable *find_function(const char *name, int len) { +static const te_variable *find_builtin(const char *name, int len) { int imin = 0; int imax = sizeof(functions) / sizeof(te_variable) - 2; @@ -116,7 +116,7 @@ static const te_variable *find_function(const char *name, int len) { } -static const te_variable *find_var(const state *s, const char *name, int len) { +static const te_variable *find_lookup(const state *s, const char *name, int len) { int i; if (!s->lookup) return 0; for (i = 0; i < s->lookup_len; ++i) { @@ -158,8 +158,8 @@ void next_token(state *s) { start = s->next; while ((s->next[0] >= 'a' && s->next[0] <= 'z') || (s->next[0] >= '0' && s->next[0] <= '9')) s->next++; - const te_variable *var = find_var(s, start, s->next - start); - if (!var) var = find_function(start, s->next - start); + const te_variable *var = find_lookup(s, start, s->next - start); + if (!var) var = find_builtin(start, s->next - start); if (!var) { s->type = TOK_ERROR; From 31782a849f464eaa97b477ff31e4d0b5ef91ec3d Mon Sep 17 00:00:00 2001 From: Lewis Van Winkle Date: Wed, 24 Feb 2016 13:52:42 -0600 Subject: [PATCH 2/2] Bug fix in list grammar. --- test.c | 3 +++ tinyexpr.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test.c b/test.c index ffbfbf3..bf5344d 100644 --- a/test.c +++ b/test.c @@ -116,9 +116,11 @@ void test_results() { {"sqrt (100 * 100)", 100}, {"1,2", 2}, + {"1,2+1", 3}, {"1,2,3", 3}, {"(1,2),3", 3}, {"1,(2,3)", 3}, + {"-(1,(2,3))", -3}, {"2^2", 4}, {"pow(2,2)", 4}, @@ -358,6 +360,7 @@ void test_dynamic() { {"f+f", 10}, {"f+test0", 11}, {"test0+test0", 12}, + {"test0()+test0", 12}, {"test1 test0", 12}, {"test1 f", 10}, {"test1 x", 4}, diff --git a/tinyexpr.c b/tinyexpr.c index fb56ef8..b111537 100644 --- a/tinyexpr.c +++ b/tinyexpr.c @@ -361,7 +361,7 @@ static te_expr *list(state *s) { while (s->type == TOK_SEP) { next_token(s); - ret = new_expr(TE_FUNCTION2, ret, term(s)); + ret = new_expr(TE_FUNCTION2, ret, expr(s)); ret->f2 = comma; }