Abc!?
Abc!? is a simple, procedural, unstructured (esoteric) programming language that I made up.
Program syntax
A program file consists of a data section and then a code section. All text in the program file is data by default. The code section does not start until a line with only "Abc!?" written on it appears. So, a file consists of an optional data section, followed by the line "Abc!?", and then an optional code section. An example:
Sample text in the data section. Abc!? 1 line of code; 0>!
Each line in the program section begins with a comment/label, then a semicolon, then optional whitespace, and finally a statement/operation. This forces every single line of code to be documented (or you could take the lazy path and just label each line with a number like in BASIC).
Text in the data section also processes escape codes. An escape code is a backslash followed by a the ASCII number for the character you want.
There are 3 kinds of number literals in the code section: decimal, hexadecimal, and un-escaped characters. Decimal numbers are just written out normally with the digits 0-9, and hexadecimal numbers are prefixed with the dollar sign. An "un-escaped character" is a character literal, which is any character preceded by a backslash (like \H in the hello world example).
Variables
Every variable named with a lower case letter holds 1 byte and every variable named with an upper case letter holds 8 bytes. All values (variables and literals) are treated as signed integers within arithmetic operations. All values are converted to characters for input and output.
The only variables that are available are the 26 upper and lower case letters of the alphabet. Case matter, so A ≠ a. There are also two special variables: "?" and "!", which only hold 1 byte each. The question mark can only be from, and when it is, it reads a character of program input. The exclamation mark variable can be written to, and when it is, it writes a character of program output. These two special variables, "?" and "!" can also be used in all operations as parameters. The value of "?" is fetched only once, even if it is used multiple times on one line. For example, the following line of code will read "?" once and move the value into "a" unless the value is 0.
1; [?#0]?>a
Memory
Memory addresses are integer literals within the source code. The addresses start at zero, and address zero points to the beginning of the data section. Note that memory addresses do not fit within a variable
Operators
Binary operators
- add:
+
- subtract:
-
- multiply:
*
- divide:
/
- bitwise and:
&
- bitwise or:
|
Conditional operators
- equal:
=
- not equal:
#
- less than:
<
- more than:
>
Unary operators
- bitwise complement:
~
- address dereference:
*
Statements
A statement must be on one line. It begins with a comment, then a semicolon, and then the statement's code. There are 2 kinds of statements: move and jump.
Move
A move statement moves a value into a variable or a memory address. A move can contain a calculation on the left hand side. The syntax for a move is the left hand side followed by a greater-than sign followed by a destination. If the destination is a variable, then you may repeat the greater-than-sign to signify that the address referred to by the variable is meant to be written to rather than the variable itself.
Examples of "move" lines
Example 1; a+b>c
Example 2; a+b>>c
Example 3; ~a>b
Example 4; ~a>>b
Example 5; a>b
Example 6; a>>b
Jump
A jump statement jumps to the line with the given label. A jump statement begins with a colon and the rest of the line is devoted to specifying the label of the line to jump to. The line the jump statement jumps to is the first line that appears in the code that has all of the same first characters as the label. Note that letter case does matter for labels, but the labels do not have to match the full text.
Examples of "jump" lines
Infinite loop; :Inf
Jump to line starting with abc; :abc
Conditional statements
Any statement which is not already conditional may be made conditional by preceding the code part with a condition.
A condition is a binary comparison enclosed in square brackets.
The valid comparison operators are: =
, #
, >
, and >
.
The operator #
means "not equal".
Examples of conditional statements
Set b to a unless a=1; [a#1]a>b
Most complicated statement possible; [a=b]c+d>>e
.
Special features
It is not completely true that you can only read values from question mark and write values to exclamation mark. Writing to question mark will exit the program with an exit code given by the written value. And reading from exclamation mark will return a random value.
Example Programs
Hello world (long and straightforward)
Abc!? H; \H>! e; \e>! l; \l>! l; \l>! o; \o>! ,; \,>! space; \ >! w; \w>! o; \o>! r; \r>! l; \l>! d; \d>! !; \!>! newline; 10>! exit; 0>?
Hello world (shorter)
This program prints out its data section until it reaches a sentinel value, which is the null character (0) in this case.
Hello, world!\0 Abc!? Start; 0>i Get data; *i>x Check end; [x=0]:Done Increment; i+1>i Print char; x>! Loop back; :Get data Done; 0>?
Cat
Abc!? I/O; ?>! Rep; :I/O
Truth-machine
Abc!? Get; ?>x Check; [x=\0]:False True; \1>! Loop; :True False; \0>! Exit; 0>?