final parser and adding of iterations number

This commit is contained in:
Arthur 2021-02-03 10:05:31 +01:00
parent 049e3aeda7
commit cab689070c
3 changed files with 45 additions and 36 deletions

4
.gitignore vendored
View File

@ -1,2 +1,6 @@
.idea/ .idea/
out/ out/
/bin/
.project
.classpath
.bin

View File

@ -22,6 +22,8 @@ public class Main {
rules.add(scanner.next()); rules.add(scanner.next());
} }
rules.remove(rules.size() - 1); rules.remove(rules.size() - 1);
System.out.println("Nombre d'itérations: ");
nbIterations = scanner.nextInt();
parser = new Parser(axiom, rules,nbIterations); parser = new Parser(axiom, rules,nbIterations);
} }

View File

@ -7,7 +7,7 @@ public class Parser {
private final String axiom; private final String axiom;
private final List<String> rules; private final List<String> rules;
private final int nbIterations; 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) { public Parser(String axiom, List<String> rules,int nbIterations) {
this.axiom = axiom; this.axiom = axiom;
@ -16,40 +16,43 @@ public class Parser {
} }
public boolean isCorrect(){ public boolean isCorrect(){
return (rulesCorrect() || axiomCorrect()); if (nbIterations == 0) {
} System.out.println("Erreur, nombre d'itérations inssufissant (plus petit que 1)");
private boolean axiomCorrect() {
return false; 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() { char old = ' ';
for(String r : this.rules) {
String[] stringsplitted = r.split("");
String old = null;
int bracket = 0; int bracket = 0;
for (String rules : stringsplitted){ for (int i =0; i>stringToCheck.length();i++){
for(String string : validStrings){ char temp = stringToCheck.charAt(i);
if (rules == "[") for(char validChar : validChars){
if (temp == '[')
bracket += 1; bracket += 1;
if(rules =="]") if(temp ==']')
bracket -=1; bracket -=1;
if(old == "."){ if(old == '.'){
for(int i = 0;i<10;i++){ for(int y = 0;y<12;y++){
if(rules == validStrings[i]) if(temp == validChars[y])
return false; return false;
} }
} }
old = rules; old = temp;
if(rules == string) if(temp == validChar)
break; break;
if(string == "9" && rules != string) if(validChar == ' ' && temp != validChar)
return false; return false;
} }
} }
if (bracket != 0) if (bracket != 0)
return false; return false;
}
return true; return true;
} }
} }