kelp is an interpreted, statically typed, C-like programming language. It is compiled to bytecode which is then interpreted in a stack-based virtual machine.
The language is currently mostly complete and has features such as:
- Arithmetic
- Conditionals
- Functions
- Structs
- Multidimensional arrays
- Strings
- Pointers
- Basic type inference (
autokeyword) - Basic introspection (
typeofoperator) - Memory allocation
The language is not yet quite finished. The main features that are currently missing are printing of strings, boolean operators and better error reporting.
For a complete grammar definition, click here.
git clone https://github.com/elvnh/kelp.git --recursivemake -jTo compile and interpret a file, simply run the program and provide the filename as a command line argument.
./build/kelp file.txtFor more examples of the language in use, see the examples directory.
// The entry point of the program.
func main() -> void // The return type of the function 'main'
{
/* In variable declarations, the variable name is followed by a double colon, followed by
the type name and optionally an initializer. */
i :: i32 = 100; // Declare a signed 32-bit integer
k :: u32 = 5; // Declare an unsigned 32-bit integer
print(i * k);
}func fib(n :: i32) -> u64
{
if (n <= 1) {
return 1;
}
return fib(n - 1) + fib(n - 2);
}
func main()
{
print(fib(20));
}struct Foo {
i :: i32;
j :: i64;
}
func make_foo(i :: i32, j :: i64) -> Foo
{
foo :: Foo;
foo.i = i;
foo.j = j;
return foo;
}
func main() -> void
{
foo :: auto = make_foo(500, 1000);
print(foo.i * foo.j);
}Several flags mainly used for debugging purposes are available. Provide one or more of them in addition to a filename. They are as follows:
-l/--lex- Tokenize the source file and print the tokens-p/--parse- Parse the source file and pretty print the abstract syntax tree-f/--fold- Log any constant folding performed-d/--disassemble- Print the bytecode emitted by the compiler-t/--trace- Print a trace of each bytecode instruction executed during interpretation, as well as the current state of the value stack in the virtual machine.-r/--resolve- Log during identifier resolution stage-i/--infer-types- Log during type inference stage