MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / factor

Function factor

extern/tinyexpr/tinyexpr.c:416–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

414
415#ifdef TE_POW_FROM_RIGHT
416static te_expr *factor(state *s) {
417 /* <factor> = <power> {"^" <power>} */
418 te_expr *ret = power(s);
419
420 int neg = 0;
421 te_expr *insertion = 0;
422
423 if (ret->type == (TE_FUNCTION1 | TE_FLAG_PURE) && ret->function == negate) {
424 te_expr *se = ret->parameters[0];
425 free(ret);
426 ret = se;
427 neg = 1;
428 }
429
430 while (s->type == TOK_INFIX && (s->function == pow)) {
431 te_fun2 t = s->function;
432 next_token(s);
433
434 if (insertion) {
435 /* Make exponentiation go right-to-left. */
436 te_expr *insert = NEW_EXPR(TE_FUNCTION2 | TE_FLAG_PURE, insertion->parameters[1], power(s));
437 insert->function = t;
438 insertion->parameters[1] = insert;
439 insertion = insert;
440 } else {
441 ret = NEW_EXPR(TE_FUNCTION2 | TE_FLAG_PURE, ret, power(s));
442 ret->function = t;
443 insertion = ret;
444 }
445 }
446
447 if (neg) {
448 ret = NEW_EXPR(TE_FUNCTION1 | TE_FLAG_PURE, ret);
449 ret->function = negate;
450 }
451
452 return ret;
453}
454#else
455static te_expr *factor(state *s) {
456 /* <factor> = <power> {"^" <power>} */

Callers 3

operator*Method · 0.85
operator*Method · 0.85
termFunction · 0.85

Calls 2

powerFunction · 0.85
next_tokenFunction · 0.85

Tested by

no test coverage detected