小编Alp*_*g14的帖子

匹配Curly Brackets

我很难在这段代码中匹配大括号.它一直指示"else"而没有"if"错误,但不确定语法应该如何读取.如果有人可以提供帮助,那将非常感激.这是代码:

private void compileFactor() {
        boolean its_a_variable = theInfo.isVar();
        if (isIdent(theToken)) {
            String ident = theToken;
            theToken = t.token();       // handles var and const cases!

            IdentInfo theInfo = symTable.lookup(ident);
        }


            boolean its_a_variable = theInfo.isVar();
            int theAddr = theInfo.getAddr(); 
            boolean isGlobal = theInfo.getIsGlobal();
            int constValue = theInfo.getValue();

            if (its_a_variable) {   // pld12: CHANGE THIS!!
                int theAddr = theInfo.getAddr(); 
                boolean isGlobal = theInfo.getIsGlobal();
                if (theAddr == -1) t.error("undeclared identifier used in expr: "+ident);
                if (isGlobal) cs.emit(Machine.LOAD, theAddr);
                else cs.emit(Machine.LOADF, theAddr);
            } else …
Run Code Online (Sandbox Code Playgroud)

if-statement

1
推荐指数
1
解决办法
481
查看次数

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 " + …
Run Code Online (Sandbox Code Playgroud)

java boolean

-1
推荐指数
1
解决办法
1320
查看次数

标签 统计

boolean ×1

if-statement ×1

java ×1