mirror of
				https://github.com/eledio-devices/thirdparty-tinyexpr.git
				synced 2025-10-31 00:32:38 +01:00 
			
		
		
		
	Merge branch 'dynfunc' of https://github.com/codeplea/tinyexpr
This commit is contained in:
		
							
								
								
									
										3
									
								
								test.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								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}, | ||||
| @@ -363,6 +365,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}, | ||||
|   | ||||
							
								
								
									
										10
									
								
								tinyexpr.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								tinyexpr.c
									
									
									
									
									
								
							| @@ -111,7 +111,7 @@ static const te_variable functions[] = { | ||||
|     {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 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; | ||||
|     if (!s->lookup) return 0; | ||||
|     for (i = 0; i < s->lookup_len; ++i) { | ||||
| @@ -176,8 +176,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; | ||||
| @@ -381,7 +381,7 @@ static te_expr *list(state *s) { | ||||
|  | ||||
|     while (s->type == TOK_SEP) { | ||||
|         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; | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user