i'm trying to build a simple program in java to check whether a real number is correctly written. following the schema that i displayed. now, the following code checks whether the state that i find myself into(from the beginning it should be q0 with a symbol) is in my list of transitions with that specific symbol.
Tranzitie findTransition(String state, char symbol){
for (int i=0; i<this.list.size(); i++){
Tranzitie tmp = this.list.get(i);
if (tmp.getSt_first().equals(state) && tmp.getSimbol()==simbol)
return tmp;
}
return null;
}
the following boolean method returns whether the string parameter "sir" is accepted by my dfa. (the string is supposed to be a real number)
boolean analyzeWord(String sir){
Tranzitie tmp = null;
for (int i = 0; i < sir.length(); i++) {
if (i == 0) {
tmp = lista.findTransition(st_initial, sir.charAt(i));
System.out.println(tmp.getSt_first() + "\t" + tmp.getSimbol() + "\t" +tmp.getSt_end());
if (tmp == null)
return false;
} else {
tmp = lista.findTransition(tmp.getSt_end(), sir.charAt(i));
System.out.println(tmp.getSt_first() + "\t" + tmp.getSimbol() + "\t" +tmp.getSt_end());
if (tmp == null)
return false;
}
}
for (String st_final : st_finale)
if (tmp.getSt_end().equals(st_final))
return true;
return false;
}
i'm reading the transitions from the file such as
q0' 0 q5
q0' 0 q2