资源描述:
《词法分析器(c#实现)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、/**********************************************************************************************************************写在最前面*词法分析前先将源码预处理,去掉多余的空格和换行以及注释*单词与单词之间最好用空格隔开,否则将被识别为未知符号*************************************************************************************************************
2、*********/usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Collections;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;namespace词法分析{publicpartialclassForm1:Form{privatestaticstring[]保留字={"bool","break","cas
3、e","char","do","double","else","false","float","for","if","int","long","main","new","null","private","protected","public","static","true","try","typeof","unit","void","while","return","short","sizeof","switch"};privatestaticstring[]运算符={"*","/","%","+","-","<<",">>","<",">","<=",">=","==
4、","!=","&","^","
5、","&&","
6、
7、","?:","+=","-=","*=","/=","%=","&=","
8、=","^=","<<=",">>=","="};privatestaticstring[]界符={",",";",".","'","(",")",":","[","]","{","}","/"};privatestaticstring[]标识符;privatestaticstring[]常数;privatestaticstring[]未知符号;privateArrayListtemp=newArrayList();publicForm1(
9、){InitializeComponent();}publicintSearch_Location(stringstr,string[]a)//查找字符编码{for(inti=0;i10、i;for(intj=0;j11、ing[]strr=str[i].Split('/');str[i]=strr[0];}}for(inti=0;i