This commit is contained in:
EvilPudding
2016-02-24 20:19:05 +00:00
2 changed files with 8 additions and 5 deletions

3
test.c
View File

@@ -116,9 +116,11 @@ void test_results() {
{"sqrt (100 * 100)", 100}, {"sqrt (100 * 100)", 100},
{"1,2", 2}, {"1,2", 2},
{"1,2+1", 3},
{"1,2,3", 3}, {"1,2,3", 3},
{"(1,2),3", 3}, {"(1,2),3", 3},
{"1,(2,3)", 3}, {"1,(2,3)", 3},
{"-(1,(2,3))", -3},
{"2^2", 4}, {"2^2", 4},
{"pow(2,2)", 4}, {"pow(2,2)", 4},
@@ -363,6 +365,7 @@ void test_dynamic() {
{"f+f", 10}, {"f+f", 10},
{"f+test0", 11}, {"f+test0", 11},
{"test0+test0", 12}, {"test0+test0", 12},
{"test0()+test0", 12},
{"test1 test0", 12}, {"test1 test0", 12},
{"test1 f", 10}, {"test1 f", 10},
{"test1 x", 4}, {"test1 x", 4},

View File

@@ -111,7 +111,7 @@ static const te_variable functions[] = {
{0} {0}
}; };
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 imin = 0;
int imax = sizeof(functions) / sizeof(te_variable) - 2; int imax = sizeof(functions) / sizeof(te_variable) - 2;
@@ -133,7 +133,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; int i;
if (!s->lookup) return 0; if (!s->lookup) return 0;
for (i = 0; i < s->lookup_len; ++i) { for (i = 0; i < s->lookup_len; ++i) {
@@ -176,8 +176,8 @@ void next_token(state *s) {
start = s->next; start = s->next;
while ((s->next[0] >= 'a' && s->next[0] <= 'z') || (s->next[0] >= '0' && s->next[0] <= '9')) 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); const te_variable *var = find_lookup(s, start, s->next - start);
if (!var) var = find_function(start, s->next - start); if (!var) var = find_builtin(start, s->next - start);
if (!var) { if (!var) {
s->type = TOK_ERROR; s->type = TOK_ERROR;
@@ -381,7 +381,7 @@ static te_expr *list(state *s) {
while (s->type == TOK_SEP) { while (s->type == TOK_SEP) {
next_token(s); next_token(s);
ret = new_expr(TE_FUN | 2, (const te_expr*[]){ret, term(s)}); ret = new_expr(TE_FUN | 2, (const te_expr*[]){ret, expr(s)});
ret->fun.f2 = comma; ret->fun.f2 = comma;
} }