📄 java词法分析器_ - java - java_开发文档.htm
字号:
<P> /**<BR> * @roseuid 3D9BB07D0239<BR>
*/<BR> public String filtrateSource(char[] Data)
{<BR> String filtratedString =
String.valueOf(Data).trim();<BR> return
filtratedString;<BR> }</P>
<P> /**<BR> * @roseuid 3D9BB9350315<BR>
*/<BR> public void startPretreatment() {<BR>
this.controlThread();<BR>
}<BR>}<BR>4) 扫描子程序:Scaner.java<BR>//Source file:
d:\\JAccidenceAnalyse\\Scaner.java</P>
<P>package JAccidenceAnalyse;</P>
<P>import JAccidenceAnalyse.Buffer.*;</P>
<P>public class Scaner {<BR> public ScanBuffer scanBuffer;
//扫描缓冲区--共享<BR> private String finalAccidence;<BR> private
AccidenceAnalyser aa;<BR> private int BUFFER_SIZE = 100;<BR>
private String toDelString;<BR> private int senLength = 0;<BR>
private char[] sentenceChar = new char[1000];<BR> private String
TOKEN;<BR> private char CHAR;<BR> private int index =
0;<BR> private String IDENTITY = "identity";<BR> private
String DIGIT = "digit";<BR> private String WORD_ERROR_INF =
"在此行发现不能识别的单词,此行分析终止!";<BR> private boolean ASTATE = true;<BR>
/**<BR> * @roseuid 3D9BB9370213<BR> */<BR>
public Scaner(AccidenceAnalyser aa) {<BR> this.aa =
aa;<BR> initBuffer();<BR>
this.finalAccidence = "";<BR>
System.out.println("[INFOR]扫描处理器已经创建!");<BR> }</P>
<P> /**<BR> * @roseuid 3D9BB2860329<BR>
*/<BR> public String readFromBuffer(char[] Data)
{<BR> String toDelString =
String.valueOf(Data);<BR> return toDelString;<BR>
}</P>
<P> /**<BR> * @param tmpString<BR> * @return
String<BR> * @roseuid 3D9BB2D5008D<BR>
*/<BR> public String scan(String toDelString)
{<BR> sentenceChar =
toDelString.toCharArray();<BR> this.senLength =
sentenceChar.length;<BR> int i =
0;<BR> //分析单词<BR> while (this.index
<= this.senLength) {<BR>
//state0:<BR> this.TOKEN =
"";<BR> this.CHAR =
GETBC(sentenceChar);<BR> if (this.CHAR ==
';') {<BR> break;
//';'表示这一行结束<BR>
}<BR>
//进入状态判断<BR> switch (this.CHAR)
{<BR> //judge letter<BR>case
'a':case 'b':case 'c':case 'd':case 'e':case 'f':case 'g':case 'h':case
'i':case 'j':case 'k':<BR>case 'l':case 'm':case 'n':case 'o':case
'p':case 'q':case 'r':case 's':case 't':case 'u':case 'v':case 'w':case
'x':case 'y':<BR>case 'z':case 'A':case 'B':case 'C':case 'D':case
'E':case 'F':case 'G':case 'H':case 'I':case 'J':case 'K':case 'L':case
'M':<BR>case 'N':case 'O':case 'P':case 'Q':case 'R':case 'S':case
'T':case 'U':case 'V':case 'W':case 'X':case 'Y':case 'Z':</P>
<P>
//do<BR> this.TOKEN
= this.CONTACT(TOKEN, CHAR);</P>
<P>
//state1<BR> CHAR =
this.GETCHAR(sentenceChar);<BR>
while (this.ISLETTER(CHAR) || this.ISDIGIT(CHAR))
{<BR>
this.TOKEN = this.CONTACT(this.TOKEN,
CHAR);<BR>
CHAR =
this.GETCHAR(sentenceChar);<BR>
}<BR>
this.RETRACT();</P>
<P>
//state2<BR> if
(aa.keyWordTable.isKeyWord(TOKEN))
{<BR>
this.finalAccidence = this.finalAccidence + "[保留字] "
+<BR>
this.returnAWord(TOKEN) +
"\n";<BR>
}<BR> else
{<BR>
this.finalAccidence = this.finalAccidence + "[标识符] "
+<BR>
this.returnAWord(TOKEN) + "[种别码] "
+<BR>
String.valueOf(aa.classIdentity.findKey(IDENTITY)) +
"\n";<BR> }</P>
<P> //clear up
token<BR> this.TOKEN
= "";<BR> break;</P>
<P> //judge
ditital<BR> case '0':case
'1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case
'9':</P>
<P>
//do<BR> this.TOKEN
= this.CONTACT(TOKEN, CHAR);</P>
<P>
//state3<BR> CHAR =
this.GETCHAR(sentenceChar);<BR>
while (this.ISDIGIT(CHAR))
{<BR>
this.TOKEN = this.CONTACT(TOKEN,
CHAR);<BR>
CHAR =
this.GETCHAR(sentenceChar);<BR>
}<BR>
this.RETRACT();</P>
<P>
//state4<BR>
this.finalAccidence = this.finalAccidence + "[数字] "
+<BR>
this.returnAWord(TOKEN) + "[种别码] "
+<BR>
String.valueOf(aa.classIdentity.findKey(DIGIT)) + "\n";</P>
<P> //clear up
token<BR> this.TOKEN
= "";<BR> break;</P>
<P> case '=':</P>
<P>
//state5<BR>
this.TOKEN = this.CONTACT(TOKEN,
CHAR);<BR>
this.finalAccidence = this.finalAccidence + "[等号] "
+<BR>
this.returnAWord(TOKEN) + "[种别码] "
+<BR>
String.valueOf(aa.classIdentity.findKey(String.valueOf(CHAR)))
+<BR>
"\n";</P>
<P> //clear up
token<BR> this.TOKEN
= "";<BR> break;</P>
<P> case '+':</P>
<P>
//state6<BR>
this.TOKEN = this.CONTACT(TOKEN,
CHAR);<BR>
this.finalAccidence = this.finalAccidence + "[加号] "
+<BR>
this.returnAWord(TOKEN) + "[种别码] "
+<BR>
String.valueOf(aa.classIdentity.findKey(String.valueOf(CHAR)))
+<BR>
"\n";</P>
<P> //clear up
token<BR> this.TOKEN
= "";<BR> break;</P>
<P> case '*':</P>
<P>
//state7<BR>
this.TOKEN = this.CONTACT(TOKEN,
CHAR);<BR> CHAR =
this.GETCHAR(sentenceChar);<BR>
//state8<BR> if
(CHAR == '*')
{<BR>
this.TOKEN = this.CONTACT(TOKEN,
CHAR);<BR>
this.finalAccidence = this.finalAccidence + "[乘方] "
+<BR>
this.returnAWord(TOKEN) + "[种别码] "
+<BR>
String.valueOf(aa.classIdentity.findKey(String.valueOf(CHAR)))
+<BR>
"\n";<BR>
}<BR>
//state9<BR> else
{<BR>
this.finalAccidence = this.finalAccidence + "[乘号] "
+<BR>
this.returnAWord(TOKEN) + "[种别码] "
+<BR>
String.valueOf(aa.classIdentity.findKey(String.valueOf(CHAR)))
+<BR>
"\n";<BR> }</P>
<P> //clear up
token<BR> this.TOKEN
= "";<BR> break;</P>
<P> case ',':</P>
<P>
//state10<BR>
this.TOKEN = this.CONTACT(TOKEN,
CHAR);<BR>
this.finalAccidence = this.finalAccidence + "[逗号] "
+<BR>
this.returnAWord(TOKEN) + "[种别码] "
+<BR>
String.valueOf(aa.classIdentity.findKey(String.valueOf(CHAR)))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -