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

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