A:;

From Esolang
Jump to navigation Jump to search

A:; is an esoteric programming language created by User:OriginalOldMan. Each A:; program has a series of statements separated by semicolons. Each A:; statement has a series of arguments separated by colons. All A:; programs must be written on one line.

Syntax

Variables

Only 12 variables can be used in A:;. They are:

b,c,j,l,o,q,r,t,u,v,w and x

Variables in A:; can contain strings or numbers. A variable can be set by entering its name as the first argument of a statement, and the value you want to set it to as the second argument. Variables cannot be set equal to other variables. The following example sets the variable j equal to "Hello World":

j:Hello World 

Variables set to number values should be in decimal form (i.e. integers have a trailing zero):

j:1.0

Commands

When using a command in A:; the command is entered as the first argument in the statement. (The commands below are also the reason we have only 12 variables)

Command Description Example
p The p command is used to print variable values to the standard output.

It can only print the values of variables.

j:Hello World\n;p:j (Prints "Hello World")
a The a command is used to add two numbers together

The value of the variable in the second argument is added to the value of the variable in the first argument.

j:1.0;l:2.0;a:j:l (Adds the value of l to j so that j is equal to 3.0)
s The s command is the same as the a command except that it subtracts. j:1.0;l:2.0;s:j:l (Subtracts the value of l from j so that j is equal to -1.0)
m The m command is the same as the s and a commands except that it multiplies instead. j:2.0;l:3.0;m:j:l (Multiplies j by the value of l so that j is equal to 6.0)
d The d command is the same as the m command except that it divides. j:4.0;l:2.0;d:j:l (Divides j by the value of l so that j is equal to 2.0)
g The g command is used to go to a certain statement.

The only argument in this command specifies the number of the statement to go to. (Note that the first statement in a program is statement 0)

j:Hello World\n;p:j;g:1 (Infinitely prints "Hello World")
i The i command is used to get input in the form of a string from the user.

The only argument in this command is the name of the variable that the input will be stored in.

i:j;p:j;g:0 (An example of a cat program)
n Similar to the i, the n command is used to get input in the form of a number. n:j;n:l;a:j:l;p:j (Adds together two numbers inputted by the user, and prints the sum)
? The ? command is used as an if statement.

The first and third arguments determine the variables to be compared. The second argument determines the way in which the variables should be compared (=,<,or >). The fourth argument determines how many of the following statements are part of the if statement's block. If statements can only compare variables.

n:j;l:2.0;b:The input was greater than 2;?:j:>:l:1;p:b (Prints "The input was greater than 2" if the user input was greater than 2)
k Ends the program

Example programs

Hello World

j:Hello World\n;p:j;k

Cat program

i:j;p:j;g:0

FizzBuzz

b:1;c:1;j:1;l:100;o:0;q:3;r:5;t:1;u:Fizz;v:Buzz;w:\n;s:c:q;?:c:=:0:3;p:Fizz;t:0;g:20;?:c:<:0:1;g:20;g:12;c:b;s:c:r;?:c:=:0:3;p:Buzz;t:0;g:29;?:c:<:0:1;g:29;g:21;?:t:=:1:1;p:b;?:b:=:100:1;k;p:w;a:b:j;g:0;

Deadfish interpreter

v:-1.0;w:256.0;u:\n;t:1;r:0;j:i;l:d;b:s;o:o;c:>>;p:c;?:r:=:v:1;r:0;?:r:=:w:1;r:0;i:q;?:q:=:o:3;p:r;p:u;g:10;?:q:=:j:2;a:r:t;g:10;?:q:=:l:2;s:r:t;g:10;?:q:=:b:2;m:r:r;g:10;p:u;g:10

Truth-machine

b:0;c:1;i:j;?:j:=:b:2;p:j;k;?:j:=:c:2;p:j;g:7

99 bottles of beer:

b:99;c:1;j: bottles of beer on the wall, \n;o: bottles of beer. \nTake one down, pass it around,\n;l:No bottles of beer on the wall!;p:b;p:j;p:b;p:o;s:b:c;?:b:<:c:1;g:13;g:5;p:l;k

Interpreter in Ruby

A quickly written interpreter for A:; written in Ruby.

print Dir.pwd
print ">>"
file = File.open(gets.delete("\n"), "rb")
program = file.read
file.close
program = program.gsub("\\n","\n")
$stmts = program.split(';')
$stmc = 0
$vars = [0,0,0,0,0,0,0,0,0,0,0,0]
def getAdress(char)
   case char
       when 'j'
       return 0
       when 'l'
       return 1
       when 'b'
       return 2
       when 'o'
       return 3
       when 'c' 
       return 4
       when 'q'
       return 5
       when 'r'
       return 6
       when 't'
       return 7
       when 'u'
       return 8
       when 'v'
       return 9
       when 'w'
       return 10
       when 'x'
       return 11
       end
   end
def run(stmt)
   
   tokens = stmt.split(':')
   
   case tokens[0]
       when 'p'
       
       print $vars[getAdress(tokens[1])]
       when 'i'
       tvar = gets
       
       $vars[getAdress(tokens[1])] = tvar[0..-2]
       when 'n'
       $vars[getAdress(tokens[1])] = Integer(gets)
       when 'g'
       $stmc = tokens[1].to_f - 1
       when '?'
       case tokens[2]
           when '='
           if $vars[getAdress( tokens[1])].to_s != $vars[getAdress(tokens[3])].to_s
               
               $stmc = $stmc + tokens[4].to_f
           end
           when '<'
           if $vars[getAdress(tokens[1])].to_f >= $vars[getAdress(tokens[3])].to_f
               $stmc = $stmc + tokens[4].to_f
               
               end
           when '>'
           if $vars[getAdress(tokens[1])].to_f <= $vars[getAdress(tokens[3])].to_f
               $stmc = $stmc + tokens[4].to_f
           end
       end
       when 'a'
          
            
           $vars[getAdress(tokens[1])] = $vars[getAdress(tokens[1])].to_f + $vars[getAdress(tokens[2])].to_f
       when 's'
       $vars[getAdress(tokens[1])] = $vars[getAdress(tokens[1])].to_f - $vars[getAdress(tokens[2])].to_f
       when 'm'
       $vars[getAdress(tokens[1])] = $vars[getAdress(tokens[1])].to_f * $vars[getAdress(tokens[2])].to_f
       when 'd'
       $vars[getAdress(tokens[1])] = $vars[getAdress(tokens[1])].to_f / $vars[getAdress(tokens[2])].to_f
       when 'k'
       abort()
       else
       $vars[getAdress(tokens[0])]= tokens[1]
       end
end
while $stmc < $stmts.count
   run($stmts[$stmc])
   $stmc = $stmc + 1
end

There also exists a C interpreter, predominantly because User:Deciode felt like writing some C.

Computational class

The Minsky machine could compile to A:;. Here, * reprecent b and c, the two accumulators.

BEGIN := l:1;
INC *, x := a:*:l;g:x;
JZDEC *, x, y := s:*:l;?:*:=:1;j:x;j:y;