Cube is a simple custom interpreted programming language implemented in Go, following the principles outlined in the book "Writing an Interpreter in Go" by Thorsten Ball. This project was designed to help me deeper understanding how interpreters work.
Before you begin, make sure you have Go installed on your system. You can download and install Go from the official website.
Clone this repository to your local machine using:
git clone https://github.com/AzraelSec/cube.gitChange your current directory to the Cube project folder:
cd cubeTo build the Cube interpreter, run the following command:
makeThis will generate two executables:
repl: A REPL interpreter to test the language instructions.cube: A file content interpreter.
To run a Cube program, use the following command:
./cube filename.cbReplace filename.cb with the path to the Cube script you want to execute.
Cube has a simple and minimalistic syntax. Here are some basic features of the language:
- Variables: Cube supports variable assignment and usage.
- Arithmetic Operations: You can perform basic arithmetic operations (addition, subtraction, multiplication, division) in Cube.
- Basic string manipulation: Cube supports strings comparison and basic concatenation using the
==and+operators. - I/O builtins: You can use the
printandreadstatement to display and read from console. - Conditional Statements: Cube supports
ifandif/elsestatements for basic conditional logic. - Functions and closures: Functions are first-class citizens in Cube, so you can assign them to variables, pass them to other functions, etc.
For a more detailed description of the language syntax, refer to the code and comments in the Cube interpreter source files.
Here's a simple Cube program that calculates the factorial of a given number and prints the result:
To run this program, save it to a file with the .cb extension and execute it using the Cube interpreter.

