Katra

BASIC language interpreter in CoffeeScript

Katra emulates a subset of three basic dialects: HP 2000/Access BASIC, GWBasic, and Atari Basic.

For our purposes, there is little difference between these three with the exception of string handling in GWBasic, which uses MID$, LEFT, RIGHT$, etc.

Other differences don't overlap:

  • You can use either braces or parens to access arrays, so DIM Z(2) and DIM Z[2] work the same.
  • Use Cat[alog], Gro[up], or Lib[rary] to list HP user group and system folders. Use GET-STTR1 to load from user, GET-*TREK73 to load from group, and GET-$TRADER to load from the system folder.
  • Use DIR to list the GWBasic root, and GWBASIC "path/to/file" to load a program.
  • Use FILES to list the Atari root, and ATARI "path/to/file" to load a program.

Katra specific:

  • Commands and keywords are not case sensitive, but variable names are. So this code:
                    10 LET X = 10
                    20 let x = 42
                    30 end
                    
    will set two different variables - 'X' and 'x' to 10 and 42 respectively. ALL of the old prgrams are in upper case, and expect upper case input. I think lower case was invented in the 90's.
  • Use TRON and TROFF to turn trace on and off. This prints each line to the console as it executes.
  • Commands vs Keywords: Keywords work can be entered directly or on a line number. Commands can only be entered directly. This means that commands cannot appear in a program.
  • Use CTRL/C to abort a program. Use CTRL/R to restart.
  • When you see the '>' prompt, you are in REPL mode.
  • When you see the '?' prompt, a running program is waiting for input.
  • You can create new HP programs. They will be saved to local storage in your browser.

Append-filename
Merge basic file into workspace.
Atari "filename"
Loads an atari basic game.
Catalog
List user programs.
Del [-from] [, to]
Delete program line number(s).
Execute-filename
Loads filename and executes.
Get-filename
Loads a program from storage.
Group
List group programs.
Gwbasic "filename"
Loads an gw basic game.
Library
List system programs.
List [-from] [, to]
To list the program, from and to line numbers.
Purge-filename
Delete program file.
Run
Runs the currently loaded progam.
Save
Saves current program.
Scratch
Erase current variables.
Tron | Troff
Turn debug listing on or off.
Base(n)
Sets the low bound array indice - default 0.
Cls
Erases the console area.
Data n, 'string', ...
List data constants.
Def FN<a>(x) = expression
Define a function.
End
Ends the program execution.
For <var> = <expression> To <expression> [Step <expression>]
Head of a For/Next loop.
Goto <line no>
Jump to the line number.
Gosub <line no>
Jump to subroutine at line number.
If <condition> Then line no
If the expression is true, jump to the line number.
Image var [,var...]
List of variables to print.
Input var [,var...]
Input a List of variables.
[Let] var = [var = ] expression
Set variable to expression.
Mat var = <Con|Zer>
Initialize array values.
Next var
Footer of for next loop. Increments var by step.
Print expression [; expression ;]
Print list of expressions.
Purge
Removes the current program from memory.
Read var [, var ...]
Read variables from Data.
Restore
Reset Data to beginning.
Return
Return from a subroutine.
Rem text...
Comments.
Stop
Stops execution.

Enter test to view the contents of the test folder. Enter get-#for to load the test program. Enter list to display the program.

Enter run to run the program, or enter exe-#data to run another test program.

Enter scr to erase the program from ry. Enter list to see that it is gone.

Enter the following code:

        10 LET X = 42
        20 PRINT "THE ANSWER IS";X
        30 END
            
Enter name-test and then save.

After restarting the browser, enter cat and the program 'test' will be included in the list. Enter exe-test to load and run the saved code.

back


Copyright Dark Overlord of Data 2012 - 2014