Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
eval(3m)		     MBA Library Functions		      eval(3m)

NAME
       eval - evaluate simple arithmetic expressions

SYNOPSIS
       #include	<mba/eval.h>

       struct eval *eval_new(symlook_fn	symlook, void *context);
       void eval_del(void *eval);
       int eval_expression(struct eval *eval, const tchar *expr, const tchar *elim, unsigned long *result);

DESCRIPTION
       The  eval(3m)  module will evaluate simple arithmentic expressions con-
       sisting of integers, symbols for	which the provided symlook_fn  returns
       an integer, and any of the operators |_^+-*/().OperatorPrecedence

       Operator	precedence is roughly the same as the C	language.

	       ( )  higher
	       * /
	       + -
	      ^	& | lower

       Prefixing integer tokens	with minus '-' to indicate a negative value is
       currently not supported.

       new    The eval_new function creates and	returns	a new  context	object
	      for  evaluating expressions. The symlook parameter is defined as
	      follows:

	      typedef int (*symlook_fn)(const tchar *name, unsigned long *val, void *context);

       The symlook_fn function will be called to resolve any non-numeric  sym-
       bols  and should	place the value	identified by name into	val and	return
       0. If the symbol	is not found -1	should be returned.

       The eval_new function can be used repeatedly to evaluate	any number  of
       expressions before being	destroyed with the eval_del function. The con-
       text parameter is passed	uninterpreted to the symlook_fn	 (e.g.	a  map
       perhaps).

       del    The  eval_del  function  deletes the context object eval freeing
	      any memory allocated with	eval_new or during the	evaluation  of
	      expressions.

       eval_expression
	      The  eval_expression function evaluates an infix expression like
	      '(5 + 3) * N', converts it into a	stack  of  tokens  in  postfix
	      orientation,  and	reduces	it with	a simple translation matrix to
	      produce a	single integer value. The eval parameter is a  context
	      object  created with eval_new.  The expression at	expr is	evalu-
	      ated up to, but not including, the memory	at  elim,  and	writes
	      the resulting value in the memory	at result.

RETURNS
       eval_expression
	      The  eval_expression  function  returns  0 if the	expression was
	      successfully reduced or -1 if an error occured in	which case er-
	      rno  will	 be  set appropriately (e.g.  ENOENT if	the symlook_fn
	      could not	resolve	a symbol).

libmba-0.9.1			 Apr 29, 2005			      eval(3m)

NAME | SYNOPSIS | DESCRIPTION | RETURNS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=eval&sektion=3m&manpath=FreeBSD+12.1-RELEASE+and+Ports>

home | help