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

Function base

extern/tinyexpr/tinyexpr.c:300–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

attr.hFile · 0.85
powerFunction · 0.85

Calls 5

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

Tested by

no test coverage detected