資源簡(jiǎn)介
C語(yǔ)言子集編譯器,采用的LL1語(yǔ)義分析法 通過(guò)TXT文檔源代碼可得到最終的4元式中間代碼。

代碼片段和文件信息
#include?
#include?
#include?
#define?E?-1
#define??FLAG?100
#define?ACC?1000
//文法規(guī)則結(jié)構(gòu)
struct?rule
{
char?left[2];
char?right[10];
};
//鏈表符號(hào)結(jié)點(diǎn)
struct?word
{
char?w[10];
struct?word?*next;
};
//狀態(tài)棧結(jié)點(diǎn)結(jié)構(gòu)
struct?state
{
int?s;
struct?state?*next;
};
struct?word?*tem_name_list;???//臨時(shí)變量存放列表
struct?formula?*four_item; ??//四元式鏈表
int?_i;??//四元式編號(hào)
int?beg[100];???//存放要回填的四元式的編號(hào)(把需要回填的四元式存起來(lái))
int?beg_i;??//這個(gè)就是回填的四元式數(shù)組下標(biāo)(就是上一數(shù)組的專用下標(biāo));
int?i_i;??//生成四元式的標(biāo)號(hào)(每產(chǎn)生一個(gè)中間變量就進(jìn)行加1操作)
//添加結(jié)點(diǎn)到鏈表,其實(shí)下面的鏈表就是一棧
void?add_list(struct?word?**headchar?*p);
//n個(gè)結(jié)點(diǎn)出棧
void?pop(struct?word?**headint?n);
//添加結(jié)點(diǎn)到狀態(tài)棧(狀態(tài)m進(jìn)棧)
void?state_add(struct?state?**headint?m);
//n個(gè)狀態(tài)結(jié)點(diǎn)出棧
void?state_pop(struct?state?**headint?n);
//在字符鏈表中查找單詞是否已經(jīng)存在,存在返回0,不存在返回-1
int?find_word(struct?word?*listchar?*p);
//判斷一個(gè)標(biāo)識(shí)符是否合法合法返回0,不合法返回-1
int?is_identifier(char?*p);
//判斷一個(gè)單詞是否是一個(gè)整數(shù),是返回0,不是返回-1
int?is_int(char?*p);
struct?word?*key_word;?????//保留關(guān)鍵字鏈表
struct?word?*identifier;???//用戶自定義標(biāo)識(shí)符
struct?word?*operation;????//運(yùn)算符
struct?word?*boundary;?????//界符
//四元式鏈表結(jié)點(diǎn)結(jié)構(gòu)
struct?formula
{
int?i;??????????//四元式編號(hào)
char?op[10];???//操作符
char?p1[10];????//
char?p2[10];
char?res[10];???
struct?formula?*next;
};
//文法規(guī)則矩陣
?struct?rule?rule_gather[27];
//產(chǎn)生式初始化
?void?init_rule();
?//SLR(1)分析表
//查找并返回單詞對(duì)應(yīng)SLR(1)分析表中的列號(hào)如果不存在,則返回-1
int?find_num(const?char?*p);
//計(jì)算一個(gè)字符串有多少個(gè)字符(以便于彈棧出棧操作)
int?word_num(const?char?*p);
//產(chǎn)生一個(gè)新的臨時(shí)變量T1T2、、、、
char?*create_tem(char?*p);
//打印出一個(gè)四元式(加入到四元式鏈表中)
void?printf_four(char?*operchar?*p1char?*p2char?*res);
//對(duì)歸約時(shí)會(huì)改變語(yǔ)義棧的規(guī)則編寫語(yǔ)義子程序
void?r_16(struct?word?**yuyi_stackchar?*p1char?*p2);
void?r_18(struct?word?**yuyi_stackchar?*p1char?*p2char?*tem);
void?r_19(struct?word?**yuyi_stackchar?*p1char?*p2char?*tem);
void?r_21(struct?word?**yuyi_stackchar?*p1char?*p2char?*tem);
void?r_22(struct?word?**yuyi_stackchar?*p1char?*p2char?*tem);
void?r_26(struct?word?**yuyi_stackchar?*p1);
//根據(jù)規(guī)則編號(hào),調(diào)用相應(yīng)的語(yǔ)義子程序(參數(shù)為語(yǔ)義棧,產(chǎn)生式編號(hào),得到的字符)
void?call_r(struct?word?**yuyi_stackint?mchar?*input_word);
//語(yǔ)法分析,整個(gè)程序語(yǔ)法正確返回0,否則返回-1
int?syntax_analyze(FILE?*fp);
//添加結(jié)點(diǎn)到鏈表,其實(shí)下面的鏈表就是一棧
void?add_list(struct?word?**headchar?*p)
{
if(*head==NULL)
{
*head=(struct?word*)malloc(sizeof(struct?word));
strcpy((*head)->wp);
(*head)->next=NULL;
}
else
{
struct?word?*tem=(struct?word*)malloc(sizeof(struct?word));
strcpy(tem->wp);
tem->next=*head;
*head=tem;
}
}
//n個(gè)結(jié)點(diǎn)出棧
void?pop(struct?word?**headint?n)
{
struct?word?*tem;
if(n<1)
return;
while(n)
{
if(*head==NULL)
return;
tem=*head;
*head=(*head)->next;
free(tem);
n--;
}
}
//添加結(jié)點(diǎn)到狀態(tài)棧,即入棧
void?state_add(struct?state?**headint?m)
{
if(*head==NULL)
{
*head=(struct?state*)malloc(sizeof(struct?state));
(*head)->s=m;
(*head)->next=NULL;
}
else
{
struct?state?*tem=(struct?state*)malloc(sizeof(s
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????????40??2010-01-13?17:04??C語(yǔ)言子集編譯器\error.txt
?????文件?????????49??2010-01-13?17:01??C語(yǔ)言子集編譯器\zm5.txt
?????文件?????????42??2010-01-12?18:30??C語(yǔ)言子集編譯器\zm1.txt
?????文件?????????52??2010-01-13?17:04??C語(yǔ)言子集編譯器\zm2.txt
?????文件?????????52??2010-01-13?10:46??C語(yǔ)言子集編譯器\zm3.txt
?????文件?????????59??2010-01-13?17:03??C語(yǔ)言子集編譯器\zm4.txt
?????文件??????30486??2010-01-12?18:31??C語(yǔ)言子集編譯器\analy.cpp
?????文件??????????0??2009-12-25?01:42??C語(yǔ)言子集編譯器\analy.h
?????文件????????214??2010-01-13?17:18??C語(yǔ)言子集編譯器\analy_res.txt
?????文件??????21320??2010-01-12?20:48??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.APS
?????文件???????1621??2010-01-12?20:48??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.clw
?????文件???????2035??2009-12-15?21:20??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.cpp
?????文件???????4542??2009-12-28?09:42??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.dsp
?????文件????????555??2009-12-15?21:20??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.dsw
?????文件???????1311??2009-12-15?21:20??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.h
?????文件?????148480??2010-01-13?17:22??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.ncb
?????文件??????????0??2009-12-25?13:11??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.ncb?(Can‘t?open)
?????文件????????264??2010-01-13?17:18??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.plg
?????文件???????6061??2010-01-12?15:53??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.rc
?????文件???????7185??2010-01-12?15:50??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器Dlg.cpp
?????文件???????1409??2009-12-28?10:19??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器Dlg.h
?????文件????????115??2010-01-13?17:18??C語(yǔ)言子集編譯器\four.txt
?????文件???????3699??2009-12-15?21:20??C語(yǔ)言子集編譯器\ReadMe.txt
?????文件???????1107??2010-01-12?15:46??C語(yǔ)言子集編譯器\resource.h
?????文件???????1159??2009-12-24?10:58??C語(yǔ)言子集編譯器\show_result.cpp
?????文件???????1189??2009-12-28?09:16??C語(yǔ)言子集編譯器\show_result.h
?????文件????????217??2009-12-15?21:20??C語(yǔ)言子集編譯器\StdAfx.cpp
?????文件???????1054??2009-12-15?21:20??C語(yǔ)言子集編譯器\StdAfx.h
?????文件?????????66??2010-01-13?17:18??C語(yǔ)言子集編譯器\zm0.txt
?????文件??????49664??2010-01-13?17:22??C語(yǔ)言子集編譯器\C語(yǔ)言子集編譯器.opt
............此處省略24個(gè)文件信息
評(píng)論
共有 條評(píng)論