MIDAS
Loading...
Searching...
No Matches
tinyexpr.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  te_expr
 
struct  te_variable
 

Typedefs

typedef struct te_expr te_expr
 
typedef struct te_variable te_variable
 

Enumerations

enum  {
  TE_VARIABLE = 0 , TE_FUNCTION0 = 8 , TE_FUNCTION1 , TE_FUNCTION2 ,
  TE_FUNCTION3 , TE_FUNCTION4 , TE_FUNCTION5 , TE_FUNCTION6 ,
  TE_FUNCTION7 , TE_CLOSURE0 = 16 , TE_CLOSURE1 , TE_CLOSURE2 ,
  TE_CLOSURE3 , TE_CLOSURE4 , TE_CLOSURE5 , TE_CLOSURE6 ,
  TE_CLOSURE7 , TE_FLAG_PURE = 32
}
 

Functions

double te_interp (const char *expression, int *error)
 
te_exprte_compile (const char *expression, const te_variable *variables, int var_count, int *error)
 
double te_eval (const te_expr *n)
 
void te_print (const te_expr *n)
 
void te_free (te_expr *n)
 

Typedef Documentation

◆ te_expr

◆ te_variable

Enumeration Type Documentation

◆ anonymous enum

Enumerator
TE_VARIABLE 
TE_FUNCTION0 
TE_FUNCTION1 
TE_FUNCTION2 
TE_FUNCTION3 
TE_FUNCTION4 
TE_FUNCTION5 
TE_FUNCTION6 
TE_FUNCTION7 
TE_CLOSURE0 
TE_CLOSURE1 
TE_CLOSURE2 
TE_CLOSURE3 
TE_CLOSURE4 
TE_CLOSURE5 
TE_CLOSURE6 
TE_CLOSURE7 
TE_FLAG_PURE 

Definition at line 43 of file tinyexpr.h.

43 {
44 TE_VARIABLE = 0,
45
46 TE_FUNCTION0 = 8,
54
55 TE_CLOSURE0 = 16,
63
64 TE_FLAG_PURE = 32
65};
@ TE_CLOSURE6
Definition tinyexpr.h:61
@ TE_FUNCTION2
Definition tinyexpr.h:48
@ TE_FUNCTION1
Definition tinyexpr.h:47
@ TE_FUNCTION6
Definition tinyexpr.h:52
@ TE_FLAG_PURE
Definition tinyexpr.h:64
@ TE_FUNCTION4
Definition tinyexpr.h:50
@ TE_CLOSURE2
Definition tinyexpr.h:57
@ TE_FUNCTION5
Definition tinyexpr.h:51
@ TE_FUNCTION0
Definition tinyexpr.h:46
@ TE_CLOSURE5
Definition tinyexpr.h:60
@ TE_FUNCTION7
Definition tinyexpr.h:53
@ TE_FUNCTION3
Definition tinyexpr.h:49
@ TE_CLOSURE7
Definition tinyexpr.h:62
@ TE_CLOSURE4
Definition tinyexpr.h:59
@ TE_CLOSURE0
Definition tinyexpr.h:55
@ TE_CLOSURE3
Definition tinyexpr.h:58
@ TE_CLOSURE1
Definition tinyexpr.h:56
@ TE_VARIABLE
Definition tinyexpr.h:44

Function Documentation

◆ te_compile()

te_expr * te_compile ( const char expression,
const te_variable variables,
int  var_count,
int error 
)

Definition at line 665 of file tinyexpr.c.

665 {
666 state s;
667 s.start = s.next = expression;
668 s.lookup = variables;
670
671 next_token(&s);
672 te_expr *root = list(&s);
673
674 if (s.type != TOK_END) {
675 te_free(root);
676 if (error) {
677 *error = (s.next - s.start);
678 if (*error == 0)
679 *error = 1;
680 }
681 return 0;
682 } else {
683 optimize(root);
684 if (error)
685 *error = 0;
686 return root;
687 }
688}
INT optimize
Definition mfe.cxx:48
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
int lookup_len
Definition tinyexpr.c:82
int type
Definition tinyexpr.c:73
const te_variable * lookup
Definition tinyexpr.c:81
const char * start
Definition tinyexpr.c:71
const char * next
Definition tinyexpr.c:72
void te_free(te_expr *n)
Definition tinyexpr.c:128
@ TOK_END
Definition tinyexpr.c:59
void next_token(state *s)
Definition tinyexpr.c:253
static te_expr * list(state *s)
Definition tinyexpr.c:567
Here is the call graph for this function:
Here is the caller graph for this function:

