r/ProgrammingLanguages • u/Gingrspacecadet • Feb 17 '26
Language announcement Coda compiler update
I've been working on Coda, an attempt at a new systems language Currently, it's able to parse this program:
module simple;
include std::io;
include std::string;
@extern
fn int[] *? *? mut* main(@extern mut char mut*? e, mut int *foo, char mut*?mut*?mut*? beans);
into this (pretty) AST:
=== Module ===
Name: simple
Includes (total 2):
Include:
Path: std::io
Include:
Path: std::string
Declarations (total 1):
- Decl 0: kind=0
Function: main
@extern
Return type: * mut opt: * opt: * opt: slice: int
Parameters:
- Param 0: e: * mut opt: char mut
@extern
- Param 1: foo: *: int mut
- Param 2: beans: * mut opt: * mut opt: * mut opt: char
Body:
<no body>
=== End Module ===
I am currently working on statement parsing, then I'll do expressions and finally function bodies (at the moment it only parses function signatures)
As always, the code can be found here. All contributions are welcome!
If you have any questions I'm up for answering them :3
10
Upvotes
View all comments
Show parent comment
2
u/Gingrspacecadet Feb 19 '26
sure! So.
all functions begin with
fn. then the return type, followed by function name, '(', comma-seperated parameters, ')' and then either a semicolon or the body. I'm assuming that you are stumbling over theint[] *? *? mut*bit? It's simple once you know.mainreturns a '?' to a '? to a 'mut*' to an int splice. '?' attaches to the pointer on its left, and means that said pointer being null is an acceptable, valid possibility - otherwise the compiler is very strict and enforces that it cannot be null. 'mut' binds to the pointer on its right, and means that the pointer can be changed, as in Coda everything is immutable by default (where it points to, not the data). finally, the '[]' after the int describes it as a splice - literally just a builtin structure of array + length (normal arrays do not exist for UB reasons). Finally, the '@extern' before the function and before a parameter is what's called an attribute (extra data for the compiler, like extern or packed), which binds to the declaration on the right.hope this helps! feel free to ask any more questions on any bits