Astaroth  3.1
Scalable Multi-GPU Stencil Computations
Loading...
Searching...
No Matches
tinyexpr.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Zlib
2/*
3 * TINYEXPR - Tiny recursive descent parser and evaluation engine in C
4 *
5 * Copyright (c) 2015-2020 Lewis Van Winkle
6 *
7 * http://CodePlea.com
8 *
9 * This software is provided 'as-is', without any express or implied
10 * warranty. In no event will the authors be held liable for any damages
11 * arising from the use of this software.
12 *
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
16 *
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software
19 * in a product, an acknowledgement in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
24 */
25
26#ifndef TINYEXPR_H
27#define TINYEXPR_H
28
29#include "func_define.h"
30
32
33typedef struct te_expr {
34 int type;
35 union {
36 double value;
37 const double *bound;
38 const void *function;
39 };
40 void* parameters[1];
41} te_expr;
42
43
44enum {
46
49
52
54};
55
56typedef struct te_variable {
57 const char *name;
58 const void *address;
59 int type;
60 void *context;
62
63
64
65/* Parses the input expression, evaluates it, and frees it. */
66/* Returns NaN on error. */
67double te_interp(const char *expression, int *error);
68
69/* Parses the input expression and binds variables. */
70/* Returns NULL on error. */
71te_expr *te_compile(const char *expression, const te_variable *variables, int var_count, int *error);
72
73/* Evaluates the expression. */
74double te_eval(const te_expr *n);
75
76/* Prints debugging information on the syntax tree. */
77void te_print(const te_expr *n);
78
79/* Frees the expression. */
80/* This is safe to call on NULL pointers. */
82
84
85#endif /*TINYEXPR_H*/
#define AC_BEGIN_C_DECLARATIONS
Definition func_define.h:14
#define AC_END_C_DECLARATIONS
Definition func_define.h:15
Definition tinyexpr.h:33
int type
Definition tinyexpr.h:34
double value
Definition tinyexpr.h:36
const double * bound
Definition tinyexpr.h:37
const void * function
Definition tinyexpr.h:38
void * parameters[1]
Definition tinyexpr.h:40
Definition tinyexpr.h:56
const void * address
Definition tinyexpr.h:58
void * context
Definition tinyexpr.h:60
const char * name
Definition tinyexpr.h:57
int type
Definition tinyexpr.h:59
double te_interp(const char *expression, int *error)
void te_free(te_expr *n)
double te_eval(const te_expr *n)
te_expr * te_compile(const char *expression, const te_variable *variables, int var_count, int *error)
@ TE_CLOSURE6
Definition tinyexpr.h:51
@ TE_FUNCTION2
Definition tinyexpr.h:47
@ TE_FUNCTION1
Definition tinyexpr.h:47
@ TE_FUNCTION6
Definition tinyexpr.h:48
@ TE_FLAG_PURE
Definition tinyexpr.h:53
@ TE_FUNCTION4
Definition tinyexpr.h:48
@ TE_CLOSURE2
Definition tinyexpr.h:50
@ TE_FUNCTION5
Definition tinyexpr.h:48
@ TE_FUNCTION0
Definition tinyexpr.h:47
@ TE_CLOSURE5
Definition tinyexpr.h:51
@ TE_FUNCTION7
Definition tinyexpr.h:48
@ TE_FUNCTION3
Definition tinyexpr.h:47
@ TE_CLOSURE7
Definition tinyexpr.h:51
@ TE_CLOSURE4
Definition tinyexpr.h:51
@ TE_CLOSURE0
Definition tinyexpr.h:50
@ TE_CLOSURE3
Definition tinyexpr.h:50
@ TE_CLOSURE1
Definition tinyexpr.h:50
@ TE_VARIABLE
Definition tinyexpr.h:45
void te_print(const te_expr *n)
error
Definition vecs.h:234