A simple interpreter written in Rust that supports basic variable declarations, printing output, and mathematical calculations following BODMAS (Brackets, Orders, Division, Multiplication, Addition, Subtraction).
- Variable declaration and assignment with optional type annotations
- Mathematical operations with proper operator precedence (BODMAS)
- Print statements for output
- String and numeric literal support
Run the interpreter on a source file:
cargo run -- path/to/file.ruspy
With debug mode to print AST and execution flow:
cargo run -- -d path/to/file.ruspy
// Variable declarations
x: int64 = 10;
y: int64 = 5;
// Mathematical operations following BODMAS
result: int64 = (x + y) * 2 / (5 - 2);
print result; // Should output 10
// Complex expression
complex: int64 = x * (y + 3) - 2 ^ 2;
print complex; // Should calculate following BODMAS
// String output
message: str = "Hello, Ruspy!";
print message;
The interpreter follows a classic compiler pipeline:
- Lexer: Tokenizes the source code
- Parser: Builds an Abstract Syntax Tree (AST) from tokens
- Interpreter: Evaluates the AST and executes the program
To get started with Ruspy, clone the repository and follow the instructions below.
- Rust 2021 edition
- Clone the repository:
git clone https://github.com/Himasnhu-at/ruspy.git
- Navigate to the project directory:
cd ruspy
- Build the project:
cargo build
Run the project using:
cargo run
Contributions are welcome! Please read the contributing guidelines for more details.
This project is licensed under the BSD-Clause-3 License - see the LICENSE file for details.
For any questions, please contact Himanshu at hyattherate2005@gmail.com.
You can download pre-built binaries for your platform:
curl -LO https://github.com/Himasnhu-at/ruspy/releases/latest/download/ruspy-linux.tar.gz
tar xzf ruspy-linux.tar.gz
sudo mv ruspy-linux /usr/local/bin/ruspy
Download ruspy-windows.zip
from the releases page and extract it.
curl -LO https://github.com/Himasnhu-at/ruspy/releases/latest/download/ruspy-macos.tar.gz
tar xzf ruspy-macos.tar.gz
sudo mv ruspy-macos /usr/local/bin/ruspy
- To build the releases, run:
Note
Before running the build script, make sure you have cross toolchain installed. MacOS build is only supported on macOS. Toolchains:
x86_64-unknown-linux-musl
x86_64-pc-windows-gnu
aarch64-apple-darwin
To install, run:
rustup target add x86_64-unknown-linux-musl
rustup target add x86_64-pc-windows-gnu
rustup target add aarch64-apple-darwin
chmod +x build.sh
./build.sh
This setup will:
- Optimize the binary size and performance
- Create static binaries that don't require Rust installation
- Support cross-compilation for different platforms
- Package the binaries appropriately for each platform