📄 creatordlg.cpp
字号:
{
myLine.InputLine(ReadLine(sText));
word=myLine.DrawWord(1);
if(word=="END") break;
if(!key.IsKeyword(word)) continue;//如果是标号,就读下一行
else {
if(word=="PRIM"||word=="RET"||word=="NOP"||word=="SETSW"||word=="SETLA"||word=="SETSWLA"
||word=="EXIT"||word=="EXITSW"||word=="EXITLA"||word=="EXITSWLA")
codestring=codestring+tool.BtoX(Producecode3(myLine)); //原语和系统语句的执行
else if(key.GetKEYWords(word)>myLine.GetiCount())//实际的单词数比应该的单词数少
codestring=codestring+tool.BtoX(Producecode1(myLine));
else codestring=codestring+tool.BtoX(Producecode2(myLine));//普通执行
codestring+=" //"+myLine.GetAllString()+" \r\n"; }
}while(1);
}
//******************子函数*****************************
CString CCREATORDlg::readline(CFile &myFile)//读一行
{
char ch;
int i;
CString sLine=" ";
BOOL flag=TRUE;
while(1)
{ sLine=" ";
ch='a';
i=0;
while(ch!='\n')
{ if(myFile.Read((void*)&ch,sizeof(char))==0)
{ sLine+=" END";
return sLine;
}
else if(ch==' '&&sLine.GetAt(sLine.GetLength()-1)==' ') continue;
else sLine+=ch;
}
if(sLine.GetAt(sLine.GetLength()-2)!=' ')
sLine.Insert(sLine.GetLength()-2,' ');//每行最后追加加一个空格
else sLine.Delete(sLine.GetLength()-2,1);
while(i<(sLine.GetLength()-2))//空行略过
{if(sLine.GetAt(i++)!=' ') flag=FALSE;}
if(!flag) break;
}
sLine=sLine.Mid(1);
return sLine;
}
void CCREATORDlg::ADDINDEX(CLine &myCLine)
{//功能
if(myCLine.DrawWord(2) == "EQU")
index.AddIndex(myCLine.DrawWord(1)+':'+myCLine.DrawWordX(3));
if( myCLine.DrawWord(2) == "STATIC" && myCLine.DrawWord(3) == "BYTE")
index.AddIndex(myCLine.DrawWord(1)+":SB[00]");
myCLine.Empty();
}
BOOL CCREATORDlg::Substring(CString &string, CString string1,CString string2)
//将string中 string1 字符串换为string2
{CString copystring,temp;
BOOL flag=FALSE;
int length=string1.GetLength(),i=0,offset=0;//用来计算不等长时的补偿;
copystring=string;
while(copystring.GetLength()>length)
{if(string1.Compare(copystring.Left(length))==0)
{flag=TRUE;
temp=string.Left(i+offset);
temp+=string2;
temp+=string.Mid(i+length+offset);
string=temp;
offset+=string2.GetLength()-string1.GetLength();
}
i++;
copystring=copystring.Mid(1);
}
return flag;
}
CString CCREATORDlg::SubStringindex(CLine myLine)//将这一行的所有单词都用index换为对应的数据
{CString mystring,restring;
KEY mykey;
int i=2;
mystring=myLine.GetAllString();
restring=myLine.DrawWord(1)+" ";
while(i<=myLine.GetiCount())
{
mystring=myLine.DrawWordX(i++);
if(!isalpha(mystring.GetAt(0)))
{
restring+=mystring+" ";
continue;
}
restring+=index.IndexWork(mystring)+" ";
}
restring+="\r\n";
return restring;
}
int CCREATORDlg::IsRegister(CString string) //不是寄存器返回'0',其它的对应返回的是falg的值
{string=string.Left(2);
if(string=="SB") return 1;
if(string=="ST") return 2;
if(string=="DB") return 3;
if(string=="LB") return 4;
if(string=="DT") return 5;
if(string=="PB") return 6;
if(string=="PT") return 7;
return 0;
}
CString CCREATORDlg::ReadLine(CString &sText)//读出不带换行的一行
{CString restring;
int i=0;
while(sText.GetAt(i)!='\n')
{
restring+=sText.GetAt(i++);
}
if(tool.Drawword(sText,1)!="END") sText=sText.Mid(i+1);
return restring;
}
CString CCREATORDlg::Producecode1(CLine myLine)//比应该的单词少一个的情况(flag=0的情况)
{KEY key;
CString opercode,kind,restring;
int tag=0,nByte;
opercode=key.GetKeyOpercode(myLine.DrawWord(1));
kind=key.GetKeyKind(myLine.DrawWord(1));
int count=kind.GetAt(kind.GetLength()-1)-'0'-2;//这句话有的除关键字外的单词数(剔除关键词和少一个)
CString *string=new CString[count];
for(int i=0;i<count;i++)
{ nByte=kind.GetAt(i+2)-'0';//对应的数据应该的字节长度
string[i]=myLine.DrawWord(i+2);//获得对应string的字符
if(IsRegister(string[i])) //如果是寄存器
{string[i]=tool.XStoB(tool.OutData(string[i]));
}
else if(tool.IsDigit(string[i])) //如果是十进制字符串
{string[i]=tool.DStoB(string[i]);
}
else if(!tool.IsXDigit(string[i]))//如果是标号
{string[i]=tool.Drawword(sTable,GetsTableCount(string[i])+1);
string[i]=tool.XStoB(string[i]);
Tablecount++;//Tabkecount的初始值为1,所以放在后面
}
else//如果是十六进制字符串
{ string[i]=tool.XStoB(string[i]);
}
string[i]=tool.KeepLengthString(string[i],nByte*8);
}
restring=Compose(opercode,tag);
for(int j=count;j>=1;j--)//倒着加,因为他们是反着读进来的
{ restring+=string[j-1];}
delete []string;
return restring;
}
CString CCREATORDlg::Producecode2(CLine myLine)
{ KEY key;
CString opercode,kind,restring;
int tag=0,nByte;
opercode=key.GetKeyOpercode(myLine.DrawWord(1));
kind=key.GetKeyKind(myLine.DrawWord(1));
int count=kind.GetAt(kind.GetLength()-1)-'0'-1;//这句话有的除关键字外的单词数
CString *string=new CString[count];
CString temp=myLine.DrawWord(1);
//********************获得flag值*****************************
if(kind.GetAt(0)=='1') tag=key.GetKeyTag(key.GetKEYn(temp));
else tag=IsRegister(myLine.DrawWord(2));
//处理"BRA\CALL\JUMP",这些标记
CString name;
name=myLine.DrawWord(1);
name.MakeUpper();
if(name=="BRA"||name=="CALL"||name=="JMP")
tag=7;
//************************************
for(int i=0;i<count;i++)
{ nByte=kind.GetAt(i+1)-'0';//对应的数据应该的字节长度
string[i]=myLine.DrawWordX(i+2);//获得对应string的字符
if(IsRegister(string[i])) //如果是寄存器
{string[i]=tool.XStoB(tool.OutData(string[i]));
}
else if(tool.IsDigit(string[i])) //如果是十进制字符串
{string[i]=tool.DStoB(string[i]);
}
else if(!tool.IsXDigit(string[i]))//如果是标号
{string[i]=tool.Drawword(sTable,GetsTableCount(string[i])+1);
string[i]=tool.XStoB(string[i]);
Tablecount++;
}
else//如果是十六进制字符串
{ string[i]=tool.XStoB(string[i]);
}
string[i]=tool.KeepLengthString(string[i],nByte*8);
}
restring=Compose(opercode,tag);
for(int j=count;j>=1;j--)//倒着加,因为他们是反着读进来的
{ restring+=string[j-1];}
delete []string;
return restring;
}
CString CCREATORDlg::Producecode3(CLine myLine)
{CString restring;
KEY key;
int tag=0,i=0;
CString string=myLine.DrawWord(1);
if(string=="NOP") return Compose("0x00",0);
if(string=="SETSW") return Compose("0x00",1)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(2)),8)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(3)),8);
if(string=="SETLA") return Compose("0x00",2)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(2)),8);
if(string=="SETSWLA") return Compose("0x00",3)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(2)),8)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(3)),8)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(4)),8);
if(string=="EXIT") return Compose("0x00",4);
if(string=="EXITSW") return Compose("0x00",5)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(2)),8)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(3)),8);
if(string=="EXITLA") return Compose("0x00",6)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(2)),8);
if(string=="EXITSWLA")return Compose("0x00",7)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(2)),8)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(3)),8)+tool.KeepLengthString(tool.XStoB(myLine.DrawWord(4)),8);
if(string=="PRIM")
{tag=myLine.GetiCount()-2;
CString *string=new CString[tag+1];
for(i=0;i<=tag;i++)
{string[i]=myLine.DrawWord(i+2);
restring+=tool.KeepLengthString(tool.XStoB(string[i]),8);
}
restring=Compose("0x05",tag)+restring;
delete []string;
return restring;
}
if(string=="RET")
{tag=myLine.GetiCount()-2+4;
CString *string=new CString[tag+1];
for(i=0;i<=tag;i++)
{string[i]=myLine.DrawWord(i+2-4);
restring+=tool.KeepLengthString(tool.XStoD(string[i]),8);
}
restring=Compose("0x05",tag)+restring;
return restring;
}
return "";
}
CString CCREATORDlg::Compose(CString opercode, int flag)
{CString sflag;
return (tool.KeepLengthString(tool.XStoB(opercode),5)+tool.KeepLengthString(tool.DtoB(flag),3));
}
BOOL CCREATORDlg::IsStart(CString string)
{string.MakeUpper();
if(string=="START") return TRUE;
else return FALSE;
}
int CCREATORDlg::GetsTableCount(CString string)//获得对应标号的是第n个单词
{
for(int i=0;i<30;i++)
{if(tool.Drawword(sTable,i)==string)
return i;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -