DEV Community

Tushar Vaghela
Tushar Vaghela

Posted on

Ghost BASIC: the dead language still runs, and Gemma has to learn its dialect

Hacktoberfest Open-Source AI Challenge: Ghost in the Machine Submission 👻🌼

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine

What I Built

Ghost BASIC is a small BASIC environment you run in a terminal. The ghost is the language.

Numbered BASIC is the dialect people met in school computer labs: line numbers, FOR/NEXT, PRINT, a program that fit on one screen. Those machines are gone. The programs are not. Ghost BASIC loads a .bas file, including old DOS text, and runs it. Press F5 and it prints. Press F1 and it opens an offline reference for the dialect it actually implements.

Week 4 asked for something spooky, or something that keeps a memory alive. I took the second reading. The first one is painted on the splash screen: an ASCII ghost crosses the terminal, then gets out of the way. What remains is an editor.

Code Magic, on F8, is the optional companion. It can debug, explain, write, or suggest. The default model is Gemma 4 31B (gemma4:31b) through Ollama Cloud. It does not get to invent a richer BASIC than the one on the left. A proposal is compiled locally, and applied only after you review the diff.

Many entries this week put a spirit in the shell. An offline séance with ALGOL 60 keeps a dead language honest by refusing to let the model speak past a curated record. Ghost BASIC is the other half of that idea: the language is executable again, and the model has to write something the runtime will accept.

This is a numbered-BASIC subset, not a finished GW-BASIC or QBasic. QBasic procedures can be opened and read. They cannot run yet.

Demo

Ghost BASIC is a terminal program, so the live site is a tour with real screenshots, not a hosted interpreter:

https://tusharv.github.io/GBASIC/

Startup splash

Editor running a pyramid example

Code Magic beside the program

Python 3.12 or newer. No account for the editor, the examples, F1 help, or Run. Code Magic asks for your own Ollama Cloud key the first time you open it.

git clone https://github.com/tusharv/GBASIC.git
cd GBASIC
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -e '.[dev]'
GBASIC
Enter fullscreen mode Exit fullscreen mode

Then F3, choose fibonacci.bas, F5. Answers to INPUT go in the bottom field. F6 stops a run. GBASIC --no-splash skips the ghost.

The syntax check around Magic is tested with an in-process stand-in for the HTTP call. I did not have an Ollama key in the build environment, so a live model reply is something you will see with your own key. I am not pasting one here as a recorded run.

Code

MIT licensed. The interpreter does not phone home. Magic contacts the network only when you press Send.

GitHub logo tusharv / GBASIC

Ghost Basic - Python based version of classic QBASIC

Ghost BASIC

An independent MIT-licensed BASIC environment for Python 3.12+. Version 0.4 includes a full-screen ASCII terminal editor, searchable keyword help, a tested BASIC interpreter and optional Code Magic powered by Ollama Cloud It is not yet a complete GW-BASIC or QBasic implementation.

Screenshots

Real captures of the running terminal application. The ghost moves in the app; its image below shows one frame of the startup animation.

Editor and program output

Ghost BASIC editor running the pyramid example

Startup splash and flying ghost

Ghost BASIC splash screen with the ASCII ghost

See the examples picker and keyword help

Open dialog with the examples dropdown expanded

Searchable keyword reference displaying FOR loop help

Visit the Ghost BASIC website. The landing page source and GitHub Pages deployment guide are included in this repository.

Launch the terminal UI

After installation and activating the environment, launch from the project folder with:

GBASIC
Enter fullscreen mode Exit fullscreen mode

The package installs both GBASIC and ghost-basic commands. You can also launch directly with .venv/bin/GBASIC (Windows: .venv\Scripts\GBASIC.exe).

A startup splash displays Ghost BASIC with a flying ASCII ghost…

examples/fibonacci.bas:

10 A=0: B=1
20 FOR I=1 TO 10
30 PRINT A;
40 T=A+B: A=B: B=T
50 NEXT I
60 PRINT
Enter fullscreen mode Exit fullscreen mode

The editor, the runtime, and the 175-topic help stay on the machine. Send is the only arrow that leaves: one fenced program comes back, the local compiler checks it, and you apply the diff yourself.

How I Built It

Ghost BASIC is Python 3.12. The terminal UI is Textual. Execution, file loading, and help need no model and no network. Help covers 175 topics, and anything not implemented is marked that way.

Old files are part of the point. Open accepts UTF-8 and falls back to DOS CP437, including box-drawing characters and a trailing Ctrl+Z. Save writes UTF-8 and does not rewrite the original just because you opened it.

Code Magic calls Ollama's chat endpoint. The default model name is gemma4:31b. You can type another Cloud model name. The key is stored in the OS credential vault (macOS Keychain, Windows Credential Locker, or a Linux secret service), not in a project file.

The model has no shell, no filesystem, and no permission to run the program. Each Send can include the open filename (not the folder), the source, and the last 6,000 characters of that run's output. Turn Context off and those stay behind. The prompt lists the implemented statements and tells the model not to invent RND, procedures, or graphics.

If the reply contains exactly one basic fence, Ghost BASIC compiles that source and does not execute it. A syntax error triggers one correction request. A second failure is shown to you. Apply appears only after you open the diff. Ctrl+Z undoes it. F5 is how you learn whether the program does what you asked. A clean compile is not proof of behavior.

That constraint is the project. A general model will happily write QBasic. Ghost BASIC cannot run QBasic procedures. The interesting failure is a fluent program the interpreter rejects.

Why Does Open Innovation Matter?

A closed chat API could explain a FOR loop. It could not be the language.

The interpreter, the help, and the examples stay on the machine. A classroom or a folder of old .bas files does not need an account. If the model host disappears, PRINT still prints. That is the part a closed API cannot offer: the artifact outlives the service.

Magic does use a service, and that limit should be plain. It needs a network and an Ollama Cloud account. It does not run with the cable pulled. What the open-weight model changes is the contract around that call:

  • The default brain is Gemma, named in settings as gemma4:31b. Swapping the model name does not mean rewriting the interpreter.
  • The dialect rules live next to the compiler that enforces them. A vendor cannot silently widen BASIC with features this runtime does not have. The local check sends those answers back.
  • You can read the prompt, the size limits, and the one-correction rule. Apply is a diff against the editor, not a hidden write.
  • Only the open buffer and a slice of output go out, and only when you press Send.

A closed assistant would still draw a triangle of asterisks. It would also be free to describe a language I did not build. Here the language is the repository. The model is a guest that has to pass the compiler.

The Spirit of It

The splash ghost is a joke that lasts a few seconds. The part that stayed is quieter.

Open a file saved on a DOS machine. The line endings are wrong for a modern editor, the box-drawing characters are in CP437, and the file may end with the Ctrl+Z those programs used as an end mark. Ghost BASIC reads it, leaves the original bytes on disk, and shows numbered lines you can run.

That is the offering. Not a story about the person who typed 10 PRINT. The program itself, still willing to print.

Prize Categories

  • Best Use of Gemma. Code Magic defaults to gemma4:31b on Ollama Cloud. The prompt, the one-shot syntax repair, and the apply path are built around that open-weight model, and the name can be changed. Inference is hosted. This is not a local Gemma runtime.

Top comments (0)