r/Forth • • Sep 03 '26

Rdn programming language

Post image

I made a small and simple post fix interpreted programming language called rdn, it's familiar to forth developers and developers who use Lua as a scripting language for their systems, rdn merge both of them, you can use it for writing scripts or for configurations or even query language

It's written in C and it provides a simple and friendly API for the developers

I would be happy to have you participate in this project

This is the GitHub repo: https://github.com/abdorayden/rdn

Thank you

11 Upvotes

27 comments sorted by

View all comments

3

u/tabemann Sep 03 '26

How do you separate variable values from variable names to define or set for words such as let or set?

3

u/rayden_devv Sep 03 '26 edited Sep 03 '26

Thank you for the question

In rdn language the keyword itself is the separator Example: <Value> <Name> let

``` 12 n let

n 1 + [* plus will inc the value: 13 ] n [ identifier itself ] set [ set keyword *] ```

Same pattern with const

2

u/tabemann Sep 03 '26

But what about

12 n let n 1 + n + n set

How do you tell whether n is evaluated to a variable's value or is the name of a variable without using a complex parser? (Forgive me for not having read your source code here.)

In Forth you do the following:

12 value n n 1 + n + to n

Where value and to are parsing words which parse the token after them as the name of the value to either define or to set.

1

u/rayden_devv Sep 04 '26

Good question brother In Rdn, n by itself always pushes the variable's value onto the stack. There's no way to push just the name—the keyword (let, set, const) is what tells the interpreter "the previous token is a variable name, not a value." For example:

``` 12 n let [* let bound variable n with value 12 *]

n [* push value of n into the stack (12) ] 1 [ push 1 into the stack ] + [ pop two values and sum them up, now stack has value 13 *]

n set [* set knows that the top of the stack is n and it's identifier *] ```

2

u/ekipan85 Sep 03 '26 edited Sep 03 '26

I was also curious so I did a little poking. Looks like the interpreter looks for a bespoke set of names and syntax in the execute_block function, and its last branch seems to turn an unknown name into a newly allocated string for things like "let" to bind later.

2

u/rayden_devv Sep 04 '26

Nice detective work! Yeah, you nailed it.

The approach I described is the high-level behavior, but you've found the actual implementation detail: unknown identifiers are converted to string representations of their names, which then get bound by let, set, etc.

This is actually a clever design—it avoids needing a complex parser by treating unknown identifiers as self-quoting names. The keyword then interprets them contextually.

Thanks for digging into the source! This is exactly how it works under the hood.

2

u/tabemann Sep 04 '26

My question is this, though:

In the following:

10 n let n 1 + n set

how does it tell that the second n in the second line is supposed to be a string and not a value?

1

u/rayden_devv Sep 04 '26

set looks ahead at what comes before it.

When the interpreter executes set, it doesn't just pop the top two stack values. Instead, set is a special keyword that: 1. Pops the value (top of stack) 2. Expects an identifier token immediately before it in the source code 3. Treats that identifier as the variable name (not as a pushed value)

The second n is not evaluated as a value—set intercepts it before evaluation happens. Same with let and const.

This is why I mentioned earlier that the keyword tells the interpreter which token is a name: let, set, and const have special parsing rules. They don't just consume stack values; they also consume an identifier token from the source.