Annuum is a simple interpreter for a custom scripting language with mathematical focus. It provides functionality for arithmetic operations, variable assignments, conditional statements, loops, function definitions, and printing values to the console.
- π Simple syntax inspired by JavaScript/C
- π’ Support for numeric variables and operations
- π Control flow with if/else statements and loops
- π Loop constructs with
stopandnextoperators - π Constant variable declarations with
const - π¨οΈ Print function for output
- π Function definitions and calls
- π Return statements
- π Comprehensive error reporting
- GCC compiler
- Unix-like environment (Linux or macOS)
- Note: This project is designed exclusively for Unix-like systems due to Cbuilder dependencies
- First, build the builder utility:
gcc b.c -o b- Run the builder to compile the interpreter:
./bThis will create an executable called anum in the current directory.
- Run the interpreter on a script file:
./anumBy default, it will look for a script file at /Users/UserName/Documents/GitHub/Annuum/src/src.txt. You may need to modify the path in main.c to point to your script file.
Variables are dynamically typed and store numeric values:
a = 5;
b = 10;
c = a + b * 2;
Declare constants that cannot be modified:
const PI = 3.14;
const GRAVITY = 9.8;
Supports basic arithmetic:
- β Addition:
+ - β Subtraction:
- - βοΈ Multiplication:
* - β Division:
/
Operations follow standard order of precedence.
Use the print function to display values:
print(c);
If/else statements for conditional execution:
if (condition) {
// code executed if condition is true
} else {
// code executed if condition is false
}
Supported comparison operators:
- Equal to:
== - Not equal to:
!= - Greater than:
> - Less than:
< - Greater than or equal to:
>= - Less than or equal to:
<=
Loop statements for repetitive execution:
loop (condition) {
// code executed while condition is true
}
Loop control operators:
stop- breaks out of the loopnext- skips to the next iteration
Define functions using two different syntaxes:
- Block syntax for multi-statement functions:
fn function_name(param1, param2, ...) {
// function body
// multiple statements
return value; // optional
}
- Arrow syntax for single-expression functions:
fn function_name(param1, param2, ...) -> expression;
Call functions and use their return values:
result = function_name(arg1, arg2, ...);
Use curly braces to group statements:
{
statement1;
statement2;
// more statements
}
Single-line comments start with //:
// This is a comment
a = 5; // This is also a comment
// Define a function that calculates volume of a cylinder
fn cylinder_volume(radius, height) {
const PI = 3.14;
return PI * radius * radius * height;
}
// Call the function
r = 5;
h = 10;
volume = cylinder_volume(r, h);
print(volume); // Output: 785.0
// Define a function to calculate area using arrow syntax
fn circle_area(radius) -> 3.14 * radius * radius;
// Use the function
area = circle_area(5);
print(area); // Output: 78.5
// Calculate factorial of 5
fn factorial(n) {
if (n <= 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}
print(factorial(5)); // Output: 120
// Print factorials until they exceed 100
n = 10;
factorial = 1;
i = 1;
loop(i <= n) {
factorial = factorial * i;
i = i + 1;
if(factorial > 100){
stop; // Break out of the loop
}
print(factorial);
}
To run your own code, save it to a file and update the file path in src/main.c:
const char* src_path = "/path/to/your/file.txt";Then rebuild and run the interpreter.
- Only supports numeric values (floating-point)
- No string support
- No arrays or complex data structures
- Limited standard library functions
- No closures or higher-order functions
src/arr.c&src/arr.h: Dynamic array implementationsrc/lexer.c&src/lexer.h: Lexical analyzersrc/parser.c&src/parser.h: Parser for the languagesrc/interpreter.c&src/interpreter.h: Interpreter for the ASTsrc/logger.c&src/logger.h: Logging utilitiessrc/main.c: Entry pointb.c&b.h: Custom build system (Cbuilder)
The project uses Cbuilder, a custom build system designed for Unix-like environments only. This is why the project will not work on Windows systems without additional compatibility layers.
Made with β€οΈ by DilemaFixer