Classic BASIC interpreter

A BASIC interpreter as on the early home computers. Although slow, it will run faster than on the original hardware. It is still unstructured, of course. No spaces are necessary between keywords. To use this program, knowledge of BASIC is assumed. There is no tutorial. Documentation: Vijgeblad #42, 1993. The original author is Lennart Benschop. Here is the main source file that will work for iForth. And here are two example input files (1,2).

Bugs

Not in the original specification

KEYWORD PUT \ one str var, may be preceded by #n

Unimplemented as yet


KEYWORD EDIT \ EDIT n
KEYWORD DEF \ DEF FNa(x)=expr Define a user function

EDIT is not needed when PROCED is active. Just type the linenumber and ^PgDn

DEF is difficult; what happens to the formal parameter? Is it a global?

Implemented constructs

PRINT     \ num or string exprs or TAB(n), separated by ; or ,
          \ may be preceded by #n
INPUT     \ one num or str var, may be preceded by #n
GET       \ one str var, may be preceded by #n
PUT       \ one str var, may be preceded by #n
OPENIN    \ OPENIN a$, Open the single input file #1
OPENOUT   \ OPENOUT a$, Open the single output file #1
GOTO      \ GOTO line number.
ON        \ ON n GOTO linenumbers or ON n GOSUB linenumbers
GOSUB     \ GOSUB linenumber
RETURN
IF        \ IF n THEN linenumber or IF n THEN statements
THEN
FOR       \ FOR var=n1 TO n2, with optional STEP n3
NEXT      \ NEXT or NEXT var
END	  \ Ends with "Ok" message
STOP	  \ Ends with "Stop" message
CLEAR     \ Removes all variables.
LET       \ LET var=n or LET var$=n$, The word LET is optional
REM
READ      \ num or str var, separated by ,
DATA      \ num or str expr separated by commas, skipped on execution
RESTORE   \ Resets data pointer
CLS       \ clear screen
LOCATE    \ LOCATE row,col
INVERSE   \ INVERSE n, where n=0 or 1
BEEP      \ Make a sound
RANDOMIZE \ RANDOMIZE or RANDOMIZE n. Initialize random numbers.
POKE      \ POKE addr,n Corrupts your memory
CALL      \ CALL addr   Hangs your machine
DEF       \ DEF FNa(x)=expr Define a user function 		UNIMPLEMENTED
NEW       \ Remove program and variable from memory.
LIST      \ LIST LIST n LIST m-n LIST -n LIST m- all possible
          \ May be followed by ;A$ to send listing to file.	UNIMPLEMENTED
	  \ (Workaround: type open-log BASIC LIST BYE close-log)
LOAD      \ LOAD a$
SAVE      \ SAVE a$. Program is stored in internal format
RUN       \ clear variables and start running
CONT      \ continue after break or STOP command
EDIT      \ EDIT linenumber (use PROCED)			UNIMPLEMENTED
MERGE     \ MERGE a$ Add the lines to your program, from ASCII file
DELETE    \ DELETE n, DELETE m-n
BYE       \ Return to the world of REAL computing.
MODE      \ MODE 0 or MODE 1 Select text/graphics mode
PLOT      \ PLOT x,y  plot a single point.
DRAW      \ DRAW x,y  draw a line.
CLOSEIN   \ Close the input file
CLOSEOUT  \ CLose the output file
DIM	  \ num or str array variables separated by ,
FILES     \ Show the directory.

TO
STEP
AND
OR
NOT
<>
<=
<
>=
>
FN

ABS   	\ ABS(n), absolute value
SGN   	\ SGN(n), 0,1 or -1 depending on sign.
INT   	\ INT(n), round down towards -infinity.
SQR   	\ SQR(n), square root.
LOG   	\ LOG(n), natural logarithm.
EXP   	\ EXP(n), e to the power of n
ATN   	\ ATN(n), inverse tangent, in radians.
SIN   	\ SIN(n),
COS   	\ COS(n)
TAN   	\ TAN(n)
LEN   	\ LEN(n$), length of n$
ASC     \ ASC(n$), ASCII code of first char, 0 if n$ is empty
CHR$    \ CHR$(n), Single char string with ASCII code n.
LEFT$   \ LEFT$(n$,n)  Left n characters from n$
MID$    \ MID$(n$,m,n) or MID$(n$,m)  Substring starting at m
RIGHT$  \ RIGHT$(n$,n)  Right n characters from n$
UCASE$  \ UCASE$(n$) n$ converted to uppercase.
VAL     \ VAL(n$) convert ASCII string to number.
STR$    \ STR$(n) or STR$(n,w,a) convert n to ASCII, optionally
        \ w indicates the length and a the number of places after .
EOF     \ EOF indicates end of input file.
HPOS    \ HPOS the horizontal position of the cursor
VPOS    \ VPOS the vertical position of the cursor
FREE    \ FREE  The free space in bytes.
SCREEN$ \ SCREEN$(row,col) the character there
PEEK    \ PEEK(addr) The byte stored there.
RND     \ RND gives a different random number every time.
INKEY$  \ INKEY$ the string containing the key pressed, if any
TAB

free counter Valid HTML 3.0