我有一個方法,產生一個int期望,但發現布爾錯誤,但當我切換到一個布爾值它說相同的錯誤,但反向int和布爾值。這裏是我的代碼:INT和布爾錯誤
private void compileDeclaration(boolean isGlobal) {
if (equals(theToken, "int")) {
accept("int");
String ident = theToken;
if (!isIdent(theToken)) t.error("expected identifier, got " + theToken);
else if (isGlobal){
symTable.allocVar(ident, isGlobal);
}
if (!isGlobal) cs.emit(Machine.ALLOC, symTable.stackFrameSize());
//dprint("declaring int " + ident);
theToken = t.token();
accept (";");
} else if (equals (theToken, "final")) {
accept("final");
accept("int");
String ident = theToken;
if (!isIdent(theToken)) t.error("expected identifier, got " + theToken);
theToken = t.token();
accept("=");
int numvalue = new Integer(theToken).intValue();
if (!isNumber(theToken)) t.error("expected number, got " + theToken);
else if (numvalue = 0) { **//This is where it highlights my error**
symTable.allocConst(ident, numvalue);
}
任何幫助將不勝感激。
語言是什麼呢? – ysth 2009-12-07 03:07:57
不錯,你展示的代碼,你只需要顯示錯誤信息,這將更容易發現。我認爲菲利普·甘有正確的答案,你應該讓他接受。 – OscarRyz 2009-12-07 03:30:34