| 334 | static te_expr *power(state *s); |
| 335 | |
| 336 | static te_expr *base(state *s) { |
| 337 | /* <base> = <constant> | <variable> | <function-0> {"(" ")"} | <function-1> <power> | <function-X> "(" <expr> {"," <expr>} ")" | "(" <list> ")" */ |
| 338 | te_expr *ret; |
| 339 | int arity; |
| 340 | |
| 341 | switch (TYPE_MASK(s->type)) { |
| 342 | case TOK_NUMBER: |
| 343 | ret = new_expr(TE_CONSTANT, 0); |
| 344 | CHECK_NULL(ret); |
| 345 | |
| 346 | ret->value = s->value; |
| 347 | next_token(s); |
| 348 | break; |
| 349 | |
| 350 | case TOK_VARIABLE: |
| 351 | ret = new_expr(TE_VARIABLE, 0); |
| 352 | CHECK_NULL(ret); |
| 353 | |
| 354 | ret->bound = s->bound; |
| 355 | next_token(s); |
| 356 | break; |
| 357 | |
| 358 | case TE_FUNCTION0: |
| 359 | case TE_CLOSURE0: |
| 360 | ret = new_expr(s->type, 0); |
| 361 | CHECK_NULL(ret); |
| 362 | |
| 363 | ret->function = s->function; |
| 364 | if (IS_CLOSURE(s->type)) ret->parameters[0] = s->context; |
| 365 | next_token(s); |
| 366 | if (s->type == TOK_OPEN) { |
| 367 | next_token(s); |
| 368 | if (s->type != TOK_CLOSE) { |
| 369 | s->type = TOK_ERROR; |
| 370 | } else { |
| 371 | next_token(s); |
| 372 | } |
| 373 | } |
| 374 | break; |
| 375 | |
| 376 | case TE_FUNCTION1: |
| 377 | case TE_CLOSURE1: |
| 378 | ret = new_expr(s->type, 0); |
| 379 | CHECK_NULL(ret); |
| 380 | |
| 381 | ret->function = s->function; |
| 382 | if (IS_CLOSURE(s->type)) ret->parameters[1] = s->context; |
| 383 | next_token(s); |
| 384 | ret->parameters[0] = power(s); |
| 385 | CHECK_NULL(ret->parameters[0], te_free(ret)); |
| 386 | break; |
| 387 | |
| 388 | case TE_FUNCTION2: case TE_FUNCTION3: case TE_FUNCTION4: |
| 389 | case TE_FUNCTION5: case TE_FUNCTION6: case TE_FUNCTION7: |
| 390 | case TE_CLOSURE2: case TE_CLOSURE3: case TE_CLOSURE4: |
| 391 | case TE_CLOSURE5: case TE_CLOSURE6: case TE_CLOSURE7: |
| 392 | arity = ARITY(s->type); |
| 393 | |