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

📄 bwb_mth.c

📁 这是一个简易的basic语言解释器, 可供我们学习和改进.
💻 C
📖 第 1 页 / 共 4 页
字号:
   /* initialize the variable if necessary */   if ( init == FALSE )      {      init = TRUE;      var_make( &nvar, STRING );      }#if PROG_ERRORS   if ( argc < 1 )      {      sprintf( bwb_ebuf, "Not enough parameters (%d) to function MKS$().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function MKS$().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   a_float.the_float = var_getnval( &( argv[ 0 ] ) );   for ( i = 0; i < sizeof( float ); ++i )      {      tbuf[ i ] = a_float.the_chars[ i ];      tbuf[ i + 1 ] = '\0';      }   b = var_getsval( &nvar );   b->length = sizeof( float );   b->sbuffer = tbuf;   b->rab = FALSE;#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in fnc_mks(): string <%s> hex vals <%X><%X><%X><%X>",      tbuf, tbuf[ 0 ], tbuf[ 1 ], tbuf[ 2 ], tbuf[ 3 ] );   bwb_debug( bwb_ebuf );#endif   return &nvar;   }/***************************************************************        FUNCTION:       fnc_cvi()        DESCRIPTION:    This C function implements the BASIC                        predefined CVI() function.	NOTE:		As implemented in bwBASIC, this is a			pseudo-function, since bwBASIC does			not recognize precision levels.	SYNTAX:		CVI( string$ )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_cvi( int argc, struct bwb_variable *argv, int unique_id  )#elsestruct bwb_variable *fnc_cvi( argc, argv, unique_id  )   int argc;   struct bwb_variable *argv;   int unique_id;#endif   {   register int i;   struct bwb_variable *v;   bstring *b;   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 CVI().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function CVI().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   v = &( argv[ 0 ] );   b = var_findsval( v, v->array_pos );   for ( i = 0; i < sizeof( int ); ++i )      {      an_integer.the_chars[ i ] = b->sbuffer[ i ];      }   * var_findnval( &nvar, nvar.array_pos ) = (bnumber) an_integer.the_integer;   return &nvar;   }/***************************************************************        FUNCTION:       fnc_cvd()        DESCRIPTION:    This C function implements the BASIC                        predefined CVD() function.	NOTE:		As implemented in bwBASIC, this is a			pseudo-function, since bwBASIC does			not recognize precision levels.	SYNTAX:		CVD( string$ )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_cvd( int argc, struct bwb_variable *argv, int unique_id  )#elsestruct bwb_variable *fnc_cvd( argc, argv, unique_id  )   int argc;   struct bwb_variable *argv;   int unique_id;#endif   {   register int i;   struct bwb_variable *v;   bstring *b;   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 CVD().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function CVD().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   v = &( argv[ 0 ] );   b = var_findsval( v, v->array_pos );   for ( i = 0; i < sizeof( double ); ++i )      {      a_double.the_chars[ i ] = b->sbuffer[ i ];      }   * var_findnval( &nvar, nvar.array_pos ) = (bnumber) a_double.the_double;   return &nvar;   }/***************************************************************        FUNCTION:       fnc_cvs()        DESCRIPTION:    This C function implements the BASIC                        predefined CVS() function.	NOTE:		As implemented in bwBASIC, this is a			pseudo-function, since bwBASIC does			not recognize precision levels.	SYNTAX:		CVS( string$ )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_cvs( int argc, struct bwb_variable *argv, int unique_id  )#elsestruct bwb_variable *fnc_cvs( argc, argv, unique_id  )   int argc;   struct bwb_variable *argv;   int unique_id;#endif   {   register int i;   struct bwb_variable *v;   bstring *b;   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 CVS().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function CVS().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* assign values */   v = &( argv[ 0 ] );   b = var_findsval( v, v->array_pos );   for ( i = 0; i < sizeof( float ); ++i )      {      a_float.the_chars[ i ] = b->sbuffer[ i ];      }#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in fnc_cvs(): string <%s> hex vals <%X><%X><%X><%X>",      a_float.the_chars, a_float.the_chars[ 0 ], a_float.the_chars[ 1 ],       a_float.the_chars[ 2 ], a_float.the_chars[ 3 ] );   bwb_debug( bwb_ebuf );#endif   * var_findnval( &nvar, nvar.array_pos ) = a_float.the_float;   return &nvar;   }/***************************************************************        FUNCTION:       fnc_csng()	DESCRIPTION:    This C function implements the BASIC			function CSNG().  As implemented,			this is a pseudo-function, since			all bwBASIC numerical values have the			same precision.	SYNTAX:		CSNG( number )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_csng( int argc, struct bwb_variable *argv, int unique_id )#elsestruct bwb_variable *fnc_csng( 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 );      }   /* check parameters */#if PROG_ERRORS   if ( argc < 1 )      {      sprintf( bwb_ebuf, "Not enough parameters (%d) to function CINT().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function CINT().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* get truncated integer value */   * var_findnval( &nvar, nvar.array_pos )      = (bnumber) var_getnval( &( argv[ 0 ] ) );   return &nvar;   }/***************************************************************        FUNCTION:       fnc_cint()	DESCRIPTION:    This C function returns the truncated			rounded integer value of its numerical			argument.	SYNTAX:		CINT( number )***************************************************************/#if ANSI_Cstruct bwb_variable *fnc_cint( int argc, struct bwb_variable *argv, int unique_id )#elsestruct bwb_variable *fnc_cint( 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 );      }   /* check parameters */#if PROG_ERRORS   if ( argc < 1 )      {      sprintf( bwb_ebuf, "Not enough parameters (%d) to function CINT().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }   else if ( argc > 1 )      {      sprintf( bwb_ebuf, "Too many parameters (%d) to function CINT().",         argc );      bwb_error( bwb_ebuf );      return NULL;      }#else   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )      {      return NULL;      }#endif   /* get rounded integer value */   * var_findnval( &nvar, nvar.array_pos )      = round_int( var_getnval( &( argv[ 0 ] ) ));   return &nvar;   }#endif				/* MS_FUNCS *//***************************************************************	FUNCTION:       trnc_int()	DESCRIPTION:    This function returns the truncated			truncated integer value of its numerical			argument.***************************************************************/#if ANSI_Cbnumbertrnc_int( bnumber x )#elsebnumbertrnc_int( x )   bnumber x;#endif   {   double sign; /* Was bnumber (JBV) */   if ( x < (bnumber) 0.0 )      {      sign = (double) -1.0; /* Was bnumber (JBV) */      }   else      {      sign = (double) 1.0; /* Was bnumber (JBV) */      }   /* Added double recast here (JBV) */   return (bnumber) ( floor( fabs( (double) x )) * sign );   }/***************************************************************	FUNCTION:       round_int()	DESCRIPTION:    This function returns the truncated			rounded integer value of its numerical			argument.***************************************************************/#if ANSI_Cbnumberround_int( bnumber x )#elsebnumberround_int( x )   bnumber x;#endif   {   if ( x < (bnumber) 0.00 )      {      /* Added double recasts here (JBV) */      if ( (bnumber) fabs( (bnumber) floor( (double) x ) - x ) < (bnumber) 0.500 )	 {	 return (bnumber) floor( (double) x );	 }      else	 {	 return (bnumber) ceil( (double) x );	 }      }   else      {      if ( ( x - (bnumber) floor( (double) x )) < (bnumber) 0.500 )	 {	 return (bnumber) floor( (double) x );	 }      else	 {	 return (bnumber) ceil( (double) x );	 }      }   }

⌨️ 快捷键说明

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