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

📄 comexe.c

📁 可以在嵌入式应用中
💻 C
📖 第 1 页 / 共 2 页
字号:
//命令行解释执行器
#include <CsAgb.h>
#include <rbasic.h>
#include <variable.h>
#include <rb_stdio.h>
#include <timer.h>
#include <rb_math.h>
#include <rb_string.h>
#include <cal.h>
#include <logic.h>
#include <rbdata.h>
#include <graph.h>
#include <strpro.h>
#include <rb_load.h>
#include <tree.h>
#include <rb_data.h>
#include <cyc.h>
#include <logic.h>
#include <variable.h>
#include <rb_clear.h>
//struct comtree *rb_now_line;//当前执行行
//extern struct comtree *comstart;//程序第一行
extern void rb_dim(char *exp);
extern const char *rbcoms;
void rb_exe_line(char *com);
void rb_cls()//CLS
{
   rb_xp=0;
   rb_yp=0;
   r_box(0,0,239,159,rb_bg,1);
}

void rb_let(char *com)//LET 赋值语句
{
   u8 i=0;
   u8 exp_start=0;
   u8 var_type=1;//(0 str,1 float,2 int)
   u8 is_dim=0;//是否为数组
   u8 suf=0;
   double result=0;
   char exp[str_max_len];
   char var[str_max_len];
   char str[str_max_len];
   char *strp;
   while (com[i]!='=')//获得变量名
   {
      var[i]=com[i];
      if (var[i]=='[' && is_dim==0) is_dim=i;
      else if(var[i]=='#' && is_dim==0) var_type=2;
      else if(var[i]=='$' && is_dim==0) var_type=0;
      i++;
   }
   var[i]='\0';
   exp_start=i+1;
   i++;
   while (com[i]!='\0')//获得表达式
   {
      exp[i-exp_start]=com[i];
      i++;
   }
   exp[i-exp_start]='\0';
   if (var_type) result=rb_cal(exp);//是数字变量
   else get_str(str,exp);//是字符串变量
   if (rb_error) return;
   if (is_dim)//数组
   {
      if (var[exp_start-2]!=']')//语法错误
      {
         rb_error=6;
         return;
      }
      for (i=is_dim+1;i<exp_start-2;i++)
         exp[i-is_dim-1]=var[i];//获得下标表达式
      exp[i-is_dim-1]='\0';
      suf=rb_cal(exp);//计算下标
      if (rb_error) return;
      if (var_type==1) var[is_dim]='\0';
      else var[is_dim-1]='\0';
      /*if (check_var_name(var))//非法的变量名
      {
         rb_error=22;
         return;
      }*/
      switch(var_type)
      {
         case 0://字符串赋值
         if (suf<1 || suf>=str_max_len)
         {
            rb_error=3;
            return;
         }
         strp=rb_get_str(var);
         if (strp) strp[(u8)(suf-1)]=str[0];
         break;
         case 1://实型变量赋值
         rb_give_float_dim(var,result,suf);
         break;
         case 2://整型变量赋值
         rb_give_int_dim(var,result,suf);
         break;
      }
      return;
   }
   if (var_type==1) var[exp_start-1]='\0';
   else var[exp_start-2]='\0';
   /*if (check_var_name(var))
   {
      rb_error=22;
      return;
   }*/
   switch(var_type)
   {
      case 0://
      rb_give_str(var,str);
      break;
      case 1://
      rb_give_float(var,result);
      break;
      case 2://
      rb_give_int(var,result);
   }
}
char rb_get_key()
{
   CS_ReadKey();
   if (CS_IsKeyDown(KEY_A)) return 'A';
   if (CS_IsKeyDown(KEY_B)) return 'B';
   if (CS_IsKeyDown(KEY_L)) return 'Y';
   if (CS_IsKeyDown(KEY_R)) return 'N';
   if (CS_IsKeyDown(KEY_SELECT)) return 'C';
   if (CS_IsKeyDown(KEY_START)) return 'D';
   if (CS_IsKeyDown(KEY_LEFT)) return '1';
   if (CS_IsKeyDown(KEY_RIGHT)) return '2';
   if (CS_IsKeyDown(KEY_UP)) return '3';
   if (CS_IsKeyDown(KEY_DOWN)) return '4';
}
void rb_inkey(char *name,u8 mod)//INKEY$
{
   char ch=0;
   u8 count=0;
   while (ch==0 && count<20)
   {
      ch=rb_get_key();
      count+=mod;
   }
   name[0]=ch;
   name[1]='\0';
}
rb_tab(char *exp)
{
   double step=rb_cal(exp);
   if (rb_error) return;
   if (step<0)
   {
      rb_error=25;
      return;
   }
   rb_xp+=step;
   rb_yp+=rb_xp/30;
   rb_xp=rb_xp%30;
   if (rb_yp>15) rb_cls();
}
void rb_print(char *con)//PRINT 数字/字符显示函数
{
   u8 next=0,i=0;
   char str[str_max_len];
   char temp[str_max_len];
   u8 strp=0;
   u8 is_num=1;
   u8 fla=1,flag=0;
   u8 niis=1;
   while(con[i]!='\0')
   {
      if (con[i]=='\"') niis=!niis;
      else if (niis && con[i]=='$' && fla) is_num=0;
      else if (niis && con[i]=='(') {fla=0,flag++;}
      else if (niis && con[i]==')') flag--;
      if (niis && (flag==0) && (con[i]==';' || con[i]==','))//
      {
         str[strp]='\0';
         exp_adj(str);
         if (str[0]=='\"') is_num=0;
         if(is_num) num_to_str(rb_cal(str),temp);
         else get_str(temp,str);
         if (rb_error) return;
         RBprint(temp);
         if (con[i]==',') RBprint("  ");
         strp=0;
         is_num=1;
         fla=1;
      }
      else
      {
         str[strp]=con[i];
         strp++;
      }
      i++;
   }
   if (strp)
   {
      str[strp]='\0';
      exp_adj(str);
      if (str[0]=='\"') is_num=0;
      if(is_num) num_to_str(rb_cal(str),temp);
      else get_str(temp,str);
      if (rb_error) return;
      RBprint(temp);
      endl();
   }
}
void rb_data(char *exp)//置数据
{
   char str[str_max_len];
   u8 strp=0;
   u8 i=0;
   u8 flag=1;
   u8 len;
   double num;
   while (flag)
   {
      if (exp[i]==','||exp[i]=='\0')
      {
         str[strp]='\0';
         exp_adj(str);
         len=str_len(str);
         if (len==0)
         {
            rb_error=6;
            return;
         }
         if (str[0]=='\"')//是字符串
         {
            if (str[len-1]!='\"')//出错
            {
               rb_error=6;
               return;
            }
            str[len-1]='\0';
            dat_add_str(str+1);
         }
         else
         {
            num=rb_cal(str);
            if (rb_error) return;
            dat_add_num(num);
         }
         if(exp[i]=='\0') flag=0;
         strp=0;
         i++;
      }
      else
      {
         str[strp]=exp[i];
         i++;strp++;
      }
   }
}

