Loading...
Searching...
No Matches
Expression node
Grammar nodes

A node for parsing and evaluating expressions with operators. More...

Collaboration diagram for Expression node:

## Data Structures

struct | ec_node_expr_eval_ops
| Expression evaluation operations. More...

## Typedefs

typedef int(* | ec_node_expr_eval_var_t) (void **result, void *userctx, const struct ec_pnode *var)
| Callback function type for evaluating a variable.
typedef 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.
typedef 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.
typedef 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.
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)
| Callback function type for evaluating a parenthesized expression.
typedef void(* | ec_node_expr_eval_free_t) (void *result, void *userctx)
| Callback function type for freeing an evaluated result.

## Functions

struct ec_node * | ec_node_expr (const char *id)
| Create an expression 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.
int | ec_node_expr_add_bin_op (struct ec_node *gen_node, struct ec_node *op)
| Add a binary operator to an expression node.
int | ec_node_expr_add_pre_op (struct ec_node *gen_node, struct ec_node *op)
| Add a prefix operator to an expression node.
int | ec_node_expr_add_post_op (struct ec_node *gen_node, struct ec_node *op)
| Add a postfix operator to an expression node.
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.
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.

## Detailed Description

A node for parsing and evaluating expressions with operators.

Configuration Schema

No configuration schema.

## Typedef Documentation

## ec_node_expr_eval_var_t

typedef int(* ec_node_expr_eval_var_t) (void **result, void *userctx, const struct ec_pnode *var)

Callback function type for evaluating a variable.

Parameters

  result | On success, this pointer must be set by the user to point to a user structure describing the evaluated result.
  userctx | A user-defined context passed to all callback functions, which can be used to maintain a state or store global information.
  var | The parse result referencing the variable.

Returns
  0 on success (*result must be set), or -errno on error (*result is undefined).

Definition at line 32 of file node_expr.h.

## ec_node_expr_eval_pre_op_t

typedef 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.

Parameters

  result | On success, this pointer must be set by the user to point to a user structure describing the evaluated result.
  userctx | A user-defined context passed to all callback functions, which can be used to maintain a state or store global information.
  operand | The evaluated expression on which the operation should be applied.
  operator | The parse result referencing the operator.

Returns
  0 on success (*result must be set, operand is freed), or -errno on error (*result is undefined, operand is not freed).

Definition at line 51 of file node_expr.h.

## ec_node_expr_eval_post_op_t

typedef 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.

Same as ec_node_expr_eval_pre_op_t but for postfix operators.

Definition at line 63 of file node_expr.h.

## ec_node_expr_eval_bin_op_t

typedef 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.

Parameters

  result | On success, this pointer must be set by the user to point to a user structure describing the evaluated result.
  userctx | A user-defined context passed to all callback functions.
  operand1 | The evaluated left operand.
  operator | The parse result referencing the operator.
  operand2 | The evaluated right operand.

Returns
  0 on success (*result must be set, operands are freed), or -errno on error (*result is undefined, operands are not freed).

Definition at line 88 of file node_expr.h.

## ec_node_expr_eval_parenthesis_t

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)

Callback function type for evaluating a parenthesized expression.

Parameters

  result | On success, this pointer must be set by the user to point to a user structure describing the evaluated result.
  userctx | A user-defined context passed to all callback functions.
  open_paren | The parse result referencing the opening parenthesis.
  close_paren | The parse result referencing the closing parenthesis.
  value | The evaluated expression inside the parentheses.

Returns
  0 on success (*result must be set, value is freed), or -errno on error (*result is undefined, value is not freed).

Definition at line 114 of file node_expr.h.

## ec_node_expr_eval_free_t

typedef void(* ec_node_expr_eval_free_t) (void *result, void *userctx)

Callback function type for freeing an evaluated result.

Parameters

  result | The result to free.
  userctx | A user-defined context passed to all callback functions.

Definition at line 130 of file node_expr.h.

## Function Documentation

## ec_node_expr()

struct ec_node * ec_node_expr | ( | const char * | id | ) |

Create an expression node.

Parameters

  id | The node identifier.

Returns
  The node, or NULL on error (errno is set).

## 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.

Parameters

  gen_node | The expression node.
  val_node | The node matching values. It is consumed and will be freed when the parent is freed, or immediately on error.

Returns
  0 on success, -1 on error (errno is set).

## 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.

Parameters

  gen_node | The expression node.
  op | The operator node. It is consumed and will be freed when the parent is freed, or immediately on error.

Returns
  0 on success, -1 on error (errno is set).

## 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.

Parameters

  gen_node | The expression node.
  op | The operator node. It is consumed and will be freed when the parent is freed, or immediately on error.

Returns
  0 on success, -1 on error (errno is set).

## 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.

Parameters

  gen_node | The expression node.
  op | The operator node. It is consumed and will be freed when the parent is freed, or immediately on error.

Returns
  0 on success, -1 on error (errno is set).

## 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.

Parameters

  gen_node | The expression node.
  open | The opening parenthesis node. It is consumed and will be freed when the parent is freed, or immediately on error.
  close | The closing parenthesis node. It is consumed and will be freed when the parent is freed, or immediately on error.

Returns
  0 on success, -1 on error (errno is set).

## 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.

Parameters

  result | On success, this pointer will be set to the evaluated result.
  node | The expression node.
  parse | The parse tree to evaluate.
  ops | The evaluation callbacks.
  userctx | A user-defined context passed to all callbacks.

Returns
  0 on success, -1 on error (errno is set).