Moved Parser and refactored isCorrect method in Parser

This commit is contained in:
Quentin Legot 2021-02-05 19:28:55 +01:00
parent cab689070c
commit ba570154e4
4 changed files with 21 additions and 24 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ out/
.project
.classpath
.bin
.settings/

View File

@ -1,6 +1,6 @@
package lsystem;
import lsystem.engine.parser.Parser;
import lsystem.engine.Parser;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
@ -26,7 +26,6 @@ public class Main {
nbIterations = scanner.nextInt();
parser = new Parser(axiom, rules,nbIterations);
}
scanner.close();
}

View File

@ -1,4 +1,4 @@
package lsystem.engine.parser;
package lsystem.engine;
import java.util.List;
@ -16,8 +16,8 @@ public class Parser {
}
public boolean isCorrect(){
if (nbIterations == 0) {
System.out.println("Erreur, nombre d'itérations inssufissant (plus petit que 1)");
if (nbIterations < 1) {
System.out.println("Erreur, nombre d'itérations insuffisant (plus petit que 1)");
return false;
}
boolean bl = isCorrect(axiom);
@ -26,17 +26,16 @@ public class Parser {
}
return bl;
}
private boolean isCorrect(String stringToCheck) {
private boolean isCorrect(String stringToCheck) {
char old = ' ';
int bracket = 0;
for (int i = 0; i > stringToCheck.length(); i++){
char temp = stringToCheck.charAt(i);
for(char validChar : validChars){
if (temp == '[')
bracket += 1;
bracket++;
if(temp ==']')
bracket -=1;
bracket--;
if(old == '.'){
for(int y = 0; y < 12; y++){
if(temp == validChars[y])
@ -44,15 +43,14 @@ public class Parser {
}
}
old = temp;
for(char validChar : validChars){
if(temp == validChar)
break;
if(validChar == ' ' && temp != validChar)
if(validChar == ' ')
return false;
}
}
if (bracket != 0)
return false;
return true;
return bracket == 0;
}
}

View File

@ -2,7 +2,6 @@ package lsystem.engine;
import lsystem.utils.Pair;
import java.util.HashMap;
import java.util.List;
public class Rewrite {