資源簡介
課設(shè)得了優(yōu) :-)
編譯原理的課程設(shè)計SLR(1)分析器
包含求FIRST,FOLLOW集合 LR(0)項目規(guī)范集組
SLR(1)分析表 SLR(1)分析器

代碼片段和文件信息
#include?
#include?
using?namespace?std;
const?int?maxn=100;
const?int?ERROR=1000000000;
int?binary[31]={12481632641282565121024204840968192
163843276865536131072262144524288104857620971524194304
83886081677721633554432671088641342177282684354565368709121073741824};
struct?G
{
????char?left;
????char?right[100];??
????int?l;
}g[maxn];
struct?G_EXTEND
{
????char?left;
????char?right[100];
????int?l;
????int?dot_pos;
}g_extend[maxn*maxn];
struct?C
{
????int?item[maxn];
????bool?mark[maxn];
????int?l;
}c[maxn];
int?c_len;
char?Vt[maxn]Vn[maxn]Vhash[128];
int?g_cntvt_cntvn_cntg_extend_cnt;
int?first_v[128];
int?go[maxn][128];
struct?FLO
{
????int?t;
????int?start;
}follow[128];
int?ACTION[maxn*maxn][128]GOTO[maxn*maxn][128];
int?State_S[maxn];
char?Sign_S[maxn]a[maxn];
void?FIRST()
{
????bool?visited[maxn]changed[128];
????memset(first_v0sizeof(first_v));
????for(int?i=0;i ????{
????????first_v[Vt[i]]+=binary[i];
????}
????
????int?flag;
????while(1)
????{
????????flag=0;
????????for(int?i=0;i ????????{
??????//?????cout<“< ??????//??????cout< ????????if(g[i].left!=g[i].right[0]?&&?first_v[g[i].right[0]]?&&??!(first_v[g[i].left]&first_v[g[i].right[0]])?)
????????{
????????????first_v[g[i].left]+=first_v[g[i].right[0]];
????????????flag=1;?
????????}
????????}
????????if(!flag)?break;
????}
/*????for(int?i=0;i ????{
????????for(int?ii=0;ii<31;ii++)?
??????????if(first_v[Vn[i]]&binary[ii])?cout< ????????cout< ????}*/
}
void?FOLLOW()
{
????FIRST();
????memset(follow0sizeof(follow));
????follow[Vn[0]].start=1;
????for(int?i=0;i ????{
???????for(int?j=0;j ???????if(!(follow[g[i].right[i]].t&first_v[g[i].right[j+1]]))
???????{
????????????follow[g[i].right[j]].t+=first_v[g[i].right[j+1]];
????????????if(follow[g[i].right[j+1]].start)?follow[g[i].right[j]].start=follow[g[i].right[j+1]].start;
????????}
????}
????
???/*?for(int?i=0;i ????{
????????cout< ????????for(int?j=0;j<31;j++)?if(follow[Vn[i]].t&binary[j])?cout< ????????if(follow[Vn[i]].start)?cout<<“#?“;
????????cout< ????}*/
????
????
????
????while(1)
????{
????????int?flag=0;
????????for(int?i=0;i ????????if(g[i].right[g[i].l-1]>=‘A‘?&&?g[i].right[g[i].l-1]<=‘Z‘)
????????{
????????if(?follow[g[i].left].t?&&?!(follow[g[i].right[g[i].l-1]].t&follow[g[i].left].t))
????????{
????????????flag=1;
????????????follow[g[i].right[g[i].l-1]].t+=follow[g[i].left].t;
????????}
????????else?if(follow[g[i].left].start==1&&follow[g[i].right[g[i].l-1]].start==0)
????????{
????????????flag=1;
????????????follow[g[i].right
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????.CA....????????44??2008-12-07?16:05??SLR(1)\1.in
????.CA....???????910??2008-12-08?17:10??SLR(1)\DATA.h
????.CA....??????5676??2008-12-08?22:06??SLR(1)\Debug\BuildLog.htm
????.CA....????????67??2008-12-08?22:06??SLR(1)\Debug\mt.dep
????.CA....????172032??2008-12-08?22:06??SLR(1)\Debug\SLR(1).exe
????.CA....???????145??2008-12-08?22:06??SLR(1)\Debug\SLR(1).exe.intermediate.manifest
????.CA....????229984??2008-12-08?22:06??SLR(1)\Debug\SLR.obj
????.CA....?????93184??2008-12-08?22:06??SLR(1)\Debug\vc80.idb
????.CA....??????1781??2008-12-08?17:23??SLR(1)\FOLLOW.h
????.CA....???????133??2008-12-08?22:45??SLR(1)\FOLLOW.txt
????.CA....????????74??2008-12-08?22:45??SLR(1)\G.txt
????.CA....???????231??2008-12-08?22:45??SLR(1)\G_extend.txt
????.CA....??????1219??2008-12-08?21:12??SLR(1)\INIT.h
????.CA....???????386??2008-12-08?22:45??SLR(1)\LR(0)Set.txt
????.CA....??????3910??2008-12-08?21:26??SLR(1)\LR0Set.h
????.CA....??????5300??2008-12-08?22:02??SLR(1)\SHOW.h
????.CA....?????15072??2008-12-08?01:08??SLR(1)\slr(1).cpp
????.CA....???1395712??2008-12-08?23:17??SLR(1)\SLR(1).ncb
????.CA....???????876??2008-12-08?16:27??SLR(1)\SLR(1).sln
????.CA..H.?????15360??2008-12-08?23:17??SLR(1)\SLR(1).suo
????.CA....??????3452??2008-12-08?21:13??SLR(1)\SLR(1).vcproj
????.CA....??????1427??2008-12-08?23:17??SLR(1)\SLR(1).vcproj.PC-200811121904.Administrator.user
????.CA....???????510??2008-12-08?22:45??SLR(1)\SLR(1)Grid.txt
????.CA....???????410??2008-12-08?21:33??SLR(1)\SLR.cpp
????.CA....??????2443??2008-12-08?17:51??SLR(1)\SLR1Grid.h
????.CA....??????1637??2008-12-08?22:06??SLR(1)\SLRDFA.h
????.C.D...?????????0??2008-12-08?22:06??SLR(1)\Debug
????.C.D...?????????0??2008-12-08?23:17??SLR(1)
-----------?---------??----------?-----??----
??????????????1951975????????????????????28
............此處省略1個文件信息
評論
共有 條評論