BASIC implemented in Snap!

I most likely posted this in here before, but here is a programming language that I made when the new "split blocks" block came in. I made this solely because Snap was getting laggy when I had too many blocks in a project, so I made this one day. The language supports a "texting based" game that I made when the "ask" block got changed. (see: I made a story using the Menus library)

Here's the project: Snap! Build Your Own Blocks

The documentation for it: I made a custom programming language based on BASIC

It's simply a BASIC compiler that boils things back down to Snap! blocks. I'd really like to see what the Snap! community does with it. (i.e. extends the language to support FOREVER loops, FOR loops, etc. etc.)

I think it's a neat little thing for what it does.

IFVAR types:

CONST - using this allows you to put anything between this and a THEN
BOOL - specifies that the next word has to be either a TRUE or FALSE
VAR - using this allows you to compare one variable to another.

the commands (in their current state):

i. control flow/program control:

SUB [func name] - declares a function. requires a title declared by a string.
IFVAR [variable being compared] [an operator ==, >=, <=, ~=] [a type, see above] [see above for what to put here] THEN - performs an IF THEN statement. if there is an ELSE, it will do that if the condition fails.
PLAYSND [a sound name] - plays a sound with the name given. if it cannot find a sound with that name, it will throw an error at runtime.
BROADCAST [event to broadcast] (AND WAIT) - broadcasts an event, if it is told to wait, it will halt execution until all receivers of that event are finished executing.
WAIT [time to wait for] - waits for the specified amount of time, in seconds.
RESETTIMER - resets the timer.
JUMP [sub name] - runs a function specified. does not return to the previous context.
CALL [sub name] - calls a function, then resumes continuation after that function is done executing.

ii. story commands:

PUSHMSG [LEFT/RIGHT] [a message, in the form of a string.] (AND CHOOSE) - pushes a message to the message stack. for AND CHOOSE, see CHOOSE.
PUSHCHOICE [choice text] [choice id] - pushes a choice to the stack to be displayed when CHOOSE is called.
CHOOSE - one of the most important commands, it displays the messages and the choices that have been added to the stack. when the user clicks a choice, it will set a variable %choice% to the ID of the choice that they clicked.
DISPLAYMESSAGES - displays the messages without the choice dialogue.
SETTITLE [a string] - sets the title of the game (seen at the top of the stage), to the string specified.
CLEARCHAT - clears the chat, does not display anything.

iii. variable controls:

VAR [SET/CHANGE] [a variable name, variable format] [TO/BY] [a string acts like the CONST] - sets/changes a variable to/by an amount.
DECL [global/script/sprite] [a variable name, string] - declares a variable to either the current scope, the sprite scope, the global scope.
LET [variable name] BE [a value, anything can be put here] - declares a temporary variable with specified variable name, that can be any value.

maybe later ill elaborate on how the compiler works, however i think there is a block for that located in control literally called "docs"

Interesting. You might be interested in my BASIC to Logo compiler from long ago, which uses a similar strategy.

i did post this before, didn't you reply to that at one point?

also, looking back on it, some of the commands were explained poorly.

You expect me to remember what I replied to? I'm an old man. :~/

good point.

the compiler has changed a lot since i wrote the "docs" block. it still uses the same strategy as it did originally, just some things are a little different.

also, neat article! :slight_smile:

Thanks!