The official repository for the GenLang programming language.
var cache = {};
func fibonacci(var n) {
if (n <= 1) {
return n;
}
if (cache[tostring n] != null) {
return cache[tostring n];
}
var result = fibonacci(n - 1) + fibonacci(n - 2);
cache[tostring n] = result;
return result;
}
func main(var argv) {
var n = tonumber argv[0];
print fibonacci(n);
}
The /programs folder contains several demo programs that showcase the power of the language:
- Interpreter - a simple bootstrapped interpreter of a programming language
- Calculator - a simple interpreter of mathematical expressions
- Fibonacci Recursive - recursive implementation of Fibonacci
- Fibonacci Cached - recursive Fibonacci with cached results
- Tree Traversal - depth-first search and bread-first search tree traversal algorithms
- Matrix Multiply - matrix multiplication algorithm
The documentation can be found in the following documents:
- Language Design - describes the language design, syntax, constructs and datatypes
- Bytecode Reference - list of supported bytecode instructions
- Implementation - implementation details of the language
Below is an overview of the repository structure:
/src- contains the source code of the GenLang interpreter/tests- contains unit test files/programs- contains example demo programs/docs- contains documentation documents/debug- contains the list of tokens and bytecode instructions emitted from the most recent run of the interpreter
The project was developed using Python version 3.14.0, therefore Python version 3 and higher is recommended for running the project. To run a source code file in the language, modify the program.gen source code and use the run.sh script:
./run.shTo provide command line arguments to the GenLang program, use the following syntax:
./run.sh "Hello, World!" 25These arguments are forwarded to the main function:
func main(var args) {
print args;
}
Alternatively, you can run the program using:
python3 main.py <source_code_file_path> <command_line_arguments>To run tests, use the test.sh script that runs lexer, parser, compiler, virtual machine and complex test suites:
./test.sh