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

📄 jsglobal_c.cpp

📁 MCS51单片机的宏汇编器源程序。有需要的朋友请下载!
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------
//  JsGlobal_C.cpp 
//---------------------------------------------------------------------------
#include "JsGlobal_H.h"

//---------------------------------------------------------------------------
void J_assert(char* cond, char* f, int l)
{ printf("\n\n\t\tTo Jamesyzzf: Assertion fail!\n\t\t\t--(%s)\n\tfile %s, line %d.",
                 cond, f, l);
  getchar();
                      abort();
} // end J_assert
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void FatalErr(char* msg)
{ printf(msg); exit(Have_Errs);
} // end FatalErr
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// 获取不带后缀名的文件名, 输出Pname返回。
// 输入name字符串。从串末尾开始搜索字符'.',遇到第一个'.'后停止。
// 例如:"ABCD3bc.efg"->"ABCD3bc";  "Abc.Efg.asm" -> "Abc.Efg".
// 如果字串中没有字符'.', 则Pname等于整个源串。 "rtA3g" -> "rtA3g".
//---------------------------------------------------------------------------
void FetchPname(const char* name, Jstring &Pname)
{ register const char* p; // 将作为指针,参加运算。
  for( p = name + strlen(name) - 1; p > name && *p != '.' ; --p ); // end for
  if( p == name ) { Pname = name; } // endif        字串中没有字符'.'
  else            { Pname.Loadstr(name, p - name ); } // end else
} // end FetchPname
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// 判断token是否为运算符,true=是,false=否。
// 运算符:   + - * / % ( ) . ~ & | ^ = < > >= <= <> 等。
// 注意,case的顺序会影响效率。
//---------------------------------------------------------------------------
bool IsOPTR(int16u token)
{ switch(token)
  { case '+' :	  case '-' :
    case '*' :    case '/' :    case '%' :
    case '(' :	  case ')' :
    case '.' :	  case '~' :
    case '&' :    case '|' :    case '^' :
    case SingleNeg :            case SinglePlus:
    case HIGH:	  case LOW :
    case SHL :	  case SHR :
    case '=' :    case '<' :    case '>' :
    case GRtEQUKen :	 case LessEQUKn	:     case NotEqual  :
    case ' ' :    // 表达式结束符
               { return true; } // end cases
    default  : { return false; } // end default
  } // end switch
} // end IsOPTR
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// 根据t 求x, 返回x。
//---------------------------------------------------------------------------
#define	index(t,x);                                                             \
          { switch(t)				                                \
            { case '|'	:			                                \
	      case '^'	: (x)= 0x02 ; break;	                                \
	      case '~'	: (x)= 0x1b ; break;	                                \
	      default	: (x)=(t) & 0x1f;                                       \
            }                                                                   \
           (x)= indexer[(x)];                                                   \
          }
//---------------------------------------------------------------------------
// 比较两个运算符的优先权。返回'<', '=', '>'。
// 返回0(NULL)表示发生错误(Have error)! 出现不该发生的情况。
// 如果主调用程序接收到0返回值,则说明主调用程序本身有错误。
//---------------------------------------------------------------------------
char OPsuperior(int16u t1, int16u t2)
{ static int8 indexer[]	=	  // stored priority of	the operator
   // null  !  "|^  #	$   %	&   '	(   )	*   +	,   -	.   /
      {	0, -1,  2, -1, -1,  6,	3, -1, 11, 12,	6,  5, -1,  5, 10,  6,
   //  +6  -5  >=  <=  <> high low shl shr '9' ':'  ;~	<   =	>   ?
	7,  7,	1,  1,	1,  8,	8,  4,	4, -1, -1,  9,	1,  1,	1,  -1 };
#define	V    AlargB
#define	A    AlessB
#define	X    AequtB
  static precede[13][13] =
  { //	N  =  |	 &  S  +  *  M	H  ~  .	 (  )
     {	X, V, V, V, V, V, V, V,	V, V, V, 0, V }, // N	NULL		 0
     {	A, V, V, V, V, V, V, V,	V, V, V, A, V }, // =	< > = <= >=	 1
     {	A, A, V, V, V, V, V, V,	V, V, V, A, V }, // |	OR XOR		 2
     {	A, A, A, V, V, V, V, V,	V, V, V, A, V }, // &	AND		 3
     {	A, A, A, A, V, V, V, V,	V, V, V, A, V }, // S	SHL SHR		 4
     {	A, A, A, A, A, V, V, V,	V, V, V, A, V }, // +	+ -		 5
     {	A, A, A, A, A, A, V, V,	V, V, V, A, V }, // *	* / %		 6
     {	A, A, A, A, A, A, A, V,	V, V, V, A, V }, // M	+5 -6		 7
     {	A, A, A, A, A, A, A, A,	V, V, V, A, V }, // H	HIGH LOW	 8
     {	A, A, A, A, A, A, A, A,	A, V, V, A, V }, // ~	NOT		 9
     {	A, A, A, A, A, A, A, A,	A, A, V, A, V }, // .	ACC.7		10
     {	A, A, A, A, A, A, A, A,	A, A, A, A, 0 }, // (			11
     {	0, V, V, V, V, V, V, V,	V, V, V, X, V }	 // )			12
  }; //	end precede
#undef V
#undef A
#undef X
   index(t1,t1);
   index(t2,t2);
   return precede[t2][t1];
} // end OPsuperior
//---------------------------------------------------------------------------
#undef index
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
//                        全局函数
//---------------------------------------------------------------------------

#define ISSNChar(x)   ( isalnum(x) || (x)=='_' || (x)=='?' )
//---------------------------------------------------------------------------
// 以可见符开头,中间夹有字母或数字或'?'、'_'的字符串叫做单词和数。
// 输入一个字符串p。 ( p!= NULL !! ) 重要!
// 如果是单词和数开头,返回一个指向串中第一个单词和数的指针。
// length返回单词长度, behind指向单词后一个字符。
// 不是单词开头,则返回NULL。len=0,behind指向文本行中的第一个可见符或者行末。
// exsample:   [    Hello,  how?  ]
//              ^   ^    ^
//              p   ret  behind     len=5
//---------------------------------------------------------------------------
const char* GetNumWord(const char* p, int16u &len, const char* &behind)
{ len = 0;                 // 初始化长度为0
  MovePoint(p); // Now, p指向文本行中的第一个可见符,或者行末
  behind = p;   // Now, p指向文本行中的第一个可见符,或者行末
  // 下面将移动behind。
  if( ISSNChar(*p) )  // Now, p is settled. 得到一个可见符开头的字符串
   { do { ++behind; } while( ISSNChar(*behind) || *behind=='$' );
     // 中间夹有字母或数字或'?', '_', '$'的字符
     len = behind - p ;
     return p;
   } // endif
  return NULL; // 如果是符号或行末(*p=='\0'),结束
} // end GetNumWord
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
const char HexcharMap::s[]="0123456789ABCDEF";
//---------------------------------------------------------------------------
// xxxx  ->  "xxxx"      使用了快速转换。
//---------------------------------------------------------------------------
const char* const Int16uToStr(int16u val)

⌨️ 快捷键说明

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