91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

c0文法的編譯器,詞法分析, 文法分析,目標(biāo)代碼生成,目標(biāo)代碼的執(zhí)行系統(tǒng)一應(yīng)俱全。為北航編譯技術(shù)的課程設(shè)計之一。 另有c0文法編譯器的java實(shí)現(xiàn),包含代碼優(yōu)化(dag圖優(yōu)化,刪除公共子表達(dá)式、刪除無效賦值等)、寄存器分配,目標(biāo)代碼為匯編碼。需要者請單獨(dú)跟本人聯(lián)系。

資源截圖

代碼片段和文件信息

#include
#include
#include
#include
#include“Compiler.h“


char?name[MAXC][MAXWORD]; //用來存儲標(biāo)識符
int?NumOfC=1; //符號表內(nèi)元素的個數(shù)
Character?Symlist[MAXC]; ????//符號表
int?numoflev[MAXLEV]; //各層的表中變量數(shù)

opr??pcode[MAXOP]; //存Pcode指令
int?oprnum; //指令數(shù)

int?stack[MAXGO]; //Pcode解釋執(zhí)行階段的堆棧
int?dl[MAXGOLEV]bl[MAXGOLEV]; ????//stack堆棧運(yùn)行過程中的指針
int?linenum=1; ????? //源程序每行的代號
int?errornum=0error[MAXERROR]errorline[MAXERROR];
int?gonum=0dlnum=0blnum=0;
int?type=0;
int?snum=0;
int?start;
int?lev=1;
int?breakoprIsbreak=0;
int?typeofexp1=11?typeofexp2=12;
int?oprnumcase=0;
int?Isret=1;




//字符獲取和處理
int?getsym()
{
char?chtmp;
int?ijm;

ch=fgetc(FIN);
while(isspace(ch))//處理空格
{
putc(chFOUT);
if(ch==‘\n‘)
{
linenum++;
printf(“%d:\t“l(fā)inenum);
}
ch=fgetc(FIN);
}

i=0;
Word[i]=ch;
i++;

//token處理
if(isalpha(ch))
{
putc(chFOUT);
ch=fgetc(FIN);
while(isalpha(ch)||isdigit(ch)||(ch==‘_‘))??????//加入下劃線
{
Word[i]=ch;
i++;

/*if(i==MAXWORD)
{
errorline[errornum]=linenum;
error[errornum++]=1;
i--;
Word[i]=‘\0‘;
putc(chFOUT);
ch=fgetc(FIN);

while(isalpha(ch)||isdigit(ch))
{
putc(chFOUT);
}
ungetc(chFIN);
return?1;//是標(biāo)識符
}*/
putc(chFOUT);
ch=fgetc(FIN);
}
ungetc(chFIN);
Word[i]=‘\0‘;??

for(m=0;m {
if(!(strcmp(Keyword[m]Word))) //讀取的字符串符合對key?word的判斷
{
if(m+10==12)
return?1;
return?m+10;//返回相應(yīng)的keyword的對應(yīng)數(shù)字
}
}
if(m==kk){
return?1;//不是key?word是標(biāo)識符
}
}

//數(shù)值處理
if(isdigit(ch))
{
putc(chFOUT);

while(isdigit((ch=fgetc(FIN))))
{
putc(chFOUT);
Word[i++]=ch;
if(i==MAXWORD)
{
errorline[errornum]=linenum;
error[errornum++]=1;
Word[--i]=‘\0‘;
ch=fgetc(FIN);
while(isdigit(ch))
{
putc(chFOUT);
}
num=atoi(Word);//將字符串轉(zhuǎn)化為對應(yīng)的數(shù)字
ungetc(chFIN);
return?2;//是數(shù)字
}

}
ungetc(chFIN);
Word[i]=‘\0‘;
num=atoi(Word);//將字符串轉(zhuǎn)化為對應(yīng)的數(shù)字
return?2;//是數(shù)字
}


//分界符
i=34;
putc(chFOUT);
switch(ch){
case‘\‘‘:
ch=fgetc(FIN);
if(ch==‘+‘||ch==‘-‘||ch==‘*‘||ch==‘\‘‘||isalpha(ch))?//對應(yīng)于printf語句中的各種參數(shù)
{
cischar=ch;
putc(chFOUT);
if?((ch=fgetc(FIN))==‘\‘‘)
{
putc(chFOUT);
return?4;//字符
}
else?
{
putc(chFOUT);
errorline[errornum]=linenum;
error[errornum++]=3;
return?-1;
}
}
case‘“‘:
j=0;
while((ch=fgetc(FIN))!=‘“‘)//若不是非空串
{
putc(chFOUT);
sisstring[j++]=ch;

if(j==MAXLENGTH)
{
printf(“warning!字符串過長\n“);
sisstring[--j]=‘\0‘;
putc(chFOUT);

ch=fgetc(FIN);
while(ch!=‘“‘)
{
putc(chFOUT);
j++;
if(ch==EOF||j>100) //字符串過長或缺少反引號
{
errorline[errornum]=linenum;

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????36246??2009-04-11?21:19??Compiler.cpp

?????文件???????4263??2009-04-11?21:24??Compiler.h

-----------?---------??----------?-----??----

????????????????40509????????????????????2


評論

共有 條評論