Programming language development

i only really know python, but ive been learning rust. And for anyone interested in programming language development (interpreters and parsers), ill give this link

https://craftinginterpreters.com/contents.html

3 Likes

Hey @JacobMcPherson1 if you’re making an introduction please make your own topic. Go to Topics and press New Topic +, and select Introductions as your tags.

1 Like

No i wasnt making an introduction, just replying to this guys post. Sorry for the confusion lol

2 Likes

Hello and thanks for the link. I know it’s been a bit since this topic was started, but I wanted to give a brief update after a week. I’ve been half-following the general ideas in Crafting Interpreters while making my programming language parser. Now I can say that it works fine with the six or so test scripts (nested control flow, variables, function calls and declarations, etc.). As of now, I’m starting interpreter data structures.

P.S: Are links for GitHub repositories okay here?

Rubel Lang:

  1. Dynamic typing but no type coercion.
  2. “Fail fast” (error on mismatched types and to replace null errors).
  3. Procedural style: just data and functions.
    • Functions are not first-class though.
  4. Might have extensions (like CPython’s API to add custom functions in C).

Syntax Example:

# find bigger number of pair

use io

proc maxPair(a, b)
    if (a >= b)
        return a
    otherwise
        return b
    end
end

# should be 10
print(maxPair(10, 6))
1 Like

Yep, fine!

Very cool. Also, glad your syntax is grammatically correct (if/otherwise instead of if/else).

Edit: also @DerkWithT will you make 1 line return statements like return a if (a >= b) otherwise b?

3 Likes

Hmm. I haven’t thought of making 1 line return statements like that before, but I might add syntax sugar after I really test my interpreter. Maybe a foreach loop of some kind. I also need to support logical operators like &&, ||.

Here is the repository (main branch only has the parser working): Rubel Language

Thanks for the feedback :slight_smile:

2 Likes

Okay, the language is getting some good progress so far. This won’t be the largest update, but the baby steps are good to see. Currently, basic function calls, expressions, and conditional statements work… But I’ll have to fix assignments like set i = i + 1 to update, say, loop counters.

Here is a little peek of my language working. :slight_smile:

1 Like

Just wondering, how does “use io” work?

For now, the use (module name) statement marks a module of native C functions as “usable” so that the function lookup code can retrieve a pointer to that module. Otherwise, the algorithm returns NULL. Then the function object is automatically taken based on its name from the module (like a dictionary with function names as keys). Names with no defined function give NULL.

In the rubel.c file within the repository’s dev branch, I put C function pointers together in a special structure. Then that would be passed by pointer into the interpreter’s context object before the run. That feature reminds me of how the Duktape JS interpreter allows adding new C functions to call from JS scripts it runs.

It is a bit hacky as a solution though, but I plan to clean up my code later this fall. The C code may be big with almost 6000 lines, but I have a working idea of where things are.

2 Likes

Forgive me for not understanding cause i dont know C lol