I am making a parser for a language I call "Dint" in Java, and I added a statement for debugging: System.out.println("tok's val: "+tok);
and it has the same value as the parser, but won't print "Found a print", why?
I have tried moving statements between lines, I have tried to look up the issue, and as a last resort I added that debugging statement, but I am confused as to why it won't work.
public class Dint {
public static void main(String[] args) {
System.out.println("Welcome Dint ISE v0.0.1! use \"help\" for help!\n");
Scanner Input = new Scanner(System.in);
String In = Input.nextLine();
boolean Program = true;
while(Program) {
String tok = "";
String string = "";
int state = 0;
String[] strings = new String[100];
for(int i = 0; i < In.length();) {
tok += In.charAt(i);
if(tok == " ") {
tok = "";
} else if(tok == "\"") {
tok = "";
} else if(tok == "out") {
System.out.println("Found a print");
tok = "";
}
i++;
}
System.out.println("tok's value: "+tok);
In = Input.nextLine();
}
}
}
I get
out
tok's val: out
When I expected to get:
out
Found a print
tok's val: out