From aa9d11f1030c34e927b353889167af9178c17ec2 Mon Sep 17 00:00:00 2001 From: "S.J. Lee" Date: Mon, 15 Jan 2018 23:01:42 +0900 Subject: [PATCH] =?UTF-8?q?Rule=20=EC=83=9D=EC=84=B1=EC=9E=90=EC=97=90=20?= =?UTF-8?q?=EC=95=84=EC=9B=83=ED=92=8B=20=ED=8C=8C=EC=9D=BC=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=9B=EA=B2=8C=20=EC=88=98=EC=A0=95,=20Main?= =?UTF-8?q?=EC=9D=84=20=EB=AA=85=EB=A0=B9=EC=96=B4=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=20=EB=B0=A9=EB=B2=95=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/Main.java | 26 ++++++++++++++++++-------- src/rule/Rule.java | 8 +++++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/Main.java b/src/main/Main.java index 53f7592..fc846b2 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -8,19 +8,29 @@ public class Main { public static void main(String[] args) throws Exception { + + if(args.length !=2) { + System.err.println("Usage: "); + System.err.println("ex) pseudo_dir/pseudo.txt output_dir/converted.java"); + System.exit(2); + } - String rawPath = "./Pseudo/pseudo.txt"; + String rawPath = args[0]; String rawCodes[] = Loader.load(rawPath).split("\n"); + + String converted = args[1]; + int pos = Math.max(converted.lastIndexOf("/"), converted.lastIndexOf("\\")); + if(pos >= 0) { + new File(converted.substring(0, pos)).mkdirs(); + new File(converted).delete(); + } - String convertedPath = "./Converted/converted.java"; - new File(convertedPath).delete(); - - Rule rule = new Rule(); + Rule rule = new Rule(converted); System.out.println("[ Pseudo 코드] "); Arrays.stream(rawCodes).forEach(System.out::println); - System.out.print("\n<< 변환 시작 ... "); + System.out.print("\n변환 시작 ... "); for(String pseudoLine : rawCodes) { pseudoLine = pseudoLine.replaceAll(" |\\t", ""); @@ -31,10 +41,10 @@ public static void main(String[] args) throws Exception { } if(matched == false) rule.forceMatch(pseudoLine+"\n"); } - System.out.println("완료 >>\n"); + System.out.println("완료\n"); System.out.println("[ Java 코드 ]"); - String converteds[] = Loader.load(convertedPath).split("\n"); + String converteds[] = Loader.load(converted).split("\n"); Arrays.stream(converteds).forEach(System.out::println); } } diff --git a/src/rule/Rule.java b/src/rule/Rule.java index 81bb67d..143e270 100644 --- a/src/rule/Rule.java +++ b/src/rule/Rule.java @@ -8,10 +8,12 @@ public class Rule { private volatile HashSet typeTable = new HashSet<>(); + private String savePath; - public Rule() { + public Rule(String savePath) { typeTable.add("for"); typeTable.add("print"); + this.savePath = savePath; } public boolean match(String code, String codeLine) throws ClassNotFoundException, InstantiationException, IllegalAccessException { @@ -21,7 +23,7 @@ public boolean match(String code, String codeLine) throws ClassNotFoundException Type type = new Dao().getType(code); String converted = type.convert(codeLine); - Saver.save("./Converted/converted.java", converted); + Saver.save(savePath, converted); } catch (Exception e) { e.printStackTrace(); return false; @@ -30,6 +32,6 @@ public boolean match(String code, String codeLine) throws ClassNotFoundException } public void forceMatch(String codeLine) throws Exception { - Saver.save("./Converted/converted.java", codeLine); + Saver.save(savePath, codeLine); } } \ No newline at end of file