Afth

From Esolang
Jump to navigation Jump to search
Afth
Designed by Sara Berman (User:Lykaina)
Appeared in 2025
Computational class Unknown
Reference implementation https://github.com/lykaina/afth
File extension(s) .afth

A Forth-inspired partially-esoteric language created by Sara Berman that emphasizes the component characters that make up word definitions.

Currently in alpha-stage.

Syntax

Command Groups and Full Line Commands

Most lines are made up sequences of command groups, each separated by one space between and no space at end.

Some lines, however, are full line commands that follow a specific format.

Initial Letters Table

First Char Cmd Group w/ Length or Full Line Meaning
A-Z 2-5 chars Word
' 2 chars Single Char to be put on stack.
+ 2+ chars Multiple bytes to be put on stack in one cell.
<,>,= Prefix + 1-4 chars Variable (Initial Char determines action)
! 2+ chars Command is made up of Core Instruction Chars.
; 2+ chars "Command" is a comment word.
: Full Line Defines a word using Core Instruction Chars.
$ Full Line Defines a variable.
" Full Line String input, one stack cell per char, written in top to bottom order.
# Full Line Line is a Comment

Stacks

There are two LIFO stacks that start empty.

The reference interpreter does not currently have protections against stack underrun.

As Afth lacks interactivity, there is no core instruction that views the stack contents without changing it.

Arrays

There is a single array of signed 32-bit ints with 16384 elements.

Words

Words must start with a capital letter and be made up of 2-5 non-space Printable ASCII chars.

Sample Declaration:

:DUP sSS

Line-scope Variables

There are 7 line-scope variables that are all set to zero at the beginning of a new line (or when jumping to the beginning of the same line):

t, tf, tg, th, ti, tk, tl.

They can not be accessed by the programmer directly.

Variables

Variables are made up of 1-4 non-space Printable ASCII chars.

Variables must be initialized with a value when declared, and must be declared before use.

Sample Declaration:

$i 00

Sample being called to replace it's contents with that of the top of the stack without changing it:

=i

When called, prefix character determines action:

Prefix Char Action
< Puts value of variable on top of stack.
> Pops value off top of stack and puts it in variable.
= Copies top value from stack and puts it in variable.

Jumping

When jumping from one line to another or to the beginning of the same line, any further instructions in the current word or later words on that line are ignored.

If no jump is made, the program will auto-jump to the next line after execution of the line is complete, as if the code _^K_^j were present at the end of the line.

The code _^K_j at the end of a line forces the program into an infinite loop on current line.

Core Instructions

Click here for a copy of this table, ASCII-Sorted

Char Command Name Python-like Pseudo-code
s rcore_t_s t=stack.pop()
S rcore_s_t stack.append(t)
t rcore_t_s2 t=stack2.pop()
T rcore_s2_t stack2.append(t)
. rcore_t_len_s t=len(stack)
: rcore_t_len_s2 t=len(stack2)
f rcore_t_f t=tf
F rcore_f_t tf=t
g rcore_t_g t=tg
G rcore_g_t tg=t
h rcore_t_h t=th
H rcore_h_t th=t
i rcore_t_i t=ti
I rcore_i_t ti=t
k rcore_t_k t=tk
K rcore_k_t tk=t
l rcore_t_l t=tl
L rcore_l_t tl=t
z rcore_zte if(t==0) tk=1; else tk=0
Z rcore_ztg if(t>0) tk=1; else tk=0
j rcore_jnz_r if(tk!=0) goto line# (line+t)
J rcore_jnz_a if(tk!=0) goto line# t
q rcore_quit sys.exit(t)
Q rcore_quit_ifkz if(tk==0) sys.exit(t)
n rcore_not_tk tk = NOT tk
N rcore_not_tl tl = NOT tl
a rcore_and_tk tk = tk AND tl
A rcore_and_tl tl = tk AND tl
o rcore_or_tk tk = tk OR tl
O rcore_or_tl tl = tk OR tl
x rcore_xor_tk tk = tk XOR tl
X rcore_xor_tl tl = tk XOR tl
_ rcore_t_zero t=0
^ rcore_t_inc t=t+1
v rcore_t_dec t=t-1
< rcore_t_shl t=t*2
> rcore_t_shr t=t//2
| rcore_t_abs t=abs(t)
- rcore_t_flipsign t=t*-1
+ rmath_t_tl_add t=t+tl
* rmath_t_tl_mul t=t*tl
/ rmath_t_tl_idiv t=t//tl
% rmath_t_tl_mod t=t%tl
p rmath_t_tl_pow t=math.floor(pow(t,tl))
P rmath_t_tl_log t=math.floor(math.log(t,tl))
b rbarr_t_b_tl t=b[tl]
B rbarr_b_t_tl b[tl]=t
c rbarr_t_wordnum_tl_b get wordnum from t%4+2 chars in array b starting at index tl ; store wordnum to t
C rbarr_t_varnum_tl_b get varnum from t%4+1 chars in array b starting at index tl ; store varnum to t
d rbarr_word_b make new word with name (in wordnum form) in b[t] and valid chars starting at b[t+1]
D rbarr_var_b make new var with name (in varnum format) in b[t] and value of b[t+1]
u rxtra_t_uptime_s t=math.floor(time.monotonic())
U rxtra_t_uptime_ns t=time.monotonic_ns()%1000000000
r rxtra_t_randint t=random.randint(0,t-1)
R rxtra_t_randseed random.seed(t)
w rxtio_t_in_char t=sys.stdin.read(1)
W rxtio_t_in_int codeblock that inputs a base-10 int and stores it to t
y rxtio_t_out_char sys.stdout.write(t)
Y rxtio_t_out_int codeblock that outputs t as a base-10 int
m rxtio_t_in_hex codeblock that inputs a base-16 int and stores it to t
M rxtio_t_out_hex codeblock that outputs t as a base-16 int
e rmeta_run_word_t runs word with name (in wordnum format) in t; t=(sum of return vals)%256 (usually 0). Note: any word whose code contains the char 'e' will not run properly here.
E rmeta_t_var value of var with name (in varnum format) in t is stored to t.

Predefined Words

Word Char String Meaning
NUL Does Nothing
A+ sLs+S Addition
A- s-Ls+S Subtraction
A* sLs*S Multiplication
A/ sLs/S Int Division
A% sLs%S Modulus
Ic wS Char in
Oc sy Char out
Id WS Int in (dec)
Od sY Int out (dec)
Ih mS Int in (hex)
Oh sM Int out (hex)
END _q Quits Program
ABS s|S Makes num on top of stack positive.
NEG s|-S Makes num on top of stack negative.

Examples

Section moved to here.

External Links

GitHub Repository for Afth

GitHub Repository's Wiki for Afth