1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-License-Identifier: EUPL-1.2
// Copyright (c) 2025 The BASIC DSL Contributors
/*!
# BASIC DSL
A procedural macro crate that provides a BASIC interpreter DSL embedded in Rust.
## Usage
```rust
use basic_dsl::basic;
basic! {
10 FOR I = 1 TO 5
20 PRINT I
30 NEXT I
40 PRINT "DONE"
50 END
}
```
The macro supports classic BASIC programming constructs:
### Control Flow
- **FOR...NEXT loops**: `FOR variable = start TO end [STEP increment]` and `NEXT [variable]`
- **Conditional jumps**: `IF condition THEN GOTO line`
- **Unconditional jumps**: `GOTO line`
- **Program termination**: `END`
### Variables and Expressions
- **Variable assignment**: `LET variable = expression`
- **Arithmetic**: `+`, `-`, `*`, `/`
- **Comparisons**: `<`, `<=`, `=`, `>=`, `>`
- **Numbers and string literals**: `42`, `"Hello World"`
### Input/Output
- **Printing**: `PRINT expression` (numbers and strings)
### Advanced Features
- **Nested loops**: Full support for nested FOR...NEXT constructs
- **Expression evaluation**: Complex arithmetic and string handling
- **Runtime error checking**: Proper error handling for invalid operations
*/
use TokenStream;
use Result;
use crategenerate_runtime_code;
use crateparse_basic_program_tokens;
/// Main entry point for the BASIC DSL macro.
///
/// Accepts BASIC program code as direct tokens.