MCPcopy Create free account
hub / github.com/crownengine/crown / base

Function base

3rdparty/tinyexpr/tinyexpr.c:310–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

308static te_expr *power(state *s);
309
310static te_expr *base(state *s) {
311 /* <base> = <constant> | <variable> | <function-0> {"(" ")"} | <function-1> <power> | <function-X> "(" <expr> {"," <expr>} ")" | "(" <list> ")" */
312 te_expr *ret;
313 int arity;
314
315 switch (TYPE_MASK(s->type)) {
316 case TOK_NUMBER:
317 ret = new_expr(TE_CONSTANT, 0);
318 CHECK_NULL(ret);
319
320 ret->value = s->value;
321 next_token(s);
322 break;
323
324 case TOK_VARIABLE:
325 ret = new_expr(TE_VARIABLE, 0);
326 CHECK_NULL(ret);
327
328 ret->bound = s->bound;
329 next_token(s);
330 break;
331
332 case TE_FUNCTION0:
333 case TE_CLOSURE0:
334 ret = new_expr(s->type, 0);
335 CHECK_NULL(ret);
336
337 ret->function = s->function;
338 if (IS_CLOSURE(s->type)) ret->parameters[0] = s->context;
339 next_token(s);
340 if (s->type == TOK_OPEN) {
341 next_token(s);
342 if (s->type != TOK_CLOSE) {
343 s->type = TOK_ERROR;
344 } else {
345 next_token(s);
346 }
347 }
348 break;
349
350 case TE_FUNCTION1:
351 case TE_CLOSURE1:
352 ret = new_expr(s->type, 0);
353 CHECK_NULL(ret);
354
355 ret->function = s->function;
356 if (IS_CLOSURE(s->type)) ret->parameters[1] = s->context;
357 next_token(s);
358 ret->parameters[0] = power(s);
359 CHECK_NULL(ret->parameters[0], te_free(ret));
360 break;
361
362 case TE_FUNCTION2: case TE_FUNCTION3: case TE_FUNCTION4:
363 case TE_FUNCTION5: case TE_FUNCTION6: case TE_FUNCTION7:
364 case TE_CLOSURE2: case TE_CLOSURE3: case TE_CLOSURE4:
365 case TE_CLOSURE5: case TE_CLOSURE6: case TE_CLOSURE7:
366 arity = ARITY(s->type);
367

Callers 1

powerFunction · 0.85

Calls 6

new_exprFunction · 0.85
next_tokenFunction · 0.85
powerFunction · 0.85
te_freeFunction · 0.85
exprFunction · 0.70
listFunction · 0.70

Tested by

no test coverage detected