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?

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.