📄 jmexprparse.java
字号:
ckey = toParse[++JMParse.CurrPos];
continue;
}
//处理数字类型的数据
if ( (ckey > 47) && (ckey < 58)) {
if (symbolType <= 0) {
ParseSymbol(symbolType, key.toString(), stackCalc, cc);
symbolType = 1;
}
key.append(ckey);
ckey = toParse[++JMParse.CurrPos];
continue;
} //数值类型中不能有其他字符
else if (symbolType == 1)
throw new JMParseException("不正确的数字表示法");
//未确定类型的数据
if ( (ckey == 95) || (ckey > 64 && ckey < 91) ||
(ckey > 96 && ckey < 123)) {
if (symbolType <= 0) {
ParseSymbol(symbolType, key.toString(), stackCalc, cc);
symbolType = 5;
}
key.append(ckey);
ckey = toParse[++JMParse.CurrPos];
continue;
}
//处理字符串
if (ckey == '"') {
if (symbolType <= 0){
ParseSymbol(symbolType, key.toString(), stackCalc, cc);
symbolType = 2;
}
else if (symbolType == 2)
symbolType = 3;
else
throw new JMParseException("非法的字符串起始符");
ckey = toParse[++JMParse.CurrPos];
continue;
}
//处理字符串中的转义符
if (ckey == '\\') {
if (symbolType != 2)
throw new JMParseException("非法使用的转义符");
JMParse.CurrPos++;
key.append(toParse[JMParse.CurrPos]);
ckey = toParse[++JMParse.CurrPos];
continue;
}
//对象函数处理
if (ckey == '.') {
if (symbolType == 5) {
symbolType = 7;
//把解到的对象存入数组
postfixExpr[cc.Value] = PropParse.ParseObject(PropParse.FindObject(key.toString()), toParse);
cc.Inc();
} else if (symbolType == 7 || symbolType == 6) {
//如果是连续的或自定义函数返回对象的‘.‘则递归解释对象
postfixExpr[cc.Value - 1] = PropParse.ParseObject(postfixExpr[cc.Value -1], toParse);
}
else throw new JMParseException("非法使用的对象方法引用符");
ckey = toParse[JMParse.CurrPos];
key = key.delete(0, 25);
continue;
}
if (symbolType == 2){
key.append(ckey);
ckey = toParse[++JMParse.CurrPos];
continue;
} else throw new JMParseException(new StringBuffer("非法字符 \"").
append(ckey).append("\" ").toString());
}//while (ckey != 0)
ParseSymbol(symbolType, key.toString(), stackCalc, cc);
//令“#”字符出栈
ParseSymbol(-1, "#", stackCalc, cc);
if (cc.Value == 1)
return postfixExpr[0];
else if (cc.Value == 0)
return null;
//处理转化后的后缀表达式
Object First = null;
Object Second = null;
String cs;
int Index = 0;
for (int i = 0; i < cc.Value; i ++){
if (!isOperator[i])
stackCalc.push(postfixExpr[i]);
else {
Index = ((Integer)postfixExpr[i]).intValue();
if (Index == LEFT_PARENTHESES || Index == RIGHT_PARENTHESES)
throw new JMParseException("非法使用的圆括号");
try {
Second = stackCalc.pop();
cs = Second.getClass().getName();
if (JMParse.COptpriority[Index + 1] == 2)
First = stackCalc.pop();
switch(Index) {
case PLUS:
if (cs.equals("java.lang.Integer"))
stackCalc.push( new Integer(((Integer)First).intValue() +
((Integer)Second).intValue()));
else if (cs.equals("java.lang.String"))
stackCalc.push( new StringBuffer(First.toString()).append(Second.toString()));
break;
case MINUS:
stackCalc.push( new Integer(((Integer)First).intValue() -
((Integer)Second).intValue()));
break;
case MULTIPLY:
stackCalc.push( new Integer(((Integer)First).intValue() *
((Integer)Second).intValue()));
break;
case DIVIDE:
stackCalc.push( new Integer(((Integer)First).intValue() /
((Integer)Second).intValue()));
break;
case PER_CENT:
stackCalc.push( new Integer(((Integer)First).intValue() %
((Integer)Second).intValue()));
break;
case A:
int x = ((Integer)First).intValue();
int z = ((Integer)Second).intValue();
if (z == 0) x = 1;
else if (z == -1) x = 1/x;
else if (z != 1) {
for (int y = 0; y < z - 1; y++)
x = x * x;
}
stackCalc.push(new Integer(x));
break;
case LESS:
stackCalc.push( new Boolean(((Integer)First).intValue() <
((Integer)Second).intValue()));
break;
case MORE:
stackCalc.push( new Boolean(((Integer)First).intValue() >
((Integer)Second).intValue()));
break;
case LESS_EQUAL:
stackCalc.push( new Boolean(((Integer)First).intValue() <=
((Integer)Second).intValue()));
break;
case MORE_EQUAL:
stackCalc.push( new Boolean(((Integer)First).intValue() >=
((Integer)Second).intValue()));
break;
case EQUAL:
if (cs.equals("java.lang.Integer"))
stackCalc.push( new Boolean(((Integer)First).intValue() ==
((Integer)Second).intValue()));
else if (cs.equals("java.lang.Boolean"))
stackCalc.push( new Boolean(((Boolean)First).booleanValue() ==
((Boolean)Second).booleanValue()));
else if (cs.equals("java.lang.String"))
stackCalc.push( new Boolean(((String)First).equals(Second)));
break;
case NOTEQUAL:
if (cs.equals("java.lang.Integer"))
stackCalc.push( new Boolean(((Integer)First).intValue() !=
((Integer)Second).intValue()));
else if (cs.equals("java.lang.Boolean"))
stackCalc.push( new Boolean(((Boolean)First).booleanValue() !=
((Boolean)Second).booleanValue()));
else if (cs.equals("java.lang.String"))
throw new JMParseException("不支持的字符串操作“!”");
break;
case NOT:
stackCalc.push(new Boolean(!((Boolean)Second).booleanValue()));
break;
case AND:
stackCalc.push( new Boolean(((Boolean)First).booleanValue() &&
((Boolean)Second).booleanValue()));
break;
case OR:
stackCalc.push( new Boolean(((Boolean)First).booleanValue() ||
((Boolean)Second).booleanValue()));
}// end switch
} catch (ClassCastException e){
throw new JMParseException(new StringBuffer("操作数不支持的操作“").
append(JMParse.Operator.substring(Index, Index + JMParse.COptpriority[Index + 1])).
append("”").toString());
} catch (EmptyStackException e) {
throw new JMParseException(new StringBuffer("缺少操作数“").
append(JMParse.Operator.substring(Index, Index + JMParse.COptpriority[Index + 1])).
append("”").toString());
}
catch (Exception e){
throw new JMParseException(e.getMessage());
}
} //end if !Operator
} //end for (int i = 0; i < peCurrIndex; i ++)
if (stackCalc.size() > 1)
throw new JMParseException("丢失操作符");
else if(stackCalc.size() == 0)
throw new JMParseException("丢失操作数或\")\"");
else if (stackCalc.size() == 1)
return stackCalc.pop();
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -