added first parser implementation

This commit is contained in:
Quentin Legot 2021-02-02 16:07:08 +01:00
parent 0d8d0a68f2
commit 2216561506
3 changed files with 39 additions and 7 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
.idea/
.idea/
out/

View File

@ -1,5 +1,7 @@
package lsystem;
import lsystem.engine.parser.Parser;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
@ -8,13 +10,22 @@ public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Axiom: ");
String axiom = scanner.next();
System.out.println("Règles (laissez vide quand vous avez fini): ");
List<String> rules = new ArrayList<>();
while(rules.isEmpty() || !rules.get(rules.size() - 1).equals("")) {
rules.add(scanner.next());
Parser parser = null;
while(parser == null || parser.isCorrect()) {
if(parser != null)
System.out.println("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
System.out.println("Axiome: ");
String axiom = scanner.next();
System.out.println("Règles: (\"finish\" quand vous avez fini): ");
List<String> rules = new ArrayList<>();
while(rules.isEmpty() || !rules.get(rules.size() - 1).equals("finish")) {
rules.add(scanner.next());
}
rules.remove(rules.size() - 1);
parser = new Parser(axiom, rules);
}
scanner.close();
}
}

View File

@ -0,0 +1,20 @@
package lsystem.engine.parser;
import java.util.List;
public class Parser {
private final String axiom;
private final List<String> rules;
public Parser(String axiom, List<String> rules) {
this.axiom = axiom;
this.rules = rules;
}
public boolean isCorrect(){
return false;
}
}