BASIC Interpreter

(remixed from BASIC Interpreter, by pumpkinhead) by 18001767679
See Code Download Embed
-------------------------------
HOW TO USE:
-------------------------------
This is BASIC. I'm not going to write down all of how BASIC works, but here is a website that briefs on how it works: http://www.quitebasic.com/help/

Note that the website has some special variables/functions that are exclusive to their interpreter. There is no LEVEL constant and arrays don't work like that here. Also you need to declare variable types here. Also, the graphics capabilities I programmed here differ from the ones they say. Additionally, there is no modulo operator because % is already used for something else. But I added a modulo function in case you need that. mod(a, b)

==TYPED VARIABLES==

The Quite BASIC help does not tell you how to make variables types, because their interpreter is special and does not use typed variables. But my interpreter does.

Let us have a variable named "TEST". If we want to make that a string:

LET TEST$ = "Hello, world!"

(I think $ was chosen because it looks like S, which could stand for string)

If we want to make that an integer:

LET TEST% = 3

And if we just want to make that a floating point number:

LET TEST = 3.14159265

Also you don't have to name your variables one letter with several digits after here, unlike what it says in the Quite BASIC help page. You can name it any text, like "TEST". "T123" works here too. And even "123T". That's weird

==KEYBOARD INPUT==

To get the last key pressed, use the GETCHAR function. It will return the keycode of the last key pressed.

For letter keys, they are the unicode value of the text from the unicode of () block. Here are a few useful keycodes:

SPACE: 32
LEFT: 37
RIGHT: 39
UP: 38
DOWN: 40

==HOW TO DRAW GRAPHICS==

I put in a few special commands/variables that allow you to draw things on screen. It uses turtle graphics because that is how pen works in Snap!.

Commands:
- TGOTO x,y: Equivalent to the go to x: () y: () block
- TDOWN: Equivalent to the pen down block
- TUP: Equivalent to the pen up block
- TMOVE steps: Equivalent to the move () steps block
- TCLEAR: Equivalent to the clear block
- THUE hue: Sets pen hue
- TSAT saturation: Sets pen saturation
- TBRI brightness: Sets pen brightness
- THUEC d: Changes pen hue
- TSATC d: Changes pen saturation
- TBRIC d: Changes pen brightness 

Special variables:
- TURTLEX: X position of turtle
- TURTLEY: Y position of turtle
- TURTLEDIR: Direction of turtle
- TURTLESIZE: Pen size

These special variables work just like regular variables: you can set them using LET and get them by calling their name.

-----------------------------
CHANGELOG
-----------------------------

11/5/20: Expressions are compiled into an expression tree before running. This makes it much faster. In the circle example, it took about 20 seconds to draw the circle previously. Now it takes just 3 -- 566% faster.

-----------------------------
RESEARCH
-----------------------------

Actually I didn't know how to program in BASIC before starting this project

https://www.calormen.com/jsbasic/
https://www.quitebasic.com/ 

Created September 25, 2020

Last updated November 17, 2020

Shared November 17, 2020