// 处理数值常量
int end = start + 1;
while (end < len) {
char d = line.charAt(end);
if (Character.isJavaIdentifierStart(d)) {
throw new ParseException("数值常量格式错误");
} else if (!Character.isDigit(d)) {
break;
}
end++;
}
int index = words.size() - 1;
if (index > 3 && words.get(index) == Operation.C_SUB
&& words.get(index - 1) == Operation.C_SET) {
// 识别负数
words
.add(new Integer(-Integer.parseInt(line.substring(start, end))));
} else {
words.add(new Integer(line.substring(start, end)));
}
start = end;
continue;
} else if (Character.isLetter(c)) {
// 识别变量名
int end = start + 1;
while (end < len) {
if (!Character.isJavaIdentifierPart(line.charAt(end))) {
break;
}
end++;
}
String name = line.substring(start, end);
if (!fields.containsKey(name)) {
throw new ParseException("变量[" + name + "]不存在");
}
words.add(fields.get(name));
start = end;
continue;
}
}
throw new ParseException("语法错误");
}
return words.toArray();
}