final parser and adding of iterations number
This commit is contained in:
parent
049e3aeda7
commit
cab689070c
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,6 @@
|
||||
.idea/
|
||||
out/
|
||||
/bin/
|
||||
.project
|
||||
.classpath
|
||||
.bin
|
@ -22,6 +22,8 @@ public class Main {
|
||||
rules.add(scanner.next());
|
||||
}
|
||||
rules.remove(rules.size() - 1);
|
||||
System.out.println("Nombre d'itérations: ");
|
||||
nbIterations = scanner.nextInt();
|
||||
parser = new Parser(axiom, rules,nbIterations);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ public class Parser {
|
||||
private final String axiom;
|
||||
private final List<String> rules;
|
||||
private final int nbIterations;
|
||||
private String[] validStrings = {"]","[",".","+","-","X","Y","Z","x","y","z","0","1","2","3","4","5","6","7","8","9"};
|
||||
private char[] validChars = {'=',']','[','.','+','-','X','Y','Z','x','y','z','0','1','2','3','4','5','6','7','8','9',' '};
|
||||
|
||||
public Parser(String axiom, List<String> rules,int nbIterations) {
|
||||
this.axiom = axiom;
|
||||
@ -16,40 +16,43 @@ public class Parser {
|
||||
}
|
||||
|
||||
public boolean isCorrect(){
|
||||
return (rulesCorrect() || axiomCorrect());
|
||||
}
|
||||
private boolean axiomCorrect() {
|
||||
|
||||
if (nbIterations == 0) {
|
||||
System.out.println("Erreur, nombre d'itérations inssufissant (plus petit que 1)");
|
||||
return false;
|
||||
}
|
||||
boolean bl = isCorrect(axiom);
|
||||
for(String rule : this.rules){
|
||||
bl = bl && isCorrect(rule);
|
||||
}
|
||||
return bl;
|
||||
}
|
||||
private boolean isCorrect(String stringToCheck) {
|
||||
|
||||
public boolean rulesCorrect() {
|
||||
for(String r : this.rules) {
|
||||
String[] stringsplitted = r.split("");
|
||||
String old = null;
|
||||
char old = ' ';
|
||||
int bracket = 0;
|
||||
for (String rules : stringsplitted){
|
||||
for(String string : validStrings){
|
||||
if (rules == "[")
|
||||
for (int i =0; i>stringToCheck.length();i++){
|
||||
char temp = stringToCheck.charAt(i);
|
||||
for(char validChar : validChars){
|
||||
if (temp == '[')
|
||||
bracket += 1;
|
||||
if(rules =="]")
|
||||
if(temp ==']')
|
||||
bracket -=1;
|
||||
if(old == "."){
|
||||
for(int i = 0;i<10;i++){
|
||||
if(rules == validStrings[i])
|
||||
if(old == '.'){
|
||||
for(int y = 0;y<12;y++){
|
||||
if(temp == validChars[y])
|
||||
return false;
|
||||
}
|
||||
}
|
||||
old = rules;
|
||||
if(rules == string)
|
||||
old = temp;
|
||||
if(temp == validChar)
|
||||
break;
|
||||
if(string == "9" && rules != string)
|
||||
if(validChar == ' ' && temp != validChar)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (bracket != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user