Skip to content

Commit

Permalink
Rule 생성자에 아웃풋 파일 경로 받게 수정, Main을 명령어 입력 실행 방법으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
occidere committed Jan 15, 2018
1 parent 792807b commit aa9d11f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
26 changes: 18 additions & 8 deletions src/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,29 @@

public class Main {
public static void main(String[] args) throws Exception {

if(args.length !=2) {
System.err.println("Usage: <Input> <Output>");
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", "");

Expand All @@ -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);
}
}
8 changes: 5 additions & 3 deletions src/rule/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

public class Rule {
private volatile HashSet<String> 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 {
Expand All @@ -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;
Expand All @@ -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);
}
}

0 comments on commit aa9d11f

Please # to comment.