BASIC DSL for Rust 🦀
A Rust procedural macro crate that provides a BASIC interpreter embedded as a domain-specific language with direct token parsing for excellent IDE support.
Features
- Variables: Assignment with
LETand arithmetic expressions - Output:
PRINTstatements for numbers and string literals - Control Flow:
IF...THEN GOTOconditionals andGOTOjumps - Loops:
FOR...NEXTloops with optionalSTEPincrement - Program Structure: Line numbers, labels, and
ENDtermination - IDE Support: Full syntax highlighting, error reporting, and code completion
Usage
Add this to your Cargo.toml:
[]
= "0.2.0"
Then use the macro in your Rust code:
use basic;
Syntax
The DSL supports classic BASIC syntax with modern IDE integration:
Statements
LET variable = expression- Variable assignmentPRINT [expression, ...]- Output values or strings (comma creates tab stops for columnar formatting, or empty for newline)GOTO label- Jump to line numberIF condition THEN GOTO label- Conditional jumpFOR variable = start TO end [STEP increment]- Loop initializationNEXT [variable]- Loop increment and condition checkEND- Terminate program
Expressions
- Arithmetic:
+,-,*,/with proper precedence - Comparisons:
<,<=,=,>=,> - Literals: Numbers (
42) and strings ("Hello") - Variables: Any valid identifier (
X,COUNTER, etc.) - Parentheses: For grouping expressions
Program Structure
- Line numbers act as labels for jumps and program flow
- Statements are written directly without quotes for full IDE support
- Nested FOR loops and complex expressions are fully supported
Examples
Enhanced PRINT Statement
basic!
RustBasic FizzBuzz
basic!
Running Examples
This repository includes example programs that you can run:
# Run the RustBasic FizzBuzz example
# Run comprehensive feature tests
# Run enhanced PRINT statement demo
License
Licensed under the European Union Public Licence 1.2 (EUPL-1.2).