C3 is an open source programming language created in 2019 by Christoffer LernΓΆ.
| #107on PLDB | 7Years Old |
git clone https://github.com/c3lang/c3cC3 is a programming language that builds on the syntax and semantics of the C language, with the goal of evolving it while still retaining familiarity for C programmers.
module stack {Type};
// Above: the parameterized type is applied to the entire module.
struct Stack
{
usize capacity;
usize size;
Type* elems;
}
// The type methods offers dot syntax calls,
// so this function can either be called
// Stack.push(&my_stack, ...) or
// my_stack.push(...)
fn void Stack.push(Stack* this, Type element)
{
if (this.capacity == this.size)
{
this.capacity *= 2;
this.elems = realloc(this.elems, $sizeof(Type) * this.capacity);
}
this.elems[this.size++] = element;
}
fn Type Stack.pop(Stack* this)
{
assert(this.size > 0);
return this.elems[--this.size];
}
fn bool Stack.empty(Stack* this)
{
return !this.size;
}| Feature | Supported | Example | Token |
|---|---|---|---|
| hasReservedWords | β | ||
| Switch Statements | β | switch(expression) { case 1: do_something(); case 2: if (x > 0) nextcase 1; // Jump to 1 nextcase; // Jump to the next case. default: foo(); } | |
| Structs | β | struct Test { int x; float y; String z; } | |
| Strings | β | String s = "hello"; String t = `I say "hello"`; | |
| Ternary operators | β | int foo = x ? 1 : 0; | |
| Scientific Notation | β | ||
| While Loops | β | while (int x = foo(); x > 0) { sum += x; } | |
| Conditionals | β | ||
| Assignment | β | a = b; | |
| Case Sensitivity | β | ||
| Pointers | β | ||
| Variadic Functions | β | fn void foo_typed(int x, int... arg) { ... } fn void foo_untyped(int x, ...arg) ... foo_typed(1, 2, 3); foo_untyped(1, "hello", 1.2); | |
| Module Pattern | β | module my_module::submodule; ... | |
| Operator Overloading | β | fn int IntList.get(IntList* this, int idx) @operator([]) { return this.vals[idx]; } ... IntList x = ... foo(x[1]); | |
| Multiline Strings | β | String s = `this string is multiline`; | |
| MultiLine Comments | β | /* Multiline comment */ | /* */ |
| Methods | β | fn int Foo.get_value(Foo* this) { return this.value; } | |
| File Imports | β | import std::io; | |
| hasForEachLoops | β | foreach (x : list) { foo(x); } | |
| Macros | β | macro square(x) { return x * x; } | |
| Union Types | β | union Foo { int x; float f; struct { char[2] z; } } | |
| Single-Type Arrays | β | ||
| Unary Operators | β | ||
| Enums | β | enum TestEnum : int { FOO, BAR, BAZ } | |
| Doc comments | β | <* @param [in] foo "The foo value" @return "the toal foo count" *> | |
| Constants | β | const FOO = 123; const void* BAR = null; | |
| Access Modifiers | β | ||
| Zero-based numbering | β | ||
| Default Parameters Pattern | β | fn void test(int x = 10) { ... } | |
| Assert Statements | β | assert(a > 0, "Expected a positive number"); $assert(Foo.sizeof == 8, "Foo sizecheck at compile time failed"); | |
| Manual Memory Management | β | ||
| Increment and decrement operators | β | i++; --j; | |
| Integers | β | int x = 314159; | |
| Namespaces | β | import std::io; ... io::printf("%d", i); | |
| Type Casting | β | double d = 3.3; int x = (int)d; | |
| Binary Literals | β | 51 | |
| Null | β | ||
| Lazy Evaluation | β | fn void print(String s) { io::printfn("Said: %s", s); } macro @foo(bool run, #lazy) { if (run) #lazy; } // Only "Said: Hello" is printed: @foo(false, print("Bye")); @foo(true, print("Hello")); | |
| Labels | β | while FOO: (x > 0) { for (int i = 0; i < 10; i++ { x = baz(); if (x > i) break FOO; } } | |
| Inheritance | β | ||
| Functions | β | ||
| Implicit Type Casting | β | ||
| hasIfElses | β | ||
| hasIfs | β | ||
| Hexadecimals | β | ||
| hasForLoops | β | ||
| Expressions | β | ||
| hasEscapeCharacters | β | "\e\n\r" | |
| hasContinue | β | ||
| hasBreak | β | ||
| hasBoundedCheckedArrays | β | ||
| hasArraySlicingSyntax | β | int[] slice1 = array[0..5]; // start..end int[] slice2 = array[0:6]; // start:length | |
| Octals | β | 127 | |
| Bitwise Operators | β | int i = b << 4 + x; // Same as (b << 4) + x | |
| Booleans | β | true false | |
| Comments | β | // A comment /* Another comment */ | |
| Line Comments | β | // A comment | // |
| Garbage Collection | X | ||
| Gotos | X | ||
| Case Insensitive Identifiers | X | ||
| Constructors | X | ||
| Variable Substitution Syntax | X | ||
| hasUserDefinedOperators | X | ||
| Units of Measure | X | ||
| Unicode Identifers | X | ||
| Abstract Types | X | ||
| Classes | X | ||
| Directives | X | ||
| Multiple Inheritance | X | ||
| S-Expressions | X | ||
| Pipes | X | ||
| Message Passing | X | ||
| Magic Getters and Setters | X | ||
| Homoiconicity | X | ||
| Function Composition | X | ||
| Function Overloading | X | ||
| Here Document | X | ||
| Dynamic Properties | X | ||
| Duck Typing | X | ||
| hasBuiltInRegex | X | ||
| Async Await | X | ||
| Semantic Indentation | X | ||
| Regular Expression Syntax Sugar | X |