将表达式(如 @a - @b + @c)中各部分 解析为token并存放在List中,算法如下:
ExpressUtils.java
public static List<Token> parse(String expr) {
List<Token> tokenList = new ArrayList<Token>();
TokenType type = TokenType.Text;
StringBuffer buf = new StringBuffer();
char[] charArray = expr.toCharArray();
for (int i = 0; i < charArray.length; ++i) {
char ch = charArray[i];
if (ch == '@') {
if (buf.length() > 0) {
tokenList.add(new Token(type, buf.toString()));
}
type = TokenType.Variant;
buf = new StringBuffer();
continue;
}
if (ch == '/' && i < charArray.length - 1 && charArray[i + 1] == '*') {
if (buf.length() > 0) {
tokenList.add(new Token(type, buf.toString()));
}
buf.append("/*");
++i;
type = TokenType.MultiLineComment;
continue;
}
if (ch == '/' && i < charArray.length - 1 && charArray[i + 1] == '/') {
if (buf.length() > 0) {
tokenList.add(new Token(type, buf.toString()));
}
buf.append("//");
++i;
type = TokenType.LineComment;
continue;
}
if (type == TokenType.Variant) {
if (Character.isLetter(ch) || Character.isDigit(ch)) {
buf.append(ch);
} else if (ch == '_') {
buf.append(ch);
} else {
tokenList.add(new Token(type, buf.toString()));
type = TokenType.Text;
buf = new StringBuffer();
--i;
}
continue;
}
if (type == TokenType.Text) {
buf.append(ch);
continue;
}
if (type == TokenType.MultiLineComment) {
if (ch == '*' && i < charArray.length - 1 && charArray[i + 1] == '/') {
buf.append("*/");
++i;
tokenList.add(new Token(type, buf.toString()));
type = TokenType.Text;
buf = new StringBuffer();
continue;
} else {
buf.append(ch);
}
}
if (type == TokenType.LineComment) {
if (ch == '\n') {
buf.append(ch);
tokenList.add(new Token(type, buf.toString()));
type = TokenType.Text;
buf = new StringBuffer();
} else if (ch == '\r') {
buf.append(ch);
if (i < charArray.length - 1 && charArray[i + 1] == '\n') {
buf.append(charArray[i + 1]);
++i;
}
tokenList.add(new Token(type, buf.toString()));
type = TokenType.Text;
buf = new StringBuffer();
} else {
buf.append(ch);
}
continue;
}
}
if (buf.length() > 0) {
tokenList.add(new Token(type, buf.toString()));
}
return tokenList;
}
将java源文件编译成类的Class型实例:JdkCompiler.java/JdkCompileTask.java
public synchronized Class<? extends Expr> compile(JavaSource javaSource) {
compileCount.incrementAndGet();
long startTimeMillis = System.nanoTime();
try {
final DiagnosticCollector<JavaFileObject> errs = new DiagnosticCollector<JavaFileObject>();
JdkCompileTask<Expr> compileTask = new JdkCompileTask<Expr>(classLoader, options);
String fullName = javaSource.getPackageName() + "." + javaSource.getClassName();
return (Class<? extends Expr>) compileTask.compile(fullName, javaSource.getSource(), errs);
} catch (JdkCompileException ex) {
DiagnosticCollector<JavaFileObject> diagnostics = ex.getDiagnostics();
throw new CompileExprException("compile error, source : \n" + javaSource + ", " + diagnostics.getDiagnostics(), ex);
} catch (Exception ex) {
throw new CompileExprException("compile error, source : \n" + javaSource, ex);
} finally {
// 编译时间统计
compileTimeNano.addAndGet(System.nanoTime() - startTimeMillis);
}
}
待研究:
javax.tools.JavaCompiler.JavaCompiler
compiler = javax.tools.ToolProvider.getSystemJavaCompiler().
分享到:
相关推荐
最新阿里云ddns openwrt 插件 luci-app-aliddns_0.4.0-1_all.ipk
最新版本 阿里DDNS ipk包 luci-app-aliddns_0.3.8-1_all.ipk 适用于openwrt
openwrt 阿里DDNS ipk包 luci-app-aliddns_0.4.0-1_all.ipk
K3 路由器 阿里DDNS ipk包 luci-app-aliddns_0.3.0-1_all.ipk
最新版本 K3 路由器 阿里DDNS ipk包 luci-app-aliddns_0.3.8-1_all.ipk
ALI213-PhysX
RS232 Programmer for CHIPSET ALI3510C
目前使用比较多的便宜的CD解码芯片ALI公司的 M5673D的规格说明书。
firmware para decos con chip ali 36xx
ali_repo文件夹下的另一部分ali_repo文件夹下的另一部分
我加入了IPv6自动解析脚本。到手直接用。非常适合家里有群晖NAS但是只有公网IPv6的家庭宽带。绝对是优秀的DDNS方案。 本脚本的工作流程是:对比云端解析记录-> 不存在则添加 -> 存在... ./aliddns.sh [OPTION] <String>
内含ali愚公项目的安装配置细节,与实际使用中需要注意的事项。
ali213pk_setup4.0.2.7
ALI方案M3330EDIY教程ALI方案MALI方案M3330EDIY教程3330EDIY教程ALI方案M3ALI方案M3330EDIY教程330EDIY教程
AliDDNS-v2.0.sh
ali maven setting.xml 配置文件,
ALI3510C RS232 Programmer
Set Top Box ALi 3329E Tools
“Ali巴巴商品信息采集”软件可以为您解决以上问题。本软件是为做网店代理的各位亲专门设计的助手工具,本软件的主要功能是自动化的大批量从指定的阿里巴巴商家网站中搜索读取各项重要的产品信息(包括商品标题、...
RSA ALI 360X TOOL-04