資源描述:
《【精品】詞法分析主體代碼》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystenkData;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystein.10;usingSystem.Collections;namespaceBYYLpublicpartialclassForml:FormStringBuilderglobalBSF=newStringBuilder();String
2、Bui1derglobalBLZ二newStringBui1dor();StringBuilderglobalZS=newStringBuilder();StringBuilderStringBui1derStringBuilderStringBuilderglobalSS二newStringBuilder();global/!7二newStringBuiIder();globalZFC=newStringBuilder();globalBE二newStringBuilder();StringBui1derglobalYSF二newStringBui1der();StringBuilde
3、rglobalJF二newStringBuilder();publicForml()//全局變量存儲(chǔ)標(biāo)識(shí)符//全局變量存儲(chǔ)保留字//全局變量存儲(chǔ)整型常數(shù)//全局變量存儲(chǔ)實(shí)型常數(shù)//全局變量存儲(chǔ)字符常數(shù)//全局變量存儲(chǔ)字符出常數(shù)//全局變量存儲(chǔ)布爾常數(shù)//全局變量存儲(chǔ)運(yùn)算符〃全局變量存儲(chǔ)界符Initiali^eComponentO;privatestringopenCFi1e(){string[]fileName=newstring[l];openC.Filter=〃C語言文件(*.c)
4、*.c〃;openC.VaiidatcNames=true;openC.CheckF訂eExists=
5、true;openC.CheckPalhExists二true;openC.FileName="“;if(openC.ShowDialogO==DialogRcsult.//選擇打開的C語言文件//支持的文件類型//驗(yàn)證用八輸入是否是一個(gè)有效的Windows文件名〃驗(yàn)證路徑有效性〃驗(yàn)證文件有效性//起始?文件名置空0K)fileName二openC.Fi1eNames;}returnfileName[0];}//清空存儲(chǔ)各類單詞符號(hào)的變量privatevoidqk(){globalBE.Clear();globalJF.Clear();globalZS.Clear();globalSS.
6、Clear();globalYSF.Clear();globalZF.Clear();globalZFC.Clear();globalBLZ.Clear();globalBSE.Clear();privatevoidremovedh(stringfileName)//去掉多行注釋{〃讀取文件中c語句代碼FileStrecimfs二newFi1eStream(fi1eName,FileMode.Open);bytc[]arr=newbytc[fs.Length];fs.Read(arr,0,int.Parse(fs>Length.ToStringO));stringtemp二Encodin
7、g.Default.GetString(arr);while(temp.Contains(@〃/*〃))//去掉/*???*/型注釋{intstart二temp.IndexOf(@"7*");intend=temp.IndcxOf(@〃*/〃);temp二temp.Remove(start,end-start+2);}if(DBOperation.QueryBySqll(,zselect*from.Rows.Count>0)//如存儲(chǔ)代碼的表中有數(shù)據(jù)則清空{(diào)_DBOperation.SqlCmdOpcration(''deletefromt_dm〃);}temp=temp.Replace
8、(〃’〃,;DBOperation.Sq1CmdOperation(,zinsertintot_dmvalues(0,J+temp+〃')〃);//將全部代碼存入數(shù)據(jù)庫中//百表冋車,以冋車拆分全部的代碼//刪除數(shù)據(jù)庫中的數(shù)據(jù)DataTabledt=DBOperation.QueryBySqll("selectdmfromt_dm〃);string[]arrStr二dt.Rows[0]["dm"].ToString()?Split(