operations[lastOperation] = null;
isFirst = true;
} else if (word == C_R_GROUP) {
while (true) {
if (lastOperation < 0) {
throw new ParseException("缺失左括号");
}
Operation op = operations[lastOperation];
lastOperation--;
if (op != null) {
expressionSize -= op.process(expressions, expressionSize, mode);
} else {
break;
}
}
isFirst = false;
} else {
for (Operation op : opers) {
outer: for (Object[] name : op.names) {
// 有一些操作符是由一组汉字组成的, 需要比较每一个
int len = name.length;
int index = i + len - 1;
if (index < end) {
for (; index >= i; index--) {
if (!name[index - i].equals(words[index])) {
continue outer;
}
}
// 如果栈内存在优先级较高的符号, 需要将数据弹出栈
int priority = op.priority;
for (; lastOperation >= 0; lastOperation--) {
Operation tmp = operations[lastOperation];
if ((tmp != null) && (priority <= tmp.priority)) {
expressionSize -= tmp.process(expressions, expressionSize,
mode);
} else {
break;
}
}
lastOperation++;
operations[lastOperation] = op;
i += len;
continue main;
}
}
isFirst = true;
}
throw new ParseException("不能识别的运算符");
}
}
i++;
}
// 处理完表达式后, 将所有的数据弹出栈
for (; lastOperation >= 0; lastOperation--) {
expressionSize -= operations[lastOperation].process(expressions,
expressionSize, mode);
}
if (expressionSize == 1) {
return expressions[0];
} else {
throw new ParseException("表达式语法错误");
}
}