Loading...
Searching...
No Matches
node_expr.h
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
*/
#pragma once
#include <ecoli/node.h>
typedef int (*ec_node_expr_eval_var_t)(void **result, void *userctx, const struct ec_pnode *var);
typedef int (*ec_node_expr_eval_pre_op_t)(
void **result,
void *userctx,
void *operand,
const struct ec_pnode *operator
);
typedef int (*ec_node_expr_eval_post_op_t)(
void **result,
void *userctx,
void *operand,
const struct ec_pnode *operator
);
typedef int (*ec_node_expr_eval_bin_op_t)(
void **result,
void *userctx,
void *operand1,
const struct ec_pnode *operator,
void * operand2
);
typedef int (*ec_node_expr_eval_parenthesis_t)(
void **result,
void *userctx,
const struct ec_pnode *open_paren,
const struct ec_pnode *close_paren,
void *value
);
typedef void (*ec_node_expr_eval_free_t)(void *result, void *userctx);
struct ec_node *ec_node_expr(const char *id);
int ec_node_expr_set_val_node(struct ec_node *gen_node, struct ec_node *val_node);
int ec_node_expr_add_bin_op(struct ec_node *gen_node, struct ec_node *op);
int ec_node_expr_add_pre_op(struct ec_node *gen_node, struct ec_node *op);
int ec_node_expr_add_post_op(struct ec_node *gen_node, struct ec_node *op);
int ec_node_expr_add_parenthesis(
struct ec_node *gen_node,
struct ec_node *open,
struct ec_node *close
);
struct ec_node_expr_eval_ops {
ec_node_expr_eval_var_t eval_var;
ec_node_expr_eval_pre_op_t eval_pre_op;
ec_node_expr_eval_post_op_t eval_post_op;
ec_node_expr_eval_bin_op_t eval_bin_op;
ec_node_expr_eval_parenthesis_t eval_parenthesis;
ec_node_expr_eval_free_t eval_free;
};
int ec_node_expr_eval(
void **result,
const struct ec_node *node,
struct ec_pnode *parse,
const struct ec_node_expr_eval_ops *ops,
void *userctx
);
ec_node_expr_add_post_op
int ec_node_expr_add_post_op(struct ec_node *gen_node, struct ec_node *op)
Add a postfix operator to an expression node.
ec_node_expr_eval
int ec_node_expr_eval(void **result, const struct ec_node *node, struct ec_pnode *parse, const struct ec_node_expr_eval_ops *ops, void *userctx)
Evaluate a parsed expression.
ec_node_expr_add_bin_op
int ec_node_expr_add_bin_op(struct ec_node *gen_node, struct ec_node *op)
Add a binary operator to an expression node.
ec_node_expr_eval_pre_op_t
int(* ec_node_expr_eval_pre_op_t)(void **result, void *userctx, void *operand, const struct ec_pnode *operator)
Callback function type for evaluating a prefix-operator.
Definition node_expr.h:51
ec_node_expr_eval_bin_op_t
int(* ec_node_expr_eval_bin_op_t)(void **result, void *userctx, void *operand1, const struct ec_pnode *operator, void *operand2)
Callback function type for evaluating a binary operator.
Definition node_expr.h:88
ec_node_expr_eval_free_t
void(* ec_node_expr_eval_free_t)(void *result, void *userctx)
Callback function type for freeing an evaluated result.
Definition node_expr.h:130
ec_node_expr_add_pre_op
int ec_node_expr_add_pre_op(struct ec_node *gen_node, struct ec_node *op)
Add a prefix operator to an expression node.
ec_node_expr_add_parenthesis
int ec_node_expr_add_parenthesis(struct ec_node *gen_node, struct ec_node *open, struct ec_node *close)
Add parentheses to an expression node.
ec_node_expr_eval_var_t
int(* ec_node_expr_eval_var_t)(void **result, void *userctx, const struct ec_pnode *var)
Callback function type for evaluating a variable.
Definition node_expr.h:32
ec_node_expr_eval_post_op_t
int(* ec_node_expr_eval_post_op_t)(void **result, void *userctx, void *operand, const struct ec_pnode *operator)
Callback function type for evaluating a postfix-operator.
Definition node_expr.h:63
ec_node_expr
struct ec_node * ec_node_expr(const char *id)
Create an expression node.
ec_node_expr_set_val_node
int ec_node_expr_set_val_node(struct ec_node *gen_node, struct ec_node *val_node)
Set the value (terminal) node for an expression.
ec_node_expr_eval_parenthesis_t
int(* ec_node_expr_eval_parenthesis_t)(void **result, void *userctx, const struct ec_pnode *open_paren, const struct ec_pnode *close_paren, void *value)
Callback function type for evaluating a parenthesized expression.
Definition node_expr.h:114
ec_node
struct ec_node * ec_node(const char *typename, const char *id)
Create a new node from its type name.
ec_pnode
struct ec_pnode * ec_pnode(const struct ec_node *node)
Create an empty parsing tree.
ec_node_expr_eval_ops
Expression evaluation operations.
Definition node_expr.h:217