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

📄 calcu.c

📁 redboy for gba 是BPNS为GBA编写的一个小软件。软件的邹形是BASIC高级语言解释执行器。几经修改和扩展
💻 C
字号:
#include <CsAgb.h>
#include <rbasic.h>
#include <string.h>
#include <rb_string.h>
#define float_tp 1
#define math_cnt 39
#define bg_id 128
#define max_len 10 //最大长度
extern const char rb_math_std[math_cnt][10];
extern double rb_cal(char *exp);
extern void rb_get_str(char *exp,char *str);
int rb_is_opt(char ch)
{
   int i=0;
   char opts[]="+-*/%^()";
   while (opts[i]!='\0')
   {
      if (ch==opts[i]) return i+1;
      i++;
   }
   return 0;
}

int is_math_fun(char *name)
{
   int i=0;
   while (i<20)
   {
      if (strcmp(rb_math_std[i],name)==0) return i+1;
      i++;
   }
   return 0;
}

int is_float_var(char *name)
{
   int i=0;
   while (i<rb_float_cnt)
   {
      if (strcmp((char *)rb_mes[float_tp]+max_len*i,name)==0) return i+1;
      i++;
   }
   return 0;
}

double rb_calcu(char *exp)
{
   int ep=0,np=0,tp=0,id,i;
   char nexp[str_max_len];
   char temp[str_max_len];
   no_blank(exp);
   str_up(exp);
   while (1)//解析表达式
   {
      if (rb_is_opt(exp[ep]) || exp[ep]=='\0')//是运算符
      {
         if (tp)
         {
            temp[tp]='\0';//arlt("AAA",temp);
            id=is_math_fun(temp);
            if (id)//是数学函数
            {
               nexp[np]='M';
               np++;
               nexp[np]=bg_id+id-1;
               np++;
            }
            else
            {
               id=is_float_var(temp);
               if (id)
               {
                  nexp[np]='F';
                  np++;
                  nexp[np]=bg_id+id-1;
                  np++;
               }
               else
               {
                  if (temp[0]<'0' || temp[0]>'9') {rb_error=6;return 0.0;}
                  for (i=0;i<tp;i++)
                  {
                     nexp[np]=temp[i];
                     np++;
                  }
               }
            }
         }
         tp=0;
         nexp[np]=exp[ep];
         np++;
         if (exp[ep]=='\0') break;//识别结束
         ep++;
      }
      else
      {
         temp[tp]=exp[ep];
         ep++;
         tp++;
      }
   }
   nexp[np]='\0';
   //RBprint(nexp);
   return rb_cal(nexp);
}
double rb_calcu1(char *exp)
{
   char str[str_max_len];
   rb_get_str(exp,str);
   return rb_calcu(str);
}

⌨️ 快捷键说明

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