Skip to content

Instantly share code, notes, and snippets.

@schas002
Created March 25, 2017 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schas002/51bb8d945b71a8656b27099ebc919c05 to your computer and use it in GitHub Desktop.
Save schas002/51bb8d945b71a8656b27099ebc919c05 to your computer and use it in GitHub Desktop.
schas002's Concise Language specification, working draft 1.

A work in progress esoteric language. Version: WD 1

Syntax

Data types

The language has a meaning of data types. There are number data types, the only ones so far.

Number

Numbers are signed integers which can go at least up to 255 (2^8 - 1).

They are denoted as N in instruction listings, though that can also denote any type at all.

Commands

Commands are characters or character combinations that start with one or more `x` characters and end with the same amount of characters, with the requirement that the first of these is not `x`.

Execution

Commands act on an infinite stack.

Commands are executed left-to-right.

Sanitization

Before a schas002’s Concise Language program is executed, it is first sanitized from non-code by removing these things in order.

1. Block comments

Any construct that starts with `x[` and ends with `x]` is removed. (Blocks that encounter the start or end of the file don’t require a matching `x[` or `x]`.)

2. Inline comments

Any construct that starts with `x#` and goes up until the end of line is removed.

3. Whitespace

Any whitespace characters (any space, tab or newline) is removed.

NOP axiom

If an invalid command is detected, it is just not executed, essentially becoming a no-op (NOP).

Instructions

Input/Output

`i` ( | N )

  1. Input N, an integer from standard input.
  2. Push N.

`I` ( | N )

  1. Input a character from standard input. Let this be c.
  2. Push N, the character ordinal of c.

`o` ( N | )

  1. Pop N, an integer.
  2. Output N to standard output.

`O` ( N | )

  1. Pop N, an integer.
  2. Output the character corresponding to the ordinal N to standard output.

Push/Pop

`0` ( | 0 )

  1. Push 0.

`_` ( N | )

  1. Pop N.

Increment/Decrement

`u` ( N | N2 )

  1. Pop N.
  2. Push N2, N + 1.

`d` ( N | N2 )

  1. Pop N.
  2. Push N2, N - 1.

Arithmetic

`+` ( N N2 | N3 )

  1. Pop N, an integer.
  2. Pop N2, an integer.
  3. Push N3, N + N2.

`-` ( N N2 | N3 )

  1. Pop N, an integer.
  2. Pop N2, an integer.
  3. Push N3, N - N2.

`*` ( N N2 | N3 )

  1. Pop N, an integer.
  2. Pop N2, an integer.
  3. Push N3, N × N2.

`/` ( N N2 | N3 )

  1. Pop N, an integer.
  2. Pop N2, an integer.
  3. Push N3, N ÷ N2 rounded down.

`m` ( N N2 | N3 )

  1. Pop N, an integer.
  2. Pop N2, an integer.
  3. Push N3, N mod N2.

Rationale

`%`, which is usually used in other programming languages for this operation, is already allocated for the swap operation in this language. `m` is used instead, which stands for modulo.

`p` ( N N2 | N3 )

  1. Pop N, an integer.
  2. Pop N2, an integer.
  3. Push N3, N to the power of N2.

Rationale

`^`, which is usually used in other programming languages for this operation, is already allocated for the pick operation in this language. `p` is used instead, which stands for power.

Open questions
Couldn’t `e` be used instead, which stands for exponentiation?

Stack operations

`$` ( x N | x N N )

  1. Pop N.
  2. Push N two times.

This is also known as the dup operation, and is expressed in instruction listings as:

  1. Dup a.

`%` ( x N N2 | x N2 N )

  1. Pop N.
  2. Pop N2.
  3. Push N2.
  4. Push N.

This is also known as the swap operation.

`@` ( a b c d | d a b c )

  1. Move the top of stack to the bottom of stack.

This is also known as the roll operation, and it rolls the stack upwards.

`^` ( x N N2 | x N N2 N )

  1. Dup N.

This is basically the dup operation applied on the second to top of stack, and is known as the pick operation.

Flow control

`:`

Closes the nested structure currently going on.

`?`

Is a nested structure that runs if and only if the top of stack is nonzero. The top of stack is only peeked at.

`w`

Is a nested structure that loops while the top of stack is nonzero. The top of stack is only peeked at.

`xh`

Halts execution of the program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment