[SOLVED] if else conditions not working. T_T
Hello, I am new at this forum.
I have this problem and I dunno what's wrong with my code.
This is a part of my "compiler" project using the java language. This is a method to determine correct declarations of the variables.
I am still testing the "int" data type.
but the problem is... it won't go inside the if(cnemPos1=="int") condition, it goes to the else, even if I cnemPos1 has a value "int". I wonder what's wrong. I hope you can help me out. Thanks a plenty. ^___^
here is my code.
Code:
if(items.contains("=")== true){
int state1 = 0;
int cPos1 = items.indexOf("=");
String cnemPosn = (String)(items.get(cPos1-1));
String cnemPos1 = (String)(items.get(cPos1-2));
String cnemVal = (String)(items.get(cPos1+1));
items.remove(cPos1);
boolean chk;
MenuGui.resultArea.append(cnemPos1);
MenuGui.resultArea.append("\n");
MenuGui.resultArea.append(cnemPosn);
MenuGui.resultArea.append("\n");
MenuGui.resultArea.append(cnemVal);
MenuGui.resultArea.append("\n");
MenuGui.resultArea.append("\n");
if(cnemPos1=="int"){
boolean wat = checkDT(cnemPos1,cnemVal);
if(wat== true){
symDTypeNem.add(cnemPosn);
symDTypeL.add(cnemPos1);
symDTypeVal.add(cnemVal);
MenuGui.resultArea.append("correct");
MenuGui.resultArea.append("\n");
state1 = 5; //to be changed to state number going to next token.
}
else if(ifExbalpar(cnemVal)==true){
MenuGui.resultArea.append("balanced expression");
MenuGui.resultArea.append("\n");
state1 = 5;// to be changed
}
else if(ifExbalpar(cnemVal)==false){
MenuGui.resultArea.append("warning! error unbalanced expression");
MenuGui.resultArea.append("\n");
state1 = 5;// to be changed
}
else{
MenuGui.resultArea.append("incompatible data type, int expected");
MenuGui.resultArea.append("\n");
}
}
else{
MenuGui.resultArea.append("value of cnemPos1 is no int");
MenuGui.resultArea.append("\n");
}