資源簡介
武漢大學(xué)cmm解釋器構(gòu)造實踐課程作業(yè),包含詞法分析器 語法分析器 語義分析和界面。

代碼片段和文件信息
package?com.vincent.compiler;
import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.StringReader;
import?java.util.ArrayList;
import?java.util.linkedList;
import?com.vincent.model.ConstVar;
import?com.vincent.model.Token;
import?com.vincent.model.TreeNode;
public?class?CMMLexer?{
//?注釋的標志
private?boolean?isNotation?=?false;
//?錯誤個數(shù)
private?int?errorNum?=?0;
//?錯誤信息
private?String?errorInfo?=?““;
//?分析后得到的tokens集合,用于其后的語法及語義分析
private?ArrayList?tokens?=?new?ArrayList();
//?分析后得到的所有tokens集合,包含注釋、空格等
private?ArrayList?displayTokens?=?new?ArrayList();
//?讀取CMM文件文本
private?BufferedReader?reader;
//文本緩存
private?static?BufferedReader?mBufferedReader;
????private?static?int?currentInt;
????private?static?char?currentChar;
????private?static?int?lineNo;
public?boolean?isNotation()?{
return?isNotation;
}
public?void?setNotation(boolean?isNotation)?{
this.isNotation?=?isNotation;
}
public?int?getErrorNum()?{
return?errorNum;
}
public?void?setErrorNum(int?errorNum)?{
this.errorNum?=?errorNum;
}
public?String?getErrorInfo()?{
return?errorInfo;
}
public?void?setErrorInfo(String?errorInfo)?{
this.errorInfo?=?errorInfo;
}
public?ArrayList?getTokens()?{
return?tokens;
}
public?void?setTokens(ArrayList?tokens)?{
this.tokens?=?tokens;
}
public?ArrayList?getDisplayTokens()?{
return?displayTokens;
}
public?void?setDisplayTokens(ArrayList?displayTokens)?{
this.displayTokens?=?displayTokens;
}
/**
?*?識別字母
?*?
?*?@param?c
?*????????????要識別的字符
?*?@return
?*/
private?static?boolean?isLetter(char?c)?{
if?((c?>=?‘a(chǎn)‘?&&?c?<=?‘z‘)?||?(c?>=?‘A‘?&&?c?<=?‘Z‘)?||?c?==?‘_‘)
return?true;
return?false;
}
/**
?*?識別數(shù)字
?*?
?*?@param?c
?*????????????要識別的字符
?*?@return
?*/
private?static?boolean?isDigit(char?c)?{
if?(c?>=?‘0‘?&&?c?<=?‘9‘)
return?true;
return?false;
}
/**
?*?識別正確的整數(shù):排除多個零的情況
?*?
?*?@param?input
?*????????????要識別的字符串
?*?@return?布爾值
?*/
private?static?boolean?matchInteger(String?input)?{
if?(input.matches(“^-?\\d+$“)?&&?!input.matches(“^-?0{1}\\d+$“))
return?true;
else
return?false;
}
/**
?*?識別正確的浮點數(shù):排除00.000的情況
?*?
?*?@param?input
?*????????????要識別的字符串
?*?@return?布爾值
?*/
private?static?boolean?matchReal(String?input)?{
if?(input.matches(“^(-?\\d+)(\\.\\d+)+$“)
&&?!input.matches(“^(-?0{2}+)(\\.\\d+)+$“))
return?true;
else
return?false;
}
/**
?*?識別正確的標識符:有字母、數(shù)字、下劃線組成,必須以字母開頭,不能以下劃線結(jié)尾
?*?
?*?@param?input
?*????????????要識別的字符串
?*?@return?布爾值
?*/
private?static?boolean?matchID(String?input)?{
if?(input.matches(“^\\w+$“)?&&?!input.endsWith(“_“)
&&?input.substring(0?1).matches(“[A-Za-z]“))
return?true;
else
return?false;
}
/**
?*?識別保留字
?*?
?*?@param?str?要分析的字符串
?*?@return?布爾值
?*/
private?static?boolean?isKey(String?str)?{
if?(str.equals(ConstVar.IF)?||?str.equals(ConstVar.ELSE)
||?str.equals(ConstVar.WHILE)?||?str.equals
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-01-07?03:55??CMMLexer\
?????文件?????????397??2018-12-31?12:22??CMMLexer\.classpath
?????文件?????????384??2018-12-31?12:22??CMMLexer\.project
?????目錄???????????0??2019-01-07?03:55??CMMLexer\.settings\
?????文件?????????598??2018-12-31?12:22??CMMLexer\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2019-01-07?03:55??CMMLexer\bin\
?????目錄???????????0??2019-01-07?03:55??CMMLexer\bin\com\
?????目錄???????????0??2019-01-07?03:55??CMMLexer\bin\com\vincent\
?????目錄???????????0??2019-01-07?03:55??CMMLexer\bin\com\vincent\compiler\
?????文件???????15492??2019-01-07?02:26??CMMLexer\bin\com\vincent\compiler\CMMLexer.class
?????目錄???????????0??2019-01-07?03:55??CMMLexer\bin\com\vincent\main\
?????文件????????1029??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????文件?????????848??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????文件?????????869??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????文件????????1717??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????文件?????????831??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????文件?????????762??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????文件?????????756??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????文件????????1127??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????文件?????????710??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????文件????????1026??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????文件???????12885??2019-01-07?02:26??CMMLexer\bin\com\vincent\main\Compilerfr
?????目錄???????????0??2019-01-07?03:55??CMMLexer\bin\com\vincent\model\
?????文件????????1424??2019-01-07?02:26??CMMLexer\bin\com\vincent\model\ConstVar.class
?????文件????????5433??2019-01-07?02:26??CMMLexer\bin\com\vincent\model\Token.class
?????文件????????2555??2019-01-07?02:26??CMMLexer\bin\com\vincent\model\TokenList.class
?????文件????????1959??2019-01-07?02:26??CMMLexer\bin\com\vincent\model\TreeNode.class
?????目錄???????????0??2019-01-07?03:55??CMMLexer\bin\com\vincent\util\
?????文件????????6821??2019-01-07?02:26??CMMLexer\bin\com\vincent\util\Codest
?????文件?????????826??2019-01-07?02:26??CMMLexer\bin\com\vincent\util\JCloseableTabbedPane$1.class
?????文件????????1055??2019-01-07?02:26??CMMLexer\bin\com\vincent\util\JCloseableTabbedPane$2.class
............此處省略228個文件信息
評論
共有 條評論