ABC
Jump to navigation
Jump to search
- Not to be confused with tom7's ABC (compiler), AlPhAbEt, nor Abc.
ABC is an esoteric programming language created by User:Orange. The language is very simple and easy to implement. This language has nothing to do with the real programming language ABC.
Instructions
a - Increment the accumulator b - Decrement the accumulator c - Output the accumulator d - Invert accumulator r - Set accumulator to a random number between 0 and accumulator n - Set accumulator to 0 $ - Toggle ASCII output mode. When on, the c instruction prints the accumulator as an ASCII character. l - Loop back to the beginning of the program. Accumulator and ASCII mode does not reset. ; - Debug. Prints out accumulator as a number and ascii character.
Unknown instructions are treated as NOPs.
Examples
Print out 1337
acaaccaaaac
Simulate a dice throw
aaaaarac
Random phone number generator
ac naaaaaaaaradc naaaaaaaaarc naaaaaaaaarc naaaaaaaaradc naaaaaaaaarc naaaaaaaaarc naaaaaaaaradc naaaaaaaaarc naaaaaaaaarc naaaaaaaaarc
Hello World
$aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacaaaaaa aaaaaaaaaaaaaaaaaaaaaaacaaaaaaaccaaacnaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aacbbbbbbbbbbbbcaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacaaaaaaaa aaaaaaaaaaaaaaaacaaacbbbbbbcbbbbbbbbcnaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac
Count infinitely
acl
Beep infinitely using ASCII code 7 (bell)
aaaaaaa$cn$l
Resources
Interpreters
Java
public class ABC{ public static void interpreter(String code){ int acc=0; boolean stringMode=false; for(int i=0;i<code.length();i++){ switch(code.charAt(i)){ case'a':++acc;break; case'b':--acc;break; case'c':if(stringMode)System.out.print((char)acc); else System.out.print(acc); break; case'd':acc*=-1;break; case'r':acc=(int)Math.floor(Math.random()*(acc+1));break; case'n':acc=0;break; case'$':stringMode=(stringMode==false)?true:false;break; case'l':i=-1;break; case';':System.out.print(acc+" "+(char)acc); } } } }
Python
import sys import random prog = """ aaaaarac """ acc = 0 pc = 0 ascii_mode = False while True: if prog[pc] == 'a': acc += 1 elif prog[pc] == 'b': acc -= 1 elif prog[pc] == 'c': if ascii_mode: sys.stdout.write(chr(acc)) else: sys.stdout.write(str(acc) + ' ') elif prog[pc] == 'd': acc *= -1 elif prog[pc] == 'r': acc = random.randrange(0, acc) elif prog[pc] == 'n': acc = 0 elif prog[pc] == '$': ascii_mode = not ascii_mode elif prog[pc] == 'l': pc = 0 elif prog[pc] == ';': print(acc, chr(acc)) pc += 1 if pc == len(prog): sys.stdout.write('\n') break