Ybc
Jump to navigation
Jump to search
Programming Language YBC by Bobbyfisher101
NOTES:
This language is a simple language that uses a single memory-pointer register and an array of integers as variables (referenced as ram[index] ).
| Command | Command Explanation |
|---|---|
| Oh scrap, you're here today! | begin code execution here |
| Oh scrap! | stop code execution |
| What is ram, anyway? | prompt user to input ram[register] |
| What is string, anyway? | prompt user to input a string |
| No obense, but $String$ | println String |
| No obense... | println String from ram starting at ram[register] |
| No obense, but... | println ram[register] |
| What is register, anyway? | store the next line (a number) to the register |
| What is value, anyway? | store the next line (a number) to ram[register] |
| Bin! | register++ |
| Cho! | register-- |
| Scrap! | ram[3] = ram[1] + ram[2] |
| Scrap! Scrap! | ram[3] = ram[1] - ram[2] |
| Scrap! Scrap! Scrap! | ram[3] = ram[1] * ram[2] |
| Scrap! Scrap! Scrap! Scrap! | ram[3] = ram[1] / ram[2] |
| YoonBinCho! | Goto Yoon! with register number of O's |
| What is equal, anyway? | skip next line if ram[1] != ram[2] |
| What is greater, anyway? | skip next line if ram[1] < ram[2] |
| What is less, anyway? | skip next line if ram[1] > ram[2] |
| What is not equal, anyway? | skip next line if ram[1] == ram[2] |
| Oh! | ram[1] = ram[register] |
| Oh, hello! | ram[2] = ram[register] |
| Oh, hello there! | ram[register] = ram[3] |
SAMPLE PROGRAMS:
HELLOWORLD:
Oh scrap, you're here today! No obense, but $HELLO WORLD!$ Oh scrap!
CAT PROGRAM:
Oh scrap, you're here today! Yoon! What is register, anyway? 0 What is string, anyway? No obense... What is register, anyway? 2 YoonBinCho!
SIMPLE HIGH/LOW NUMBER GUESSING GAME (ANSWER IS 67)
Oh scrap, you're here today! What is register, anyway? 2 What is value, anyway? 67 Yoon! What is register, anyway? 1 No obense, but $ENTER GUESS:$ What is ram, anyway? What is register, anyway? 5 What is equal, anyway? YoonBinCho! What is register, anyway? 4 What is greater, anyway? YoonBinCho! What is register, anyway? 3 What is less, anyway? YoonBinCho! Yooon! No obense, but $TOO LOW!$ What is register, anyway? 2 YoonBinCho! Yoooon! No obense, but $TOO HIGH!$ What is register, anyway? 2 YoonBinCho! Yooooon! No obense, but $YOU WIN!$ Oh scrap!
Java interpreter:
import java.util.Scanner;
public class YoonCode {
public static int[] ram = new int[100];
public static int lineNumber = 0;
public static int registerM = 0;
public static boolean quit = false;
public static Scanner input = new Scanner(System.in);
public static String[] code = new String[100];
public static String errorMessage = "";
public static final boolean manual = true; //for entering in code through terminal
public static void main(String[] args){
setCode();
findStart();
while(!quit){
lineNumber++;
checkM();
execute();
if(lineNumber > 98){errorMessage = "NO_END_COMMAND"; error(); quit = true;}
}
}
public static void setCode() {
for (int i = 0; i < 100; i++) {code[i] = "";}
if(manual){ //for entering in code through terminal, after done: type XXX
int i = 0;
String enters = "NO";
while(!enters.equals("XXX")){
enters = input.nextLine();
if(!enters.equals("XXX")){code[i] = enters;}
i++;
}
System.out.println("\n\n\n\n\n");
return;
}
//TYPE CODE HERE
}
public static void checkM(){
if(registerM < 0 || registerM > ram.length){
errorMessage = "M_OUT_OF_BOUNDS: " + registerM;
error();
registerM = 0;
}
}
public static void findStart(){
lineNumber = findIndex("Oh scrap, you're here today!");
if (lineNumber == -1){errorMessage = "NO_START_DEFINED"; error(); quit = true;}
}
public static void execute(){
String s = code[lineNumber];
if(s.equals("Oh scrap!")){quit = true;}
if(s.equals("What is ram, anyway?")){ram[registerM] = input.nextInt();}
if(s.equals("What is string, anyway?")){
String enter = input.nextLine();
enter = enter.replaceAll("\\s+","");
for(int i = 0; i < enter.length(); i++){
ram[registerM + i] = (int)enter.charAt(i);
}
ram[registerM + enter.length()] = 0;
}
if(s.equals("No obense, but...")){System.out.println(ram[registerM]);}
if(s.equals("No obense...")){
for(int i = 0; ram[registerM + i] != 0; i++){
System.out.print((char)ram[registerM + i]);
}
System.out.println();
}
if(s.equals("What is register, anyway?")){
lineNumber++;
try{registerM = Integer.parseInt(code[lineNumber]);} catch(Exception e){}
}
if(s.equals("What is value, anyway?")){
lineNumber++;
try{ram[registerM] = Integer.parseInt(code[lineNumber]);} catch(Exception e){}
}
if(s.equals("Bin!")){registerM++;}
if(s.equals("Cho!")){registerM--;}
if(s.equals("Scrap!")){ram[3] = ram[1] + ram[2];}
if(s.equals("Scrap! Scrap!")){ram[3] = ram[1] - ram[2];}
if(s.equals("Scrap! Scrap! Scrap!")){ram[3] = ram[1] * ram[2];}
if(s.equals("Scrap! Scrap! Scrap! Scrap!")){
if(ram[2]!=0){
ram[3] = ram[1] / ram[2];}
if(ram[2] == 0){errorMessage = "DIVIDE_BY_ZERO!"; error();}
}
if(s.equals("YoonBinCho!")){
String find = "Y";
for(int i = 0 ; i < registerM; i++){
find = find + "o";
}
find = find + "n!";
lineNumber = findIndex(find);
if(lineNumber < 0){errorMessage = "NO_GOTO_LABEL";error();}
}
if(s.equals("What is equal, anyway?")){
if(ram[1] != ram[2]) {lineNumber++;}
}
if(s.equals("What is greater, anyway?")){
if(ram[1] < ram[2]) {lineNumber++;}
}
if(s.equals("What is less, anyway?")){
if(ram[1] > ram[2]) {lineNumber++;}
}
if(s.equals("What is not equal, anyway?")){
if(ram[1] == ram[2]) {lineNumber++;}
}
if(s.equals("Oh!")){ram[1] = ram[registerM];}
if(s.equals("Oh, hello!")){ram[2] = ram[registerM];}
if(s.equals("Oh, hello there!")){ram[registerM] = ram[3];}
if(s.contains("$")){
int i1 = s.indexOf("$");
s = s.substring(i1 + 1);
s = s.substring(0,s.length()-1);
System.out.println(s);
}
}
public static void error(){
System.out.println("\n*** No obense, but you suck at coding...***");
System.out.println("Line number: " + lineNumber);
System.out.println("Error: " + errorMessage);
System.out.println("*** No obense, but you suck at coding...***");
}
public static int findIndex(String target){
for(int i = 0; i < code.length; i++){
if(code[i].equals(target)){return i;}
}
return -1;
}
}