A modern Rust implementation of UBASIC - Advanced BASIC interpreter with mathematical capabilities, graphics support, and interactive console.
- Arbitrary Precision Arithmetic: Using the
rugcrate for high-precision mathematical calculations - Complex Numbers: Full support for complex number operations and mathematical functions
- Interactive Console: Modern REPL with syntax highlighting, auto-completion, and command history
- Graphics Support: 2D graphics using ggez and egui (optional features)
- File I/O: Execute BASIC programs from files
- Error Handling: Comprehensive error reporting with line numbers and context
- Memory Management: Efficient variable and array management
- Extensible: Modular architecture for easy extension
# Clone the repository
git clone https://github.com/your-username/ubasic-rust.git
cd ubasic-rust
# Build the project
cargo build --release
# Run in interactive mode
cargo run -- interactive# Interactive mode
cargo run -- interactive
# Execute a BASIC file
cargo run -- --file program.bas
# Evaluate code directly
cargo run -- --eval "PRINT 2 + 2"
# Set precision for calculations
cargo run -- --precision 128 --eval "PRINT PI"LET x = 3.14159
LET y = SIN(x)
PRINT "sin(π) =", y
LET z = (1 + 2i) * (3 + 4i)
PRINT "Complex multiplication:", zLET sum = 0
FOR i = 1 TO 10
LET sum = sum + i
NEXT i
PRINT "Sum of 1 to 10:", sumDIM arr(5)
FOR i = 0 TO 4
LET arr(i) = i * i
NEXT i
PRINT "Array:", arrcargo run -- examples/hello.bas
cargo run -- --interactive
In interactive mode, you can type BASIC commands directly:
> LET A = 5
> PRINT A + 2
7
> PRINT "Hello, UBASIC!"
Hello, UBASIC!
> exit
The project is organized into several modules:
types.rs: Core data types (Integer, Float, Complex, String, Array, etc.)parser.rs: Lexical analysis and parsing of BASIC codeinterpreter.rs: Execution engine and statement processingmath.rs: Mathematical functions and operationsmemory.rs: Variable and array managementconsole.rs: Interactive console interfacegraphics.rs: Graphics operations (optional)errors.rs: Error handling and reporting
# Development build
cargo build
# Release build with optimizations
cargo build --release
# Build with specific features
cargo build --features "graphics,console"# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_basic_arithmetic# Check code formatting
cargo fmt
# Run clippy linter
cargo clippy
# Run clippy with all warnings
cargo clippy -- -W clippy::all- Arbitrary Precision: Integer and floating-point arithmetic with configurable precision
- Complex Numbers: Full support for complex arithmetic and functions
- Mathematical Functions: sin, cos, tan, exp, ln, sqrt, abs, factorial, etc.
- Constants: π (pi), e (Euler's number)
- Syntax Highlighting: Color-coded BASIC syntax
- Auto-completion: Variable and function name completion
- Command History: Persistent command history across sessions
- Built-in Commands: help, clear, exit, etc.
- 2D Graphics: Drawing lines, circles, rectangles
- GUI Framework: Integration with egui for immediate mode GUI
- Game Engine: ggez integration for game development
The interpreter provides detailed error messages including:
- Syntax Errors: Line and column numbers for parsing errors
- Runtime Errors: Variable not found, type mismatches, etc.
- Mathematical Errors: Division by zero, overflow, etc.
- Stack Traces: Function call stack for debugging
- Efficient Parsing: Fast lexical analysis and parsing
- Memory Management: Optimized variable storage and garbage collection
- Arbitrary Precision: Configurable precision for mathematical calculations
- Parallel Processing: Support for parallel execution (optional)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Rust coding conventions
- Add tests for new features
- Update documentation
- Use meaningful commit messages
- Ensure all tests pass before submitting
This project is licensed under the MIT License - see the LICENSE file for details.
- Original UBASIC by Yuji KIDA
- Rust community for excellent libraries and tools
- Contributors and maintainers
- Complete parser implementation
- Graphics integration
- WebAssembly support
- Package manager for BASIC libraries
- IDE integration
- Performance optimizations
- Additional mathematical functions
- Network and I/O capabilities
For questions, issues, or contributions:
- Open an issue on GitHub
- Join our discussion forum
- Check the documentation
- Review existing issues and pull requests
UBASIC Rust - Bringing the power of modern Rust to BASIC programming!