我有一个生成和错误的方法,预期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);
}
Run Code Online (Sandbox Code Playgroud)
非常感激任何的帮助.
这条线
else if (numvalue = 0) { **//This is where it highlights my error**
Run Code Online (Sandbox Code Playgroud)
缺少一个等号,即
else if (numvalue == 0) { **//This is where it highlights my error**
Run Code Online (Sandbox Code Playgroud)