- About
- Features
- Getting Started
- Usage
- Language Syntax
- Future Features
- Benchmarking Performance
- Contributing
- License
- Contact
Beavieeer is a simple, C-like interpreted toy programming language written in Rust. This repository contains the implementation of the interpreter for Beavieeer. The language is designed to be easy to learn, with basic control structures, data types, and functional programming features. It supports both running scripts from .be files and an interactive REPL (Read-Eval-Print Loop).
- Control Structures:
ifstatements for conditional logic. - Data Types:
- Primitive types:
Integer,String, andBoolean. - Complex types:
ListandHash.
- Primitive types:
- Anonymous Functions: Functions that can be defined without a name and passed around as values.
- Higher-order function: A function that takes one or more functions as arguments
- I/O:
print- Prints a value to the console.read- Read a value from the console.readFile- Read the contents of a file.writeFile- Writes to a file the given contentString. Creates a file if it does not exist.
- List Operations:
len- Returns the length of a given list.first- Returns the first element of a list.last- Returns the last element of a list.tail- Returns all elements of a list except the first.get- Returns the element of a list specified by its index.map- Applies a function to each element of a list and returns a new list.filter- Filters a list based on a predicate function and returns a new (filtered)list.reverse- Reverses a list.
- Functional Utilities:
fold- Reduces a list to a single value using a function.
- String Utilities:
lowercase- Returns the lowercase equivalent of the original Stringuppercase- Returns the uppercase equivalent of the original Stringtrim- Returns a String with leading and trailing white space removedparseNumber- Converts a String into a numberreplaceString- Replaces all matches of a pattern with a StringreplaceN- Replaces the first N matches of a pattern with a Stringexplode- Converts a string to a list. Each of the characters in the string is given an index that starts from 0- More to be added
- Script Mode: Run Beavieeer programs from a file with the
.beextension. - Interactive REPL: Experiment with Beavieeer code interactively. To exit, type
:q.
- Rust: Ensure you have Rust installed. If not, install it using Rust's official guide.
- Clone the repository:
git clone https://github.com/Turtel216/Beavieeer.git cd Beavieeer - Build the project:
cargo build --release
- Run the interpreter:
./target/release/beavieeer
To execute a Beavieeer script, create a file with the .be extension and run:
./beavieeer path/to/script.beExample script:
let fibonacci = fun(x) {
if (x == 0) {
0;
} else {
if (x == 1) {
1;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};
let result = fibonacci(10);
print(result);Start the REPL:
./beavieeerYou can now write and execute Beavieeer code interactively. Exit the REPL by typing :q. Use :info to list built-in functions or :info <function> to get details about a specific one. You can also access all available commands and information by typing :help.
let x = 42;
let name = "Beavieeer";
let isAwesome = true;if (x > 10) {
print("x is greater than 10");
} else {
print("x is less than or equal to 10");
}let x = 1;
let y = if (x == 2) { 2 } else { 1 };
print(y); // 1let nums = [1, 2, 3, 4];
print(nums[1]); // 2
print(first(nums)); // 1
print(last(nums)); // 4
print(tail(nums)); // [2, 3, 4]Beavieeer also supports adding lists
let lstOne = [1, 2, 3, 4];
let lstTwo = [5, 6, 7, 8];
let lstCombined = lstOne + lstTwo // [1, 2 ,3 ,4 ,5 ,6 ,7 ,8]let square = fun(n) { n * n };
print(map([1, 2, 3, 4], square)); // [1, 4, 9, 16]let person = {"name": "Alice", "age": 30};
print(person["name"]); // Alicelet hello = "Hello, ";
let world = "World!";
let contact = hello + world;
print(contact); // Hello, World!
let upper = uppercase(contact);
print(upper); // HELLO, WORLD!
let lower = lowercase(upper);
print(lower); // hello, world!
let replaced = replaceString(lower, "world", "beavieeer");
print(replaced); // hello, beavieeer!
let hey = "Hey Hey Hey";
let bye = replaceN(spam, "Hey", "Bye", 2);
print(bye); // Bye Bye Hey-
importbuildin for importing other Beavieeer files. - ``Hash` utility functions
- http utility functions.
- REPL improvements.
We benchmarked our interpreter against Python using a Fibonacci sequence calculation to measure execution speed. The tests were conducted using hyperfine, a reliable benchmarking tool.
- Comparison: Our interpreter vs. Python 3.
- Tool Used:
hyperfine(for accurate timing). - Command Used:
hyperfine "python3 ./benchmarks/fibonacci.py" "./target/release/beavieeer ./benchmarks/fibonacci.be"
| Language | Execution Time (mean ± σ) | Speed Factor |
|---|---|---|
| Python 3 | 115.8 ms ± 0.7 ms | 1x (Baseline) |
| Beavieer 1.2 | 3.020 s ± 0.096 s | ~26.07x slower |
| Beavieer 1.3 | 2.841 s ± 0.086 s | ~24.38x slower |
# On Linux/macOS
sudo apt install hyperfine # Debian/Ubuntu
brew install hyperfine # macOS (Homebrew)
# On Windows (via Cargo)
cargo install hyperfinehyperfine "python3 ./benchmarks/fibonacci.py" "./target/release/beavieeer ./benchmarks/fibonacci.be"Contributions are welcome! Please open an issue or submit a pull request if you have ideas for improvements.
- Fork the repository.
- Create a new branch for your feature/fix:
git checkout -b feature-name
- Commit your changes and push to your fork.
- Open a pull request to the
mainbranch.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or suggestions, feel free to open an issue or cOntact the maintainer at papakonstantinou.dm@gmail.com.