Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BASIC Interpreter

A Dartmouth BASIC language clone, interpreter REPL and "Transpiler" to Go, written in Go Lang.

disclaimer: 80 % Vibe coded, 10% love of programming, 10% coffee.

Vibe coding and Manual coding

  • Phase 1 BASIC REPL in GoLang: AbacusAI-- Claude Sonnet 4.5; couldn't quite get it right, but laid the ground work for the REPL.

  • Phase 2 BASIC and Troubleshooting: AbacusAI Claude Sonnet 4.5; coding BASIC and troubleshooting in Go

  • Phase 3 GoLang and Troubleshooting: GPT-5.1 Codex, mostly built the compiler, not happy with this but it works.

Features

  • Classic BASIC syntax with line numbers
  • Supported statements:
    • PRINT - Output text and expressions
    • LET - Variable assignment
    • IF...THEN...ELSE - Conditional execution
    • FOR...TO...STEP...NEXT - Loops
    • GOTO - Jump to line number
    • GOSUB/RETURN - Subroutines
    • INPUT - User input
    • DIM - Array declaration
    • REM - Comments
    • END - End program
  • Operators: +, -, *, /, MOD, <, >, <=, >=, ==, <>, AND, OR, NOT
  • Data types: Numbers and Strings
  • Arrays with indexing

Building

go build -o basic main.go

Usage

Run a BASIC file:

./basic examples/hello.bas

Transpile a BASIC file to Go

./basic -compile hello.go examples/hello.bas
go run hello.go

Compile a BASIC file to a single executeable, 2 step procedure

./basic -compile hello.go examples/hello.bas && go build -o hello hello.go

Interactive REPL:

./basic

REPL commands:

  • RUN - Execute the program
  • LIST - Show the program
  • CLEAR or NEW - Clear the program
  • EXIT or QUIT - Exit the interpreter
  • SAVE <filename.bas> - Save code to disk
  • LOAD <filename.bas> - Load code from disk
  • DELETE n - Deletes a line number

Examples

Hello World

10 PRINT "Hello, World!"
20 END

For Loop

10 FOR I = 1 TO 10
20 PRINT I
30 NEXT I
40 END

Input and Conditionals

10 INPUT "Enter your age: "; AGE
20 IF AGE >= 18 THEN PRINT "Adult" ELSE PRINT "Minor"
30 END

Example Programs

See the examples/ directory for more sample programs:

  • hello.bas - Hello World
  • fibonacci.bas - Fibonacci sequence
  • guess.bas - Number guessing game
  • multiply.bas - Multiplication table
  • gosub.bas - Subroutine example

About

Dartmouth BASIC done in Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages