資源簡介
南開大學(xué)的編譯原理期末作業(yè),實(shí)現(xiàn)一個(gè)編譯器,可以實(shí)現(xiàn)將程序源代碼轉(zhuǎn)換為匯編程序然后執(zhí)行

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
using?namespace?std;
/**********類編號(hào)***********/
#define?AC 1<<30
#define?Keyword 1 //關(guān)鍵字?
#define?Identifier 2 //標(biāo)識(shí)符?
#define?Integer 3 //無符號(hào)整數(shù)?
#define?Float 4 //無符號(hào)浮點(diǎn)數(shù)?
#define?ConstChar 5 //字符常量?
#define?ConstString 6 //字符串常量?
#define?Operator 7 //操作符?
#define?Punctuation 8 //標(biāo)點(diǎn)符號(hào)?
#define?Logical 9 //邏輯運(yùn)算符?
#define?Relational 10 //關(guān)系運(yùn)算符?
#define?Comments 0 //注釋?
#define?IllegalIdentifier -2 //非法標(biāo)識(shí)符?
#define?IllegalFloat -4 //非法無符號(hào)浮點(diǎn)數(shù)?
#define?IllegalConstChar -5 //非法字符常量?
#define?IllegalConstString -6 //非法字符串常量?
#define?IllegalChar -8 //非法字符?
const?int?number_of_keywords?=?36; //關(guān)鍵字?jǐn)?shù)目?
const?int?max_of_argv?=?20; //參數(shù)字符串最長長度?
const?int?max_of_operator?=?10; //操作符字符串最長長度
const?int?number_of_char?=?15; //文法中出現(xiàn)的符號(hào)數(shù)量?
const?int?number_of_grammer?=?20; //文法數(shù)量
typedef?struct?KeyWordsTrie?{ //字典樹結(jié)構(gòu)體?
int?flag; //標(biāo)記尾部?
struct?KeyWordsTrie*?next[26]; //下一級(jí)指針?
}?KeyWordsTrie;
typedef?struct?Quadruple?{
char?op[max_of_operator]; //操作符字符串?
char?argv1[max_of_argv]; //參數(shù)1字符串?
char?argv2[max_of_argv]; //參數(shù)2字符串?
char?result[max_of_argv]; //結(jié)果字符串?
}Quad;
typedef?struct?Word?{//單詞結(jié)構(gòu)體?
int?type; //單詞類型
char?code; //單詞代號(hào)?
string?value; //單詞真值
bool?operator==(struct?Word?ot)?{ //運(yùn)算符重載?判斷兩個(gè)單詞是否相等?
if(type?==?ot.type?&&?value?==?ot.value)?{
return?true;
}
return?false;
}
}Word;
typedef?struct?Symbol?{ //符號(hào)結(jié)構(gòu)體?
Word?word; //單詞
int?Place; //在符號(hào)表中位置
int?TC; //真鏈
int?FC; //假鏈
int?Chain; //鏈,一般為假鏈
int?LoopStart; //循環(huán)開始
}Sym;
/*********詞法分析變量***********/
string?text; //讀入的代碼?
KeyWordsTrie?*keywords; //關(guān)鍵字字典樹?
/*********語法分析變量***********/
string?*G; //候選式內(nèi)容?
char?*reduction; //第i個(gè)產(chǎn)生式應(yīng)該被規(guī)約成的非終結(jié)符?
int?**SLR_Table;? //負(fù)數(shù):Sj正數(shù):Rj零:error?
char?ch_num[128]; //存儲(chǔ)不同字符對(duì)應(yīng)的SLR(1)表的列?
/*********語義分析變量**********/
int?NXQ?=?1; //當(dāng)前四元式序號(hào)?
int?Ntemp?=?0; //臨時(shí)變量個(gè)數(shù)?
vector?quadList; //四元式列表?
vector?symbol_table; //符號(hào)表?
Sym?symbols[number_of_char];//歸約符號(hào)表
void?(*func[number_of_grammer+1])();//語義處理函數(shù)指針
/**************詞法分析函數(shù)聲明**************/
KeyWordsTrie*?getKeyWordsTrie(); //構(gòu)造關(guān)鍵字字典樹
bool?isKeyword(KeyWordsTrie*?const?string);//判斷當(dāng)前單詞是否是關(guān)鍵字
bool?isPunctuation(const?char); //判斷當(dāng)前單詞是否是標(biāo)點(diǎn)符號(hào)
char?getcharFrom(FILE*); //從源代碼文件中獲取一個(gè)字符
void?retract(FILE*); //回退一個(gè)字符
Word?Scanner(FILE*); //詞法分析函數(shù)
/**************語法分析函數(shù)聲明**************/
void?readSLR(); //讀入語法和它的SLR(1)信息?
void?freeMemeory(); //釋放內(nèi)存空間?
void?read(queue&?FILE*);//讀入要識(shí)別的句子?
void?grammar_analysis(FILE*);//語法分析總控程序?
/*************語義處理函數(shù)聲明***************/
int?NewTemp(); //申請(qǐng)臨時(shí)變量?
int?Entry(Word);? //查詢符號(hào)表,不存在則?
void?Gen(const?char*?int?int?int); //生成四元式?
void?BackPatch(int?int); //回填
int?Merge(int?int); //歸并真假鏈?
int?getIndex(char); //獲得全局符號(hào)
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-10-10?14:11??編譯原理\
?????目錄???????????0??2018-10-09?14:39??編譯原理\綜合\
?????文件???????24552??2018-10-09?13:58??編譯原理\綜合\Complier.cpp
?????文件?????2208245??2018-10-09?14:39??編譯原理\綜合\Complier.exe
?????文件??????????61??2018-10-09?13:58??編譯原理\綜合\code.in
?????文件????????5296??2018-10-09?14:40??編譯原理\綜合\complier.out
?????文件????????1008??2018-10-09?13:59??編譯原理\綜合\ex
?????目錄???????????0??2018-10-09?14:38??編譯原理\詞法分析\
?????文件???????12367??2018-10-09?14:00??編譯原理\詞法分析\WordAnlayse.cpp
?????文件?????1937148??2018-10-09?14:38??編譯原理\詞法分析\WordAnlayse.exe
?????文件?????????112??2018-10-09?14:39??編譯原理\詞法分析\code.in
?????文件?????????243??2018-10-09?14:39??編譯原理\詞法分析\words.out
?????目錄???????????0??2018-10-09?13:59??編譯原理\語義分析\
?????文件???????24475??2018-10-09?13:59??編譯原理\語義分析\SemanticAnlayse.cpp
?????文件?????2136053??2018-10-09?13:59??編譯原理\語義分析\SemanticAnlayse.exe
?????文件??????????24??2018-10-09?13:59??編譯原理\語義分析\code.in
?????文件????????1008??2018-10-09?13:59??編譯原理\語義分析\ex
?????文件??????490838??2018-10-09?13:58??編譯原理\語義分析\語義分析.zip
?????目錄???????????0??2018-10-09?14:00??編譯原理\語法分析\
?????文件???????16931??2018-10-09?13:59??編譯原理\語法分析\GrammarAnlayse.cpp
?????文件?????2080436??2018-10-09?14:00??編譯原理\語法分析\GrammarAnlayse.exe
?????文件???????24651??2018-10-09?13:59??編譯原理\語法分析\SLR自動(dòng)生成.cpp
?????文件?????2470581??2018-10-09?14:00??編譯原理\語法分析\SLR自動(dòng)生成.exe
?????文件??????????26??2018-10-09?14:00??編譯原理\語法分析\code.in
?????文件?????????124??2018-10-09?14:00??編譯原理\語法分析\data.in
?????文件???????22542??2018-10-09?13:59??編譯原理\語法分析\data.out
?????文件????????1008??2018-10-09?13:59??編譯原理\語法分析\ex
?????文件????????1772??2018-10-09?13:59??編譯原理\語法分析\grammar.out
?????文件????????2002??2018-10-09?13:59??編譯原理\語法分析\if-else.info
?????文件????????1923??2018-10-09?13:59??編譯原理\語法分析\while.info
?????文件??????478963??2018-10-09?13:59??編譯原理\語法分析\語法分析.zip
............此處省略0個(gè)文件信息
評(píng)論
共有 條評(píng)論