EXCON

From Esolang
Jump to navigation Jump to search

EXCON is a lame abbreviation for EXclamation mark COloN and was designed by Emil Svensson (User: fr34k) in 2008.

Overview

Initially EXCON has one pool with 8 binary digits, all set to 0 and a pointer set to the right-most digit in the pool.

Commands

Command Function
: Reset all digits in the pool to 0
^ Flip the digit at the pointer
! Output the pool
< Move the pointer to the left

Examples

Initially, we start out with an empty pool, with the pointer pointing at the right-most digit

00000000
       ^

(the above code is just for clarification, and is not actual source code)

If we want to write the letter A, which in binary is 01000001, we must flip the first and the seventh bit. Like this

:         Reset the pool (this is optional at the beginning of a program)
^         Flip the first bit (making it 1)
<<<<<<    Move 6 steps to the left
^         Flip the 7th bit
!         Output the pool (A or in binary 01000001)

EXCON treats all other characters than ':', '^', '<' and '!' as comments. The above program can be written like this as well

:^<<<<<<^!

Notice that we don't have to move to the eight bit, since this remains 0, we don't have to do anything with it.

Note: If you move the pointer more than 8 steps, the program will take this as a fault operation, since all ASCII characters converted to binary consists only of 8 digits.

Hello, World!

hello-world.excon

:<<<^<<<^! 		1001000 H
:^<<^<<<^<^! 		1100101 e
:<<^<^<<^<^! 		1101100 l
!			1101100 l
:^<^<^<^<<^<^! 		1101111 o
:<<<<<^! 		0100000 SPACE
:^<^<^<<^<<^! 		1010111 W
:^<^<^<^<<^<^! 		1101111 o
:<^<<<^<^<^! 		1110010 r
:<<^<^<<^<^! 		1101100 l
:<<^<<<^<^! 		1100100 d
:^<<<<<^! 		0100001 BANG

Above code would output in ASCII

Hello World!

99 bottles of beer

Here is the program (it takes a long time to load, and the output gets truncated).

Interpreter

Here's an EXCON interpreter written in Ruby:

# interpreter.rb

def interpret_EXCON source

	pool = %w[0 0 0 0 0 0 0 0]
	pointer = 7
	
	for i in 0..source.length
	
		case source[i..i]
		
			when ":" then pool = %w[0 0 0 0 0 0 0 0]; pointer = 7
			when "^" then pool[pointer] = if pool[pointer]==1 then 0 else 1 end
			when "<" then pointer -= 1
			when "!" then print pool.join.to_i(2).chr
		
		end
	
	end

end

interpret_EXCON File.open(ARGV[0], "r").read

And here is an interpreter in Io:

#!/usr/local/bin/io
exconI := Object clone
exconI pool := List clone setSize(8) map(0)
exconI pointer := 7
exconI interpret := method(source,
    source foreach (c,
        if(c == 58, pool = pool map(0); pointer = 7)
        if(c == 94, pool atPut(pointer, if(pool at(pointer) == 1, 0, 1)))
        if(c == 60, pointer = pointer - 1)
        if(c == 33, pool map(print) "\n" print)
    )
)
if(System args at(1), exconI interpret(System args at(1)) println, "No input" println)

A Python interpreter by User:Bangyen can also be found here.