void rb_read(char *exp)//READ
{
   char str[str_max_len];
   char suffix[str_max_len];
   char *var;
   char *get;
   u8 strp=0;
   u8 i=0,j=0;
   u8 is_dim=0;
   u8 niis=1;
   u8 flag=0;
   u8 is_num=1;
   u8 len;
   double suf;
   while (TRUE)
   {
      if (exp[i]=='(' && niis && is_dim==0)
      {
         rb_error=6;
         return;
      }
      if (exp[i]=='[' && niis && flag==0) is_dim=1;
      else if (exp[i]=='(' && niis) flag++;
      else if (exp[i]==')' && niis) flag--;
      else if (exp[i]=='\"') niis=!niis;
      else if (exp[i]=='#' && niis && is_dim==0) is_num=2;
      else if (exp[i]=='$' && niis && is_dim==0) is_num=0;
      if ( (exp[i]==',' && niis && flag==0) || exp[i]=='\0')
      {
         str[strp]='\0';
         exp_adj(str);
         if (is_dim)
         {
            j=0;
            strp=0;
            while (str[strp]!='[') strp++;
            if (strp==0)
            {
               rb_error=6;
               return;
            }
            if (is_num!=1) str[strp-1]='\0';
            else str[strp]='\0';
            strp++;
            while (str[strp]!='\0')
            {
               suffix[j]=str[strp];
               strp++;
               j++;
            }
            if (suffix[j-1]!=']')
            {
               rb_error=6;
               return;
            }
            suffix[j-1]='\0';
            suf=rb_cal(suffix);
            if (rb_error) return;
            /*if (check_var_name(str))
            {
               rb_error=22;
               return;
            }*/
            if (is_num==0)
            {
               var=rb_get_str(str);
               if (var==NULL) return;
               if (suf<1 || suf>str_max_len)
               {
                  rb_error=3;
                  return;
               }
               get=dat_read_str();
               if (rb_error) return;
               var[(int)suf-1]=get[0];
            }
            else
            {
               if (is_num==1) rb_give_float_dim(str,dat_read_num(),suf);
               else rb_give_int_dim(str,dat_read_num(),suf);
            }
         }
         else
         {
            str[strp]='\0';
            exp_adj(str);
            len=str_len(str);
            if (len==0)
            {
               rb_error=6;
               return;
            }
            if (is_num!=1)
            {
               if (str[len-1]!='$' && str[len-1]!='#')
               {
                  rb_error=6;
                  return;
               }
               str[len-1]='\0';
            }
            /*if (check_var_name(str)) return;*/
            if (is_num)
            {
               if (is_num==1) rb_give_float(str,dat_read_num());
               else rb_give_int(str,dat_read_num());
               if (rb_error) return;
            }
            else
            {
               var=rb_get_str(str);
               if (var==NULL) return;
               strcpy(var,dat_read_str());
               if (rb_error) return;
            }
         }
         if (exp[i]=='\0') return;
         strp=0;
         is_num=1;
         is_dim=0;
         niis=1;
      }
      else
      {
         str[strp]=exp[i];
         strp++;
      }
      i++;
   }
}
void rb_restore(char *exp)
{
   exp_adj(exp);
   if (strcmp(exp,"NUM")==0) dat_restore(0);
   else if(strcmp(exp,"STR")==0) dat_restore(1);
   else if(exp[0]=='\0' || strcmp(exp,"ALL")==0)
   {
      dat_restore(1);
      dat_restore(0);
   }
   else rb_error=6;
}
void rb_clean(char *exp)
{
   exp_adj(exp);
   if (strcmp(exp,"NUM")==0) rb_clean_num();
   else if(strcmp(exp,"STR")==0) rb_clean_str();
   else if(exp[0]=='\0' || strcmp(exp,"ALL")==0)
   {
      rb_clean_num();
      rb_clean_num();
   }
   else rb_error=6;
}

