A simple interpreter for a custom scripting language (.fork files) implemented in Rust. Supports control flow constructs (like for loops), arithmetic expressions, assignments, and print statements.
- For Loops: C-style
forloops, including variable initialization, condition, and increment. - Arithmetic Expressions: Supports
+,-,*,/in assignments and print statements. - Print Statements: Print variables, string literals, and arithmetic expressions.
- Variable Assignment: Supports variables and re-assignment.
- File Extension Enforcement: Only files with
.forkextension can be run. - Clean Modular Code: Refactored for maintainability; control flow handled in dedicated modules.
- Rust (edition 2021 or later)
- Git (to clone the repo)
git clone https://github.com/Sahildhillon0/fork.git
cd forkcargo buildcargo run ./src/test.fork- Only files with the
.forkextension are accepted. - Example output:
x = 20 y*7 = 0 y*7 = 7 ...
x = 20;
print("x = ", x);
for (int y = 0; y < x; y = y + 1) {
print("y*7 = ", y*7);
}
If you run with no arguments:
cargo runYou get an interactive prompt:
fork> x = 5;
fork> print("x = ", x);
x = 5
fork>
Type exit or quit to leave the REPL.
src/main.rs- Entry point, file/repl handling, extension checksrc/interpreter/- Interpreter logiccontext.rs- Variable storage and context managementmod.rs- Module declarations for interpretercontrol/- Control flow modules:mod.rs- Control module declarationsfor_loop.rs- Implementation offorloopsif_else.rs- Implementation ofif-elseconstructsloops.rs- General loop handlingcondition.rs- Conditional logic
statement/- Statement handling modules:mod.rs- Statement module declarationsassignment.rs- Assignment statement logicprint.rs- Print statement logic
src/codegen.rs- Code generation logic (if applicable)src/test.fork- Example program
Pull requests are welcome!
MIT