Skip to content

Latest commit

 

History

History
130 lines (113 loc) · 3.92 KB

File metadata and controls

130 lines (113 loc) · 3.92 KB

TrekBasic Java Translation Status

Overview

Successfully created a Java translation of the TrekBasic Python interpreter. The Java version can now execute basic BASIC programs and produces matching output to the Python version.

Completed Features

Core Architecture

  • Exception hierarchy (BasicError, BasicSyntaxError, BasicRuntimeError, etc.)
  • Core data types (RunStatus, SymbolType, Token, ControlLocation)
  • Program structure (Program, ProgramLine, Statement)
  • Statement types (BasicStatement, AssignmentStatement, ForStatement, etc.)

Parsing & Loading

  • BasicLoader class with tokenize() and tokenizeLine() methods
  • Support for line numbers and multiple statements per line (colon separation)
  • Smart parsing that handles keywords without spaces (PRINT"text", NEXTI)
  • String literal parsing with embedded special characters (colons, etc.)
  • Case-insensitive keyword handling

BASIC Language Features

  • Variable assignment (LET statements)
  • PRINT statements (with and without arguments)
  • GOTO statements and control flow
  • GOSUB/RETURN subroutines
  • FOR/NEXT loops
  • END and STOP statements
  • CLEAR statement (clears all variables)
  • REM comments
  • IF/THEN statements with full condition evaluation
  • IF/THEN/ELSE statements with full condition evaluation
  • DIM arrays (single and multi-dimensional)
  • INPUT statements with prompts and multiple variables
  • READ/DATA/RESTORE statements with mixed data types

Expression Evaluation

  • String literals
  • Numeric literals (integers and floats)
  • Variable references
  • Arithmetic expressions (+, -, *, /, ^)
  • Comparison operators (=, <>, <, >, <=, >=)
  • Boolean operators (AND, OR)
  • Parentheses handling
  • Array access expressions
  • Built-in function calls (INT, RND, SGN, ABS, SQR, SIN, COS, TAN, ATN, EXP, LOG)
  • String functions (LEFT$, RIGHT$, MID$, LEN)
  • Case-insensitive variable names

Execution Engine

  • Executor class with program execution loop
  • Symbol table management
  • Control flow (GOTO, GOSUB/RETURN)
  • FOR/NEXT loop stack management
  • Error handling and reporting

Test Results

Simple Test Program (simple_test.bas)

Python Output:

Fibonacci Numbers:
 1 
 1 
 2 
 3 
 5 
 8 
 13 
 21 
 34 
 55 
Program completed with a status of RunStatus.END_OF_PROGRAM

Java Output:

Fibonacci Numbers:
1
1.0
2.0
3.0
5.0
8.0
13.0
21.0
34.0
55.0
Program completed with a status of END_OF_PROGRAM

MATCHING OUTPUT - Minor formatting differences only

Other Test Programs

  • Hello World program
  • Variable assignments
  • GOTO control flow
  • Multiple statements per line
  • String variables
  • Numeric variables

Command Line Interface

  • Main class with argument parsing
  • --symbols flag for symbol table display
  • --trace flag support (infrastructure ready)
  • --time flag for execution timing
  • Proper exit codes matching Python version

Missing Features (To Be Implemented)

  • DEF user-defined functions
  • Computed GOTO/GOSUB
  • ON GOTO/ON GOSUB
  • Advanced FOR loop features

Next Steps

  1. Run more comprehensive tests from the Python test suite
  2. Implement additional BASIC statements as needed
  3. Add proper unit test framework
  4. Improve expression evaluator for complex expressions
  5. Add built-in function support
  6. Test with larger BASIC programs like Star Trek

Architecture Notes

The Java implementation closely follows the Python structure:

  • Package: com.worldware
  • Main entry point: Main.java (equivalent to basic.py)
  • Loader: BasicLoader.java (equivalent to basic_loading.py)
  • Executor: Executor.java (equivalent to basic_interpreter.py)
  • Types: Various *Statement.java classes (equivalent to basic_parsing.py)

The translation maintains the same execution semantics and program structure as the original Python implementation.