An open API service indexing awesome lists of open source software.

https://github.com/anmitalidev/able

ABLE - Another BASIC Language Environment
https://github.com/anmitalidev/able

basic basic-programming-language dialect langdev language lgpl lgplv3 rust

Last synced: about 2 months ago
JSON representation

ABLE - Another BASIC Language Environment

Awesome Lists containing this project

README

          

# ABLE - Another BASIC Language Environment

**Alpha release of a BASIC dialect interpreter in Rust**

[![License: LGPL-3.0](https://img.shields.io/badge/License-LGPL--3.0-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
[![Version](https://img.shields.io/badge/version-0.1.0-green.svg)](https://github.com/AnmiTaliDev/able)
[![Rust](https://img.shields.io/badge/rust-1.70+-orange.svg)](https://www.rust-lang.org)
[![Made with Rust](https://img.shields.io/badge/Made%20with-Rust-orange.svg)](https://www.rust-lang.org)

## Features (Alpha)

### Commands
- `PRINT` - output values and expressions
- `INPUT` - user data input
- `LET` - variable assignment
- `IF...THEN` - conditional statement
- `GOTO` - jump to line number
- `SLEEP` - execution delay in milliseconds
- `END` - program termination

### Functions
- `TIME` - returns milliseconds since program start

### Data Types
- **Integers** (Integer)
- **Strings** (String) - with `$` suffix or auto-detection

### Operating Modes
- **Program Mode**: programs with line numbers (stored in BTreeMap)
- **Immediate Mode**: REPL for direct command execution

## Building and Running

```bash
# Build in release mode
cargo build --release

# Run the interpreter
cargo run

# Run the compiled binary
./target/release/able
```

## Interface Features

✨ **Colored terminal output**
- Commands highlighted in different colors
- Errors highlighted in red
- Line numbers in listing highlighted in cyan
- Beautiful banner on startup

## Project Structure

```
able/
├── Cargo.toml # Project configuration
├── README.md # Documentation
├── LICENSE # LGPL-3.0 license
├── examples/ # Example programs
│ ├── hello.bas # Hello World
│ ├── counter.bas # Simple counter
│ ├── input.bas # Working with input
│ ├── fibonacci.bas # Fibonacci numbers
│ ├── guess.bas # "Guess the number" game
│ ├── timer.bas # Using TIME and SLEEP
│ └── countdown.bas # Countdown
└── src/
├── main.rs # Entry point and REPL with colored output
├── lexer.rs # Lexical analyzer
├── parser.rs # Syntax parser
├── ast.rs # AST definitions
├── env.rs # Variable environment
└── interpreter.rs # Interpreter with GOTO logic
```

## Usage Examples

### Example 1: Hello World (Immediate Mode)
```basic
> PRINT "Hello, World!"
Hello, World!
```

### Example 2: Counter Program
```basic
> 10 LET X = 1
> 20 PRINT "Counter: "; X
> 30 LET X = X + 1
> 40 IF X <= 10 THEN GOTO 20
> 50 PRINT "Done!"
> 60 END
> LIST

10 LET X = 1
20 PRINT "Counter: "; X
30 LET X = X + 1
40 IF X <= 10 THEN GOTO 20
50 PRINT "Done!"
60 END

> RUN

Counter: 1
Counter: 2
Counter: 3
Counter: 4
Counter: 5
Counter: 6
Counter: 7
Counter: 8
Counter: 9
Counter: 10
Done!
```

### Example 3: Data Input
```basic
> 10 PRINT "What is your name?"
> 20 INPUT NAME$
> 30 PRINT "Hello, "; NAME$
> 40 END
> RUN
```

## REPL Commands

- `LIST` - show program listing
- `RUN` - run the program
- `NEW` - clear program and variables
- `VARS` - show all variables and their values
- `HELP` / `?` - command help
- `EXIT` / `QUIT` - exit the interpreter

## Interface Features

✨ **Modern REPL with extended features**
- ⌨️ **Arrow key support** - command history navigation (↑/↓)
- ✏️ **Line editing** - standard editing keys
- 📝 **Command history** - saved between sessions
- 🎨 **Colored output** - commands and errors highlighted
- ⚡ **Quick keys**:
- `Ctrl+C` - clear current line
- `Ctrl+D` - exit
- `Ctrl+L` - clear screen (in some terminals)

## Architectural Features

### Execution Loop with GOTO
A key component of the interpreter is the execution loop with `GOTO` support:

```rust
// Main loop in interpreter.rs
loop {
// Check GOTO (Program Counter)
if let Some(target_line) = self.pc.take() {
idx = find_position(target_line);
}

// Execute current line
execute_line(idx);

// Move to next line (if no GOTO)
if self.pc.is_none() {
idx += 1;
}
}
```

### Program Storage
Uses `BTreeMap` for automatic sorting of lines by numbers.

## License

This project is distributed under the LGPL-3.0 license. See the LICENSE file for details.