/**
* The Programming Language "CHINKO"
*
* Author: sira
* Date: 12/04/01
* Created with IntelliJ IDEA.
*/
import java.io.*;
class chnki {
private static final int MEM_MAX_SIZE = 32768;
public chnki
(String[] operationArray
){
char[] mem = new char[MEM_MAX_SIZE];
int ptr = 0;
for(int i = 0; i < operationArray.length; i++) {
// >
if (operationArray[i].equals("チン")) {
ptr++;
if (MEM_MAX_SIZE <= ptr) {
System.
out.
println("chnki: over flow"); }
// <
} else if (operationArray[i].equals("チィン")) {
ptr--;
if (ptr < 0) {
System.
out.
println("chnki: under flow"); }
// +
} else if (operationArray[i].equals("チチン")) {
mem[ptr]++;
// -
} else if (operationArray[i].equals("トゥィン")) {
mem[ptr]--;
// .
} else if (operationArray[i].equals("コッ")) {
// ,
} else if (operationArray[i].equals("♂")) {
try {
mem
[ptr
] = (char) System.
in.
read(); e.printStackTrace();
}
// [
} else if (operationArray[i].equals("ンンンッ")) {
if (mem[ptr] == 0) {
int nonPairCount = 0;
out:
for (++i; i < operationArray.length; i++) {
if (operationArray[i].equals("アアアッ")) {
if (nonPairCount == 0)
break out;
else
nonPairCount--;
} else if (operationArray[i].equals("ンンンッ")) {
nonPairCount++;
}
}
if (i == operationArray.length) {
System.
out.
println("chnki: 'アアアッ' not found"); }
i++;
}
// ]
} else if (operationArray[i].equals("アアアッ")) {
if (mem[ptr] != 0) {
int nonPairCount = 0;
out:
for (--i; 0 <= i; i--) {
if (operationArray[i].equals("ンンンッ")) {
if (nonPairCount == 0)
break out;
else
nonPairCount--;
} else if (operationArray[i].equals("アアアッ")) {
nonPairCount++;
}
}
if (i < 0) {
System.
out.
println("chnki: 'ンンンッ' not found"); }
i--;
}
}
}
}
try {
int cnt;
while ((cnt = bufferedReader.read()) != -1) {
stringBuffer.append((char)cnt);
}
return stringBuffer.toString();
} finally {
bufferedReader.close();
}
}
public static void main
(String args
[]) { if(args.length != 1) {
System.
out.
println("chnki: no input file"); }
try {
String[] operationArray
= code.
split("!!");
if(operationArray.length > MEM_MAX_SIZE) {
System.
out.
println("chnki: memory over"); }
new chnki(operationArray);
}
}
}