interp(3)

Section: Interp SDK (3)
Updated: 2007-07-17

NAME

interp - implements a simple, stack-based, integer, RPN interpreter

SYNOPSIS

#include itypes.h
#include interp.h

typedef enum base_E base_T;

typedef struct Interp_S *Interp_T;

enum base_E { decimal, octal, hex };

typedef ibyte * FT[CMD_ENTRIES];
typedef FT *UFT;

struct Interp_S {
  Stack_T sp;    /* data stack */
  Stack_T lcsp;  /* loop control stack */
  Stack_T frsp;  /* function return stack */
  base_T  obase; /* current output number base */
  UFT     gfp;   /* global function table pointer */
  UFT     lfp;   /* local function table pointer */
  iword   *vp;   /* global variable pool pointer */
  iword   *lp;   /* local variable pool pointer */
  iword   *kp;   /* system constants table pointer */
  uword   *vt;   /* command vector table pointer, one cmd per token */
  ibyte   *ibuf; /* input message buffer pointer */
  ibyte   *ebuf; /* output message buffer pointer */
  ibyte   *bop;  /* points to location where an error occurred */
  iword   err;   /* the nature of the error (error code) */
};

Interp_T interp_new( void );
void interp_reset( Interp_T cp );
int interp( Interp_T cp, ibyte *str );

DESCRIPTION

Simply put, this API allows you to instantiate an interpreter, reset its state after an error, and execute zero-terminated sequences of tokens.

LIST OF FUNCTIONS

Function
Description
interp_new
Creates a new interpreter instance. Data structures and buffers are allocated that represent the execution environment for this instance. Returns the interp control block pointer.
interp_reset
Restores a sane execution environment by emptying all stacks and setting the output number base to decimal. This corresponds to the initial state of every interpreter instance. Typically, this function is called as part of the response to an error.
interp
Accepts the interp control block pointer and the pointer to the zero-terminated string containing the tokens to be executed. Returns zero for success or an error code.

SEE ALSO

imem(3)