Ascii²

From Esolang
Jump to navigation Jump to search
Ascii²
Paradigm(s) imperative
Designed by User:Rphii
Appeared in 2021
Memory system Variables, dynamic Memory
Dimensions one-dimensional
Computational class Unknown
Major implementations Author's
Influenced by Text
File extension(s) .ascii2

Created by User:Rphii in 2021. Ascii², Ascii2 or AsciiAscii is an Esolang.

Variables

Before we take a look at anything else, let's talk about variables. Every variable is only one Ascii character long and has a value of type signed integer assigned.

They can be split into two groups: (see Input and Output)

  • Numbers: 0123456789
  • Characters: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz:;<=>?@[\]^_{|}~!"#$%&'()*+,-./ (Basically any Ascii character except for numbers. Including space and all control sequences.)
  • There is only one single Ascii character that should not be treated like a variable and that is `.

Initialization

  • Every variables value is initialized to its corresponding Ascii value. A in that case would get assigned to 65, B to 66, C to 67...
  • Variables 0 through 9 are an exception, as their values get assigned to 0-9 respectively (because they are in the numbers group, they get treated like numbers).
  • Every memory bank gets initialized this way.
  • The starting memory banks are 0.

Instructions

Every instruction is a pair of Ascii characters. That and the fact that almost every character is a variable is the reason for this language's name.

There are a few instructions.

  • Memory Bank
  • Add
  • Set 0
  • Loop, else and invert
  • Input
  • Output

Memory Bank

There is an other and a source bank.

  • You can switch your memory bank with `` to the last accessed variable's value.
  • Every time you switch banks, the source bank gets set to the one you switch to.
  • If you were to write the following code: ```` it will first switch the bank (described above) and afterwards swap the other and source banks.

Add

ab will add the values of a's and b's variables and assign the result to a.

  • The first variable is accessed from the source bank.
  • The second variable is accessed from the other bank.

Set 0

Since adding a value of zero to something doesn't make sense, it got replaced with a more useful operation.

  • The variable is accessed from the source bank.
  • Example: a0 will set the value of a's variable to zero. Note that you can use any variable whose value is 0 to set the value of another variable to 0.

Loop, else and invert

This can also be called the LEAI-Instruction. If you try to add a variable to itself, eg. 11, you will find out that you can't, because that's the keyword used for this instruction.

  • The variable is accessed from the source bank.
  • This instruction consists of three parts: FOR, ELSE and END thus you always have to have a triple pair present.
  • FOR: From now on, reference the variable from the current source bank. If the variable's value is not zero, decrement (positive) or increment (negative) the value by one and execute the code up to the ELSE statement. If the variable's value is zero, set it to the inverse of what it started with when it first entered the FOR. Only if it didn't entered FOR in the first place, execute the trailing code after ELSE up to the END. And in any case from now on (after executing code up to the END), remove the reference previously set.
  • ELSE: Jump back to FOR.
  • END: see above.
  • You can make nested loops with different variables. You can also escape loops.

Examples

  • Basic loop: aaa1aaaa (infinite loop)
  • Escaping ELSE: gg00gggg0000 (g would be kind of like a "global" variable from now on. If you switch banks, you would still reference the g variable from its initial bank. One of many approaches.)
  • Catching ELSE: gggggg (counterpart from above, release from "global" variable. One of many approaches.)

Input

Request user input with a leading `.

  • The variable is accessed from the source bank.
  • Example: `a request a string from the user and store it in variable a (because the variable is in the group of characters). The first character gets stored in the source bank. For each following character, we increment the bank and store it in the same variable a, until we eventually set a variable in a bank to 0, when the string ends. After this, the source bank is the same as it was when before asking for input.
  • Example: `1 request a number (multiple digits) from the user and store it in variable 1 (because the variable is in the group of numbers).

Output

Output with a trailing `.

  • The variable is accessed from the source bank.
  • Example: a` will print a single character of variable a's value (because the variable is in the group of characters).
  • Example: 1` will print the number of variable 1's value (because the variable is in the group of numbers).

Examples

Hello World

H`e`l`l`o`,` `W`o`r`l`d`!`
`

If you want a one-liner: (Ascii 10 is a linefeed, or, new line. I like to append a newline, so that the cursor moves accordingly...)

H`e`l`l`o`,` `W`o`r`l`d`!`a0a9a1a`

Truth Machine

`222211`220`22

Cat

L0L1`ILL``````III1I`L2I0IIL0IILLLL

Ascii table

Prints all Ascii characters from (space, 32) to ~ (tilde, 126)

~1~~~~~~n0n9n1R0R RRR1S0SRS~SSS0202R2`:` `R`n`R1SSR0SSRRRR

ℒight interpreter

###1#`####

Implementation

Interpreter written in C (github)