Simple example using the mathematical expression evaluator and its features.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define DUMMY_EXPR \
"$(sum, $1 + $2), x = 2.3, y = 4.5, mul(6.7, sum(x, y)) + 0.11"
__SG_UNUSED const char *identifier) {
if (!args)
return NAN;
}
int main(int argc, const char *argv[]) {
{.
func = my_mul, .identifier =
"mul", .cls = NULL},
{.func = NULL, .identifier = NULL, .cls = NULL},
};
const char *s = argc == 2 ? argv[1] : DUMMY_EXPR;
int ret;
if (ret == 0)
else {
printf(
"%*s^--- Error near here.\n",
sg_expr_near(expr),
"");
}
return EXIT_SUCCESS;
}
int sg_expr_compile(struct sg_expr *expr, const char *str, size_t len, struct sg_expr_extension *extensions)
void sg_expr_free(struct sg_expr *expr)
struct sg_expr * sg_expr_new(void) __attribute__((malloc))
const char * sg_expr_strerror(struct sg_expr *expr)
double sg_expr_eval(struct sg_expr *expr)
int sg_expr_near(struct sg_expr *expr)
double sg_expr_arg(struct sg_expr_argument *args, int index)
sg_expr_func func
Definition sagui.h:2265