?? unit1.cpp
字號:
Form1->Animate3->Play(1,24,1);
}
k=2;
}
switch(k)
{
case 0:
if(b[0]!='\0') //當B數(shù)組非空時將B數(shù)組中數(shù)字進行處理
{
n=and(j,b);
i=0; //數(shù)組A下標清零
add=ad; //分配內存單元
add=add+"H";
ad=ad+2;
Form1->StringGrid1->Cells[5][x]=n; //輸出數(shù)字到表格
Form1->StringGrid1->Cells[4][x]=add;
Form1->StringGrid1->Cells[3][x]="常數(shù)數(shù)字";
Form1->StringGrid1->Cells[2][x]="c";
Form1->StringGrid1->Cells[1][x]='1';
Form1->StringGrid1->Cells[0][x]=x;
if(ssj==0)
fprintf(fp2,"%10d, 1, c, 常數(shù)數(shù)字,%10s,%10d\n",x,add,n);
x++ ;
}
if(i>9) //當A數(shù)組中字符數(shù)量多于10個出錯處理
{
ShowMessage("此字符串中字母數(shù)目多于10個");
Form1->StringGrid1->Cells[5][x]=a;
Form1->StringGrid1->Cells[4][x]="error";
Form1->StringGrid1->Cells[3][x]="error";
Form1->StringGrid1->Cells[2][x]="error";
Form1->StringGrid1->Cells[1][x]="error";
Form1->StringGrid1->Cells[0][x]=x;
if(ssj==0)
fprintf(fp2,"%10d, error, error, error, error,%10d\n",x,n);
x++;
a[0]='\0';a[1]='\0';a[2]='\0';a[3]='\0';a[4]='\0';a[5]='\0';a[6]='\0';a[7]='\0';a[8]='\0';a[9]='\0';
while(s[p+1]>=65&&s[p+1]<=90||s[p+1]>=97&&s[p+1]<=122)
{
p++; //將多余的即10個以后的字符忽略不參與詞法分析
}
return p;
}
a[i]=ch; //將字母CH存入暫存數(shù)組A中
Form1->Edit4->Text=a;
i=i+1; //A數(shù)組下標加一
a[i]='\0';
break;
case 1:
if(a[0]!='\0') //當A數(shù)組非空時將A數(shù)組中字母進行處理
{
if(check(a)==1) //檢驗保留字,用戶自定義字符串
{
j=0; //數(shù)組B下標清零
}
else
{
j=0;
}
}
b[j]=ch; //將數(shù)字CH存入暫存數(shù)組A中
Form1->Edit5->Text=b;
j=j+1; //B數(shù)組下標加一
b[j]='\0';
break;
case 2:
i=0;
if(b[0]!='\0') //同CASE0
{
n=and(j,b);
i=0;
add=ad;
add=add+"H";
ad=ad+2;
Form1->StringGrid1->Cells[5][x]=n;
Form1->StringGrid1->Cells[4][x]=add;
Form1->StringGrid1->Cells[3][x]="常數(shù)數(shù)字";
Form1->StringGrid1->Cells[2][x]="c";
Form1->StringGrid1->Cells[1][x]='1';
Form1->StringGrid1->Cells[0][x]=x;
if(ssj==0)
fprintf(fp2,"%10d, 1, c, 常數(shù)數(shù)字,%10s,%10d\n",x,add,n);
x++;
}
j=0;
if(a[0]!='\0') //同CASE1
{
if(check(a)==1)
{
j=0;
}
else
{
j=0;
}
}
switch(ch) //將CH為字符的情況細分
{
case'<':
if(s[p+1]=='='||s[p+1]=='<') //若“<“符號后為“=”或“〈”,調用雙字符符號函數(shù)處理
{
o[0]=ch;o[1]=s[p+1];o[2]='\0'; //暫存欲匹配的雙字符符號
fuyu(o); //調用FUYU()函數(shù)處理
p=p+1;
return p;
}
goto l;
case'>':
{
if(s[p+1]=='='||s[p+1]=='>') //雙字符符號處理
{
o[0]=ch;o[1]=s[p+1];
fuyu(o);
p=p+1;
return p;
}
goto l;
}
case'=':
{
if(s[p+1]=='=') //雙字符符號處理
{
o[0]=ch;o[1]=s[p+1];
fuyu(o);
p=p+1;
return p;
}
goto l;
}
case'!':
{
if(s[p+1]=='=') //雙字符符號處理
{
o[0]=ch;o[1]=s[p+1];
fuyu(o);
p=p+1;
return p;
}
goto l;
}
case'%': //雙字符符號處理
{
if(s[p+1]=='='||s[p+1]=='d'||s[p+1]=='f'||s[p+1]=='s'||s[p+1]=='c')
{
o[0]=ch;o[1]=s[p+1];
fuyu(o);
p=p+1;
return p;
}
}
case'&': //雙字符符號處理
{
if(s[p+1]=='&'||s[p+1]=='=')
{
o[0]=ch;o[1]=s[p+1];
fuyu(o);
p=p+1;
return p;
}
}
case'|': //雙字符符號處理
{
if(s[p+1]=='|'||s[p+1]=='=')
{
o[0]=ch;o[1]=s[p+1];
fuyu(o);
p=p+1;
return p;
}
}
case'+': //雙字符符號處理
{
if(s[p+1]=='+'||s[p+1]=='=')
{
o[0]=ch;o[1]=s[p+1];
fuyu(o);
p=p+1;
return p;
}
}
case'-': //雙字符符號處理
{
if(s[p+1]=='-'||s[p+1]=='=')
{
o[0]=ch;o[1]=s[p+1];
fuyu(o);
p=p+1;
return p;
}
}
case'/': //考慮“/”符號是否為說明部分標記
{
if(s[p+1]=='*') //當“/”符號后是“*”時,找是否有“*/”與之匹配
{
p++;
while(s[p]!='\0')
{
p=p+1;
if(s[p]=='*'&&s[p+1]=='/')
{
p++;
return p;
break;
}
}
if(s[p]=='\0') //若無,則出錯處理
{
ShowMessage("無 \"*/\" 字符串與 \"/*\" 字符串匹配");
Form1->StringGrid1->Cells[5][x]="error";
Form1->StringGrid1->Cells[4][x]="error";
Form1->StringGrid1->Cells[3][x]="error";
Form1->StringGrid1->Cells[2][x]="error";
Form1->StringGrid1->Cells[1][x]="error";
Form1->StringGrid1->Cells[0][x]=x;
if(ssj==0)
fprintf(fp2,"%10d, error, error, error, error, error\n",x);
x++;
return p;
}
break;
}
if(s[p+1]=='/') //當“/”符號后為“/”時,在換行之前的字符串作為說明部分
{
p++;
while(s[p]!='\n')
{
if(s[p]=='\0')
{
Form1->StringGrid1->Cells[5][x]="error";
Form1->StringGrid1->Cells[4][x]="0000";
Form1->StringGrid1->Cells[3][x]="標識符";
Form1->StringGrid1->Cells[2][x]="";
Form1->StringGrid1->Cells[1][x]='0';
Form1->StringGrid1->Cells[0][x]=x;
}
p++;
if(s[p]=='\n')
return p;
}
}
}
}
if(ch=='+'||ch=='-'||ch=='*'||ch=='/'||ch=='%') //雙字符符號處理
{
if(s[p+1]=='=')
{
o[0]=ch;o[1]=s[p+1];
fuyu(o);
p=p+1;
return p;
}
}
if(ch=='(')
{
if(find1(p)==0) //檢驗"("是否匹配
{
Form1->Edit6->Text=ch;
Form1->StringGrid1->Cells[5][x]="( ";
Form1->StringGrid1->Cells[4][x]="error";
Form1->StringGrid1->Cells[3][x]="字符串匹配";
Form1->StringGrid1->Cells[2][x]="符串與 \"(\"";
Form1->StringGrid1->Cells[1][x]="無 \")\" 字";
Form1->StringGrid1->Cells[0][x]=x;
Form1->Edit6->Text=ch;
if(ssj==0)
fprintf(fp2,"%10d, error, error, error, error,%10c\n",x,ch);
x++;
return p;
}
else
{
Form1->StringGrid1->Cells[5][x]=ch;
Form1->StringGrid1->Cells[4][x]="10001110";
Form1->StringGrid1->Cells[3][x]="界符";
Form1->StringGrid1->Cells[2][x]="";
Form1->StringGrid1->Cells[1][x]='0';
Form1->StringGrid1->Cells[0][x]=x;
if(ssj==0)
fprintf(fp2,"%10d, 0, , 界符, 10001110,%10c\n",x,ch);
x++;
break;
}
}
if(ch==')')
{
if(find2(p)==0) //檢驗" )"是否匹配
{
Form1->Edit6->Text=ch;
Form1->StringGrid1->Cells[5][x]=")";
Form1->StringGrid1->Cells[4][x]="error";
Form1->StringGrid1->Cells[3][x]="字符串匹配";
Form1->StringGrid1->Cells[2][x]="符串與 \")\"";
Form1->StringGrid1->Cells[1][x]="無 \"(\" 字";
Form1->StringGrid1->Cells[0][x]=x;
if(ssj==0)
fprintf(fp2,"%10d, error, error, error, error,%10c\n",x,ch);
x++;
return p;
}
else
{
Form1->StringGrid1->Cells[5][x]=ch;
Form1->StringGrid1->Cells[4][x]=10001111;
Form1->StringGrid1->Cells[3][x]="界符";
Form1->StringGrid1->Cells[2][x]="";
Form1->StringGrid1->Cells[1][x]='0';
Form1->StringGrid1->Cells[0][x]=x;
Form1->Edit6->Text=ch;
if(ssj==0)
fprintf(fp2,"%10d, 0, , 界符, 10010000,%10c\n",x,ch);
x++;
break;
}
}
if(ch=='{')
{
if(find3(p)==0) //檢驗"{ "是否匹配
{
Form1->Edit6->Text=ch;
Form1->StringGrid1->Cells[5][x]="{";
Form1->StringGrid1->Cells[4][x]="error";
Form1->StringGrid1->Cells[3][x]="字符串匹配";
Form1->StringGrid1->Cells[2][x]="符串與 \"{\" ";
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -