当前位置:文档之家› 编译原理(求First集)

编译原理(求First集)


4、运行结果分析 5、总结
2、分析、设计、实现 通过对产生式的顺序扫描,运用上述规则,把每种规则都转换为相应的算法,经过规则后 将产生的 First 集存下来。 流程图 3、函数与过程的功能(MFC) CString CFirstAndFollow::First(char Vn,char PVn) { CString result,tmpresult; char tmpmid; int tmpflag; if(Vns.Find(Vn,0)==-1&&Vn!=';'&&Vn!='|') { result.Insert(result.GetLength(),Vn); return result; } for(int ix=0;ix<Vpro.GetLength();ix++) { ix=Vpro.Find(Vn,ix); if(Vpro.GetAt(ix-1)==';') { tmpflag=ix; break; } } tmpflag+=3; for(ቤተ መጻሕፍቲ ባይዱnt index=tmpflag;index<Vpro.GetLength();index++) { char tmp=Vpro.GetAt(index); tmpmid=tmp; if(Vns.Find(tmp,0)>=0) // Vn { if(tmp==PVn || tmp==Vn) { do
1、问题描述
题目: First 集和 Follow 集生成算法模拟 设计一个由正规文法生成 First 集和 Follow 集并进行简化的算法动态模拟。 动态模拟算法的基本功能是: ⅰ. 输入一个文法 G; ⅱ. 输出由文法 G 构造 FIRST 集的算法; ⅲ. 输出 First 集; ⅳ. 输出由文法 G 构造 FOLLOW 集的算法; ⅴ. 输出 FOLLOW 集。
{ index++; tmpmid=Vpro.GetAt(index); }while(tmpmid!='|'&&tmpmid!=';'); } else { CString tmpr=First(tmp,PVn); if(tmpr.Find('_',0)==-1) //Vn { tmpflag=tmpresult.Find('_',0); while(tmpflag>=0) { tmpresult.Delete(tmpflag,1); tmpflag=tmpresult.Find('_',0); } index--; do { index++; tmpmid=Vpro.GetAt(index); }while(tmpmid!='|'&&tmpmid!=';'); } else // Vn { tmpmid=Vpro.GetAt(index); } tmpresult+=tmpr; } } else { if(tmp!='|'&&tmp!=';') { tmpflag=tmpresult.Find('_',0); while(tmpflag>=0) { tmpresult.Delete(tmpflag,1); tmpflag=tmpresult.Find('_',0); } if(tmpresult.Find(tmp,0)==-1) { tmpresult.Insert(tmpresult.GetLength(),tmp); }
index--; do { index++; tmpmid=Vpro.GetAt(index); }while(tmpmid!='|'&&tmpmid!=';'); } } if(tmpmid==';'||tmpmid=='|') { for(int ii=0;ii<tmpresult.GetLength();ii++) //insert follow { if(result.Find(tmpresult.GetAt(ii),0)==-1) result.Insert(result.GetLength(),tmpresult.GetAt(ii)); } if(tmpmid==';') break; tmpresult.Empty(); } } return result; }
相关主题