void rb_locate(char *exp)//LOCATE
{
   double xp;
   double yp;
   char temp[2];
   if (get_para(temp,exp,2)) return;
   xp=rb_cal(exp);
   yp=rb_cal(exp+temp[0]);
   if (rb_error) return;
   if(xp<0 || yp<0 || xp>29 || yp>15)
   {
      rb_error=25;
      return;
   }
   rb_xp=xp;
   rb_yp=yp;
}
void rb_color(char *exp)//COLOR
{
   u16 color=rb_cal(exp);
   if (rb_error) return;
   rb_co=color;
}
void rb_screen(char *exp)//SCREEN
{
   u8 i,j;
   u16 loc;
   u16 color=rb_cal(exp);
   if (rb_error) return;
   for (i=0;i<160;i++)
   for (j=0;j<240;j++)
   {
      loc=i*240+j;
      if (*(mVRAM+loc)==rb_bg) *(mVRAM+loc)=color;
   }
   rb_bg=color;
}

void rb_draw(char *exp)//DRAW
{
   char temp[4];
   double x,y,color,mod;
   if (get_para(temp,exp,4)) return;
   x=rb_cal(exp);
   y=rb_cal(exp+temp[0]);
   color=rb_cal(exp+temp[1]);
   mod=rb_cal(exp+temp[2]);
   if (rb_error) return;
   if (x<0 || x>239 || y<0 || y>159)
   {
      rb_error=25;
      return;
   }
   r_draw(x,y,color,mod);
}
void rb_line(char *exp)//LINE
{
   char temp[6];
   double x1,x2,y1,y2,color,mod;
   if (get_para(temp,exp,6)) return;
   x1=rb_cal(exp);
   y1=rb_cal(exp+temp[0]);
   x2=rb_cal(exp+temp[1]);
   y2=rb_cal(exp+temp[2]);
   color=rb_cal(exp+temp[3]);
   mod=rb_cal(exp+temp[4]);

⌨️ 快捷键说明

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