◆ te_eval()

double te_eval ( const te_expr n)

Definition at line 583 of file tinyexpr.c.

583 {
584 if (!n)
585 return NAN;
586
587 switch (TYPE_MASK(n->type)) {
588 case TE_CONSTANT: return n->value;
589 case TE_VARIABLE: return *n->bound;
590
591 case TE_FUNCTION0:
592 case TE_FUNCTION1:
593 case TE_FUNCTION2:
594 case TE_FUNCTION3:
595 case TE_FUNCTION4:
596 case TE_FUNCTION5:
597 case TE_FUNCTION6:
598 case TE_FUNCTION7:
599 switch (ARITY(n->type)) {
600 case 0: return TE_FUN(void)();
601 case 1: return TE_FUN(double)(M(0));
602 case 2: return TE_FUN(double, double)(M(0), M(1));
603 case 3: return TE_FUN(double, double, double)(M(0), M(1), M(2));
604 case 4: return TE_FUN(double, double, double, double)(M(0), M(1), M(2), M(3));
605 case 5: return TE_FUN(double, double, double, double, double)(M(0), M(1), M(2), M(3), M(4));
606 case 6: return TE_FUN(double, double, double, double, double, double)(M(0), M(1), M(2), M(3), M(4), M(5));
607 case 7: return TE_FUN(double, double, double, double, double, double, double)(M(0), M(1), M(2), M(3), M(4), M(5), M(6));
608 default: return NAN;
609 }
610
611 case TE_CLOSURE0:
612 case TE_CLOSURE1:
613 case TE_CLOSURE2:
614 case TE_CLOSURE3:
615 case TE_CLOSURE4:
616 case TE_CLOSURE5:
617 case TE_CLOSURE6:
618 case TE_CLOSURE7:
619 switch (ARITY(n->type)) {
620 case 0: return TE_FUN(void *)(n->parameters[0]);
621 case 1: return TE_FUN(void *, double)(n->parameters[1], M(0));
622 case 2: return TE_FUN(void *, double, double)(n->parameters[2], M(0), M(1));
623 case 3: return TE_FUN(void *, double, double, double)(n->parameters[3], M(0), M(1), M(2));
624 case 4: return TE_FUN(void *, double, double, double, double)(n->parameters[4], M(0), M(1), M(2), M(3));
625 case 5: return TE_FUN(void *, double, double, double, double, double)(n->parameters[5], M(0), M(1), M(2), M(3), M(4));
626 case 6: return TE_FUN(void *, double, double, double, double, double, double)(n->parameters[6], M(0), M(1), M(2), M(3), M(4), M(5));
627 case 7: return TE_FUN(void *, double, double, double, double, double, double, double)(n->parameters[7], M(0), M(1), M(2), M(3), M(4), M(5), M(6));
628 default: return NAN;
629 }
630
631 default: return NAN;
632 }
633}
DWORD n[4]
Definition mana.cxx:247
#define TE_FUN(...)
Definition tinyexpr.c:580
#define TYPE_MASK(TYPE)
Definition tinyexpr.c:85
@ TE_CONSTANT
Definition tinyexpr.c:68
#define NAN
Definition tinyexpr.c:47
#define ARITY(TYPE)
Definition tinyexpr.c:90
#define M(e)
Definition tinyexpr.c:581
Here is the caller graph for this function:

◆ te_free()

void te_free ( te_expr n)

Definition at line 128 of file tinyexpr.c.

128 {
129 if (!n)
130 return;
132 free(n);
133}
void te_free_parameters(te_expr *n)
Definition tinyexpr.c:107
Here is the call graph for this function:
Here is the caller graph for this function:

◆ te_interp()

double te_interp ( const char expression,
int error 
)

Definition at line 690 of file tinyexpr.c.

690 {
691 te_expr *n = te_compile(expression, 0, 0, error);
692 double ret;
693 if (n) {
694 ret = te_eval(n);
695 te_free(n);
696 } else {
697 ret = NAN;
698 }
699 return ret;
700}
double te_eval(const te_expr *n)
Definition tinyexpr.c:583
te_expr * te_compile(const char *expression, const te_variable *variables, int var_count, int *error)
Definition tinyexpr.c:665
Here is the call graph for this function:
Here is the caller graph for this function:

◆ te_print()

void te_print ( const te_expr n)

Definition at line 739 of file tinyexpr.c.

739 {
740 pn(n, 0);
741}
static void pn(const te_expr *n, int depth)
Definition tinyexpr.c:702
Here is the call graph for this function: