Skip to content

otherfunc/otherfunc-basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

otherfunc-basic

Bytecode-compiled line-number BASIC interpreter with HTTP, KV, and environment variable support.

Implementation

  • Pipeline: Source -> Tokenizer -> Parser -> Compiler -> Bytecode -> Stack VM
  • f64 numbers and string variables ($ suffix); comparisons return -1 (true) or 0 (false)
  • Statements: LET, PRINT, INPUT, IF/THEN, GOTO, GOSUB/RETURN, FOR/TO/STEP/NEXT, END, REM, HTTPHEADER
  • 16 built-in functions: ABS, INT, RND, LEN, LEFT$, RIGHT$, MID$, STR$, VAL, CHR$, ASC, INSTR, KVGET$, KVSET, KVDEL, ENV$
  • HTTP outbound via coroutine/yield: HTTPGET$("url"), HTTPPOST$("url", "body"), ENV$("KEY")
  • Custom HTTP headers: HTTPHEADER name$, value$ (set before next HTTP request, auto-cleared after use)
  • KV storage via coroutine/yield: KVGET$("key"), KVSET("key", "value"), KVDEL("key")
  • Multiple statements per line with :, case-insensitive keywords, xorshift64 PRNG
  • Default instruction limit: 10,000,000 (configurable via with_instruction_limit())

Install

cargo install --path .

Usage

# Inline code
basic '10 PRINT "Hello, World!"'

# From file
basic -f program.bas

# Piped input (for INPUT statements)
echo "42" | basic '10 INPUT A : 20 PRINT A * 2'

As a Library

use otherfunc_basic::BasicInterpreter;
use otherfunc_core::Interpreter;

let mut basic = BasicInterpreter::new();
let output = basic.execute("10 PRINT 3 + 4", "").unwrap();
assert_eq!(output, "7\n");

Tests

cargo test -p otherfunc-basic    # 38 tests

About

Bytecode-compiled line-number BASIC interpreter

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages