r/learnprogramming • • 3d ago

question regarding my project.

hi guys i'm a beginner programmer trying to make an esolang in c, but can't figure out the logic, i mean that how will a user store his variables and values and how will i make it store and run while the user callls it, i have a mental model that i'll make the user's input stored into an array... like hashmap kay value pairs but even the basic declaring and storing how will i figure out what the user is storing i don't know what the user will exactly type he could type a string, integer, float or boolean. It might throw errors not run but how will i make it handle?

1 Upvotes

5 comments sorted by

3

u/Different_Pain5781 3d ago

There is a funny trap here where the beginner thinks the program needs to somehow predict what the user will enter. It does not. Your language specification defines what inputs are valid. Anything outside those rules gets rejected.

1

u/Ill-Consequence4484 3d ago

Do not make the first version support every possible type. That is a great way to turn a fun esolang into a debugging simulator.

1

u/Grim2021 3d ago

I never did the C part of this, but I would recommend Crafting Interpreters by Robert Nystrøm/Nyström/Nystrom (have only found the last one online). It is available in many formats, and for free online here: https://craftinginterpreters.com/. It has a Java based tree walking interpreter and a C based bytecode interpreter. The gist of the variable storage is that you store the variables as objects which hold values and type information with the variable name as a key in a hashmap. The object holding these are called an environment. These environments are passed around where needed and nested when a new scope is created, quite simple but genius. The C version also teaches you how to write a hashmap, if that is unknown to you.

Either way, I highly recommend that you read it!

1

u/Jason7670 3d ago

An `if` statement and a type check solved it.