fork download
  1. /**
  2.  * The Programming Language "CHINKO"
  3.  *
  4.  * Author: sira
  5.  * Date: 12/04/01
  6.  * Created with IntelliJ IDEA.
  7.  */
  8.  
  9. import java.io.*;
  10.  
  11. class chnki {
  12.  
  13. private static final int MEM_MAX_SIZE = 32768;
  14.  
  15. public chnki(String[] operationArray){
  16.  
  17. char[] mem = new char[MEM_MAX_SIZE];
  18. int ptr = 0;
  19.  
  20. for(int i = 0; i < operationArray.length; i++) {
  21.  
  22. // >
  23. if (operationArray[i].equals("チン")) {
  24. ptr++;
  25. if (MEM_MAX_SIZE <= ptr) {
  26. System.out.println("chnki: over flow");
  27. System.exit(0);
  28. }
  29.  
  30. // <
  31. } else if (operationArray[i].equals("チィン")) {
  32. ptr--;
  33. if (ptr < 0) {
  34. System.out.println("chnki: under flow");
  35. System.exit(0);
  36. }
  37.  
  38. // +
  39. } else if (operationArray[i].equals("チチン")) {
  40. mem[ptr]++;
  41.  
  42. // -
  43. } else if (operationArray[i].equals("トゥィン")) {
  44. mem[ptr]--;
  45.  
  46. // .
  47. } else if (operationArray[i].equals("コッ")) {
  48. System.out.print(mem[ptr]);
  49.  
  50. // ,
  51. } else if (operationArray[i].equals("♂")) {
  52. try {
  53. mem[ptr] = (char) System.in.read();
  54. } catch (IOException e) {
  55. e.printStackTrace();
  56. }
  57.  
  58. // [
  59. } else if (operationArray[i].equals("ンンンッ")) {
  60. if (mem[ptr] == 0) {
  61. int nonPairCount = 0;
  62. out:
  63. for (++i; i < operationArray.length; i++) {
  64. if (operationArray[i].equals("アアアッ")) {
  65. if (nonPairCount == 0)
  66. break out;
  67. else
  68. nonPairCount--;
  69.  
  70. } else if (operationArray[i].equals("ンンンッ")) {
  71. nonPairCount++;
  72.  
  73. }
  74. }
  75. if (i == operationArray.length) {
  76. System.out.println("chnki: 'アアアッ' not found");
  77. System.exit(0);
  78. }
  79. i++;
  80. }
  81.  
  82. // ]
  83. } else if (operationArray[i].equals("アアアッ")) {
  84. if (mem[ptr] != 0) {
  85. int nonPairCount = 0;
  86. out:
  87. for (--i; 0 <= i; i--) {
  88. if (operationArray[i].equals("ンンンッ")) {
  89. if (nonPairCount == 0)
  90. break out;
  91. else
  92. nonPairCount--;
  93.  
  94. } else if (operationArray[i].equals("アアアッ")) {
  95. nonPairCount++;
  96.  
  97. }
  98. }
  99. if (i < 0) {
  100. System.out.println("chnki: 'ンンンッ' not found");
  101. System.exit(0);
  102. }
  103. i--;
  104. }
  105.  
  106. }
  107. }
  108. }
  109.  
  110. public static String fileToString(File file) throws IOException {
  111.  
  112. BufferedReader bufferedReader = null;
  113.  
  114. try {
  115. bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
  116. StringBuffer stringBuffer = new StringBuffer();
  117. int cnt;
  118. while ((cnt = bufferedReader.read()) != -1) {
  119. stringBuffer.append((char)cnt);
  120. }
  121. return stringBuffer.toString();
  122. } finally {
  123. bufferedReader.close();
  124. }
  125. }
  126.  
  127. public static void main(String args[]) {
  128. if(args.length != 1) {
  129. System.out.println("chnki: no input file");
  130. }
  131. try {
  132. String code = fileToString(new File(args[0]));
  133. String[] operationArray = code.split("!!");
  134.  
  135. if(operationArray.length > MEM_MAX_SIZE) {
  136. System.out.println("chnki: memory over");
  137. System.exit(1);
  138. }
  139.  
  140. new chnki(operationArray);
  141.  
  142. } catch (IOException e) {
  143. System.err.println(e);
  144. System.exit(1);
  145. }
  146.  
  147. }
  148.  
  149. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty