From 2216561506fdabbbc78c23624944eeddc07db954 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 2 Feb 2021 16:07:08 +0100 Subject: [PATCH] added first parser implementation --- .gitignore | 3 ++- src/lsystem/Main.java | 23 +++++++++++++++++------ src/lsystem/engine/parser/Parser.java | 20 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 src/lsystem/engine/parser/Parser.java diff --git a/.gitignore b/.gitignore index 62c8935..562b66d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea/ \ No newline at end of file +.idea/ +out/ \ No newline at end of file diff --git a/src/lsystem/Main.java b/src/lsystem/Main.java index 9130184..fe0083a 100644 --- a/src/lsystem/Main.java +++ b/src/lsystem/Main.java @@ -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 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 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(); } } diff --git a/src/lsystem/engine/parser/Parser.java b/src/lsystem/engine/parser/Parser.java new file mode 100644 index 0000000..b7b4401 --- /dev/null +++ b/src/lsystem/engine/parser/Parser.java @@ -0,0 +1,20 @@ +package lsystem.engine.parser; + +import java.util.List; + +public class Parser { + + private final String axiom; + private final List rules; + + public Parser(String axiom, List rules) { + this.axiom = axiom; + this.rules = rules; + } + + public boolean isCorrect(){ + + return false; + } + +}