Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

antigravity-basic

test Antigravity for make basic

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

Tiny BASIC Interpreter (Pascal)

A lightweight, feature-rich BASIC interpreter written in Free Pascal. Supporting classic syntax, floating-point math, and character-based animations.

User Guide

How to Build

Requires Free Pascal Compiler (fpc).

bash
fpc basic.pas

How to Run

Run the executable directly for an interactive REPL:

bash
.\basic.exe

Or pipe a script file:

cmd
type anim.bas | basic.exe

Supported Commands

  • PRINT: Output text or values. Use ; for 8-char tab stops and , for a single space.
  • LET: Variable assignment (e.g., LET X = 10 or just X = 10).
  • IF ... THEN: Conditional execution.
  • FOR ... TO ... STEP ... NEXT: Loop constructs (supports nested loops and expressions).
  • GOTO: Jump to a line number.
  • LOAD "file.bas" / SAVE "file.bas": File persistence.
  • SLEEP <ms>: Pause execution.
  • CLS: Clear the screen.
  • LIST, RUN, NEW, BYE: Environment control.

Project Structure

  • basic.pas: The core interpreter source code.
  • anim.bas, multi_char_vars.bas, user_loop.bas: High-level program examples and demos.
  • tests/: Extensive suite of technical tests and feature verification scripts.

Technical Details (Internal Architecture)

🤖 LLM Implementation Notes

This interpreter is designed for modularity and correctness in parsing complex expressions and control flow.

Core Components

  • Scanner/Tokenizer: Keyword-aware scanner that handles "spaceless" syntax (e.g., LETA=10) by preferring keywords unless they are prefixes of longer identifiers. Case-insensitive.
  • Variable Storage: Uses TStringList for dynamic Name-Value mapping. Variables are stored as strings but treated as Double for calculations.
  • Expression Parser: Recursive descent parser supporting operator precedence (* / > + - > = > < <> <= >=).
  • Control Flow:
    • Line-based memory: Program is stored as a linked list of lines.
    • Statement-level jumps: Supports jumping back to specific statements within a multi-command line (separated by :).
    • Loop Stack: Handles nested FOR loops with a context stack storing the target line and the specific statement content to resume from.

Key Features

  • Floating-Point: Internal numeric type is Double.
  • Trigonometry: Built-in SIN() function.
  • Multi-Statement: : separator allows multiple commands per line.
  • Clean REPL: No prompt symbols (>) and minimal status messages for sleek output compatibility.

Constraints & Compatibility

  • Compiled with fpc version 3.2.2+.
  • Cross-platform CLS support (ANSI escape codes on POSIX, cmd /c cls on Windows).
  • Fixed-size loop stack (10 levels deep).
  • No line number range limits (uses Integer for line numbers).