Last active
April 20, 2017 05:17
Star
You must be signed in to star a gist
DADAscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.nio.charset.StandardCharsets; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.util.ArrayList; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
import java.util.stream.Collectors; | |
public class DaDaScript { | |
public static String pointerInc = "ヤサイ"; | |
public static String pointerDec = "アブラ"; | |
public static String memoryInc = "マシ"; | |
public static String memoryDec = "少なめ"; | |
public static String out = "ごちそうさまです"; | |
public static String in = "ニンニク入れますか?"; | |
public static String startRep = "ニンニク"; | |
public static String endRep = "カラメ"; | |
public static void main(String[] args) throws IOException { | |
ArrayList<String> tokens = new ArrayList<>(); | |
String filestr = Files.lines(Paths.get(args[0]), StandardCharsets.UTF_8) | |
.collect(Collectors.joining(System.getProperty("line.separator"))); | |
Pattern pattern = Pattern.compile( | |
pointerInc + "|" + pointerDec + "|" + memoryInc + "|" + memoryDec + "|" + | |
out + "|" + in + "|" + startRep + "|" + endRep | |
); | |
Matcher matcher = pattern.matcher(filestr); | |
while (matcher.find()) tokens.add(matcher.group()); | |
char[] memory = new char[30000]; | |
int operatorPointer = 0; | |
int pointer = 0; | |
int loop = 0; | |
while (operatorPointer < tokens.size()){ | |
if (tokens.get(operatorPointer).equals(pointerInc)) pointer++; | |
else if (tokens.get(operatorPointer).equals(pointerDec)) pointer--; | |
else if (tokens.get(operatorPointer).equals(memoryInc)) memory[pointer]++; | |
else if (tokens.get(operatorPointer).equals(memoryDec)) memory[pointer]--; | |
else if (tokens.get(operatorPointer).equals(out)) System.out.print(memory[pointer]); | |
else if (tokens.get(operatorPointer).equals(in)) memory[pointer] = (char) System.in.read(); | |
else if (tokens.get(operatorPointer).equals(startRep)) { | |
if (memory[pointer] == 0) { | |
operatorPointer++; | |
while (loop > 0 || !tokens.get(operatorPointer).equals(endRep)) { | |
if (tokens.get(operatorPointer).equals(startRep)) loop++; | |
if (tokens.get(operatorPointer).equals(endRep)) loop--; | |
operatorPointer++; | |
} | |
} | |
}else if (tokens.get(operatorPointer).equals(endRep)) { | |
if (memory[pointer] != 0) { | |
operatorPointer--; | |
while (loop > 0 || !tokens.get(operatorPointer).equals(startRep)) { | |
if (tokens.get(operatorPointer).equals(endRep)) loop++; | |
if (tokens.get(operatorPointer).equals(startRep)) loop--; | |
operatorPointer--; | |
} | |
operatorPointer--; | |
} | |
} | |
operatorPointer++; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
マシマシマシマシマシマシマシマシマシニンニクヤサイマシマシマシマシマシマシマシマシヤサイマシマシマシマシマシマシマシマシマシマシマシヤサイマシマシマシマシマシアブラアブラアブラ少なめカラメヤサイごちそうさまですヤサイマシマシごちそうさまですマシマシマシマシマシマシマシごちそうさまですごちそうさまですマシ | |
マシマシごちそうさまですヤサイ少なめごちそうさまです少なめ少なめ少なめ少なめ少なめ少なめ少なめ少なめ少なめ少なめ少なめ少なめごちそうさまですアブラマシマシマシマシマシマシマシマシごちそうさまです少なめ少なめ少なめ少なめ少なめ少なめ少なめ少なめごちそうさまですマシマシマシごちそうさまです少なめ少なめ少なめ少なめ少なめ少なめごちそうさまです少なめ少なめ少なめ少なめ少なめ少なめ少なめ少なめごちそうさまですヤサイマシごちそうさまです |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment