⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bwb_mth.c

📁 这是一个简易的basic语言解释器, 可供我们学习和改进.
💻 C
📖 第 1 页 / 共 4 页
字号:
#if ANSI_Cstruct bwb_variable *fnc_log( int argc, struct bwb_variable *argv, int unique_id  )#elsestruct bwb_variable *fnc_log( argc, argv, unique_id  )   int argc;   struct bwb_variable *argv;   int unique_id;#endif   {   static struct bwb_variable nvar;   static int init = FALSE;   /* initialize the variable if necessary */   if ( init == FALSE )      {      init = TRUE;      var_make( &nvar, NUMBER );      }#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in fnc_log(): received f_arg <%f> ",      var_getnval( &( argv[ 0 ] ) ) );   bwb_debug( bwb_ebuf );#endif#if PROG_ERRORS   if ( argc < 1 )      {      sprintf( bwb_ebuf, "Not enough parameters (%d) to function LOG().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function LOG().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   * var_findnval( &nvar, nvar.array_pos )       = (bnumber) log( (double) var_getnval( &( argv[ 0 ] ) ) );   return &nvar;   }/***************************************************************        FUNCTION:       fnc_sin()        DESCRIPTION:    This C function implements the BASIC                        predefined SIN function, returning                        the sine of the argument.	SYNTAX:		SIN( number )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_sin( int argc, struct bwb_variable *argv, int unique_id  )#elsestruct bwb_variable *fnc_sin( argc, argv, unique_id  )   int argc;   struct bwb_variable *argv;   int unique_id;#endif   {   static struct bwb_variable nvar;   static int init = FALSE;   /* initialize the variable if necessary */   if ( init == FALSE )      {      init = TRUE;      var_make( &nvar, NUMBER );      }#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in fnc_sin(): received f_arg <%f> ",      var_getnval( &( argv[ 0 ] ) ) );   bwb_debug( bwb_ebuf );#endif#if PROG_ERRORS   if ( argc < 1 )      {      sprintf( bwb_ebuf, "Not enough parameters (%d) to function SIN().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function SIN().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   * var_findnval( &nvar, nvar.array_pos )       = (bnumber) sin( (double) var_getnval( &( argv[ 0 ] ) ) );   return &nvar;   }/***************************************************************        FUNCTION:       fnc_sqr()        DESCRIPTION:    This C function implements the BASIC                        predefined SQR function, returning                        the square root of the argument.	SYNTAX:		SQR( number )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_sqr( int argc, struct bwb_variable *argv, int unique_id  )#elsestruct bwb_variable *fnc_sqr( argc, argv, unique_id  )   int argc;   struct bwb_variable *argv;   int unique_id;#endif   {   static struct bwb_variable nvar;   static int init = FALSE;   /* initialize the variable if necessary */   if ( init == FALSE )      {      init = TRUE;      var_make( &nvar, NUMBER );      }#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in fnc_sqr(): received f_arg <%f> ",      var_getnval( &( argv[ 0 ] ) ) );   bwb_debug( bwb_ebuf );#endif#if PROG_ERRORS   if ( argc < 1 )      {      sprintf( bwb_ebuf, "Not enough parameters (%d) to function SQR().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function SQR().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   * var_findnval( &nvar, nvar.array_pos )       = (bnumber) sqrt( (double) var_getnval( &( argv[ 0 ] ) ) );   return &nvar;   }/***************************************************************        FUNCTION:       fnc_tan()        DESCRIPTION:    This C function implements the BASIC                        predefined TAN function, returning the                        tangent of the argument.	SYNTAX:		TAN( number )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_tan( int argc, struct bwb_variable *argv, int unique_id  )#elsestruct bwb_variable *fnc_tan( argc, argv, unique_id  )   int argc;   struct bwb_variable *argv;   int unique_id;#endif   {   static struct bwb_variable nvar;   static int init = FALSE;   /* initialize the variable if necessary */   if ( init == FALSE )      {      init = TRUE;      var_make( &nvar, NUMBER );      }#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in fnc_tan(): received f_arg <%f> ",      var_getnval( &( argv[ 0 ] ) ) );   bwb_debug( bwb_ebuf );#endif#if PROG_ERRORS   if ( argc < 1 )      {      sprintf( bwb_ebuf, "Not enough parameters (%d) to function TAN().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function TAN().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   * var_findnval( &nvar, nvar.array_pos )       = (bnumber) tan( (double) var_getnval( &( argv[ 0 ] ) ) );   return &nvar;   }/***************************************************************        FUNCTION:       fnc_sgn()        DESCRIPTION:    This C function implements the BASIC                        predefined SGN function, returning 0                        if the argument is 0, -1 if the argument                        is less than 0, or 1 if the argument                        is more than 0.	SYNTAX:		SGN( number )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_sgn( int argc, struct bwb_variable *argv, int unique_id  )#elsestruct bwb_variable *fnc_sgn( argc, argv, unique_id  )   int argc;   struct bwb_variable *argv;   int unique_id;#endif   {   static struct bwb_variable nvar;   bnumber nval;   static int init = FALSE;   /* initialize the variable if necessary */   if ( init == FALSE )      {      init = TRUE;      var_make( &nvar, NUMBER );      }#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in fnc_sgn(): received f_arg <%f> ",      var_getnval( &( argv[ 0 ] ) ) );   bwb_debug( bwb_ebuf );#endif#if PROG_ERRORS   if ( argc < 1 )      {      sprintf( bwb_ebuf, "Not enough parameters (%d) to function SGN().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function SGN().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   nval = var_getnval( &( argv[ 0 ] ));   if ( nval == (bnumber) 0.0 )      {      * var_findnval( &nvar, nvar.array_pos ) = (bnumber) 0;      }   else if ( nval > (bnumber) 0.0 )      {      * var_findnval( &nvar, nvar.array_pos ) = (bnumber) 1;      }   else      {      * var_findnval( &nvar, nvar.array_pos ) = (bnumber) -1;      }   return &nvar;   }/***************************************************************        FUNCTION:       fnc_int()        DESCRIPTION:    This C function implements the BASIC                        predefined INT function, returning an                        integer value less then or equal to the 			argument.	SYNTAX:		INT( number )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_int( int argc, struct bwb_variable *argv, int unique_id  )#elsestruct bwb_variable *fnc_int( argc, argv, unique_id  )   int argc;   struct bwb_variable *argv;   int unique_id;#endif   {   static struct bwb_variable nvar;   static int init = FALSE;   /* initialize the variable if necessary */   if ( init == FALSE )      {      init = TRUE;      var_make( &nvar, NUMBER );      }#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in fnc_int(): received f_arg <%f> ",      var_getnval( &( argv[ 0 ] ) ) );   bwb_debug( bwb_ebuf );#endif#if PROG_ERRORS   if ( argc < 1 )      {      sprintf( bwb_ebuf, "Not enough parameters (%d) to function INT().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function INT().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   * var_findnval( &nvar, nvar.array_pos )       = (bnumber) floor( (double) var_getnval( &( argv[ 0 ] ) ) );   return &nvar;   }/***************************************************************        FUNCTION:       fnc_exp()	DESCRIPTION:    This C function implements the BASIC			EXP() function, returning the exponential			value of the argument.	SYNTAX:		EXP( number )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_exp( int argc, struct bwb_variable *argv, int unique_id )#elsestruct bwb_variable *fnc_exp( argc, argv, unique_id )   int argc;   struct bwb_variable *argv;   int unique_id;#endif   {   static struct bwb_variable nvar;   static int init = FALSE;   /* initialize the variable if necessary */   if ( init == FALSE )      {      init = TRUE;      var_make( &nvar, NUMBER );      }#if PROG_ERRORS   if ( argc < 1 )      {      sprintf( bwb_ebuf, "Not enough parameters (%d) to function EXP().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function EXP().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   /* Added double recast here (JBV) */   * var_findnval( &nvar, nvar.array_pos )       = (bnumber) exp( (double) var_getnval( &( argv[ 0 ] ) ) );   return &nvar;   }#endif                          /* COMPRESS_FUNCS */#if COMMON_FUNCS/***************************************************************        FUNCTION:       fnc_val()	DESCRIPTION:    This C function implements the BASIC			VAL() function, returning the numerical			value of its string argument.	SYNTAX:		VAL( string$ )***************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -