stupidBASIC
stupidBASIC is an interpreted stupid programming language that is part of the stupid programming language family. It is syntactically similar to BASIC dialects, but operates similar to Asparagus assembly.
Syntax
stupidBASIC has a very basic syntax structure;
command [argument]
...where command
is the first non-space character up until the next space character, and argument
is the rest of the line. Unlike any other programming language in the stupid family, stupidBASIC does not remove whitespace characters, so this means that store this is a variable
is actually different from store thisisavariable
.[1] When a variable or a number is needed, anything starting with a number will be treated as so, anything else will be treated as a variable.
Like Asparagus, variables in stupidBASIC are all treated as strings, and converted to numbers when needed. Unlike Asparagus, however, variables are not bound to a specific range; you can have as many variables as you want, each with unique names. They are automatically defined the first time they are used.
There is one "special" variable, the accumulator. This operates in the same way as practically any other language/bytecode with an accumulator; operations are done to it, then stored to a variable.
- Important note: Don't trust the accumulator to stay the same for long periods of time; certain commands can change it without you knowing!
Commands
Memory and I/O
load
loads a variable into the accumulator.store
stores the accumulator to a variable.set
sets the accumulator to a certain value.get
gets a "special" variable and puts the result in the accumulator. See Special Variables for more information.print
prints the accumulator to the screen, or ifnewline
is specified, then it prints a new line.say
prints text to the screen.ask
prompts the user with a string to input a value/string. The output is stored in the accumulator.newline
appends the accumulator with a new line, since there is no other way to do so.append
appends the accumulator.
Control and branching
if
executes the code inside the block, ending withend if
, if the accumulator is equal to the argument.ifeq
is an alias for this.ifne
runs the block if the two are not equal.iflt
runs the block if the accumulator is less than the argument.ifgt
runs the block if the accumulator is more than the argument.ifle
runs the block if the accumulator is less than or equal to the argument.ifge
runs the block if the accumulator is more than or equal to the argument.ifidk
runs the block if the interpreter feels like it.
loop
executes the code inside the block, ending withend loop
, continuously until anexit loop
is called.program
defines a routine with the code inside the block, ending withend program
, that can be called withdo [subroutine name]
.- If no value is specified, the code block is the default code block to run, much like
onreset
in stupidc ormain()
in C/C++.
- If no value is specified, the code block is the default code block to run, much like
end
defines the end of the block specified by the argument.- Possible values are
if
,loop
,program
, or blank. Note that using no argument can screw up the interpreter badly whenexit
is used with a specific block name.
- Possible values are
exit
exits out of a specified code block.- Possible values are
if
,loop
,program
, or blank. Leaving it blank just exits out of the current block. Note that usingend
with no argument can screw up the interpreter badly whenexit
is used with a specific block name.
- Possible values are
do
runs the corresponding code defined byprogram
, then returns.
Math
add
adds to the accumulator.subtract
subtracts from the accumulator.multiply
multiplies the accumulator. [2]divide
divides the accumulator. [2]modulo
does a modulo operation on the accumulator. [2]
Other
rem
is a comment.
Special Variables
Special variables are variables that can be accessed via the get
command. So far, there are five special variables:
random
generates a random floating-point number between 0-1.key
is the last key press since the last time it was called or the program started. If there are no keys in the buffer, it returns a blank string.key and wait
waits for a key press and then puts it in the accumulator.timer
is the time since the program started in seconds.time
is the time since midnight according to the computer's clock, in seconds.
Error catching
There are errors, and they occur more than I'd like to admit.
Moving on.
Sample programs
Hello, world!
program say Hello, world! end program
Cat
program get key and wait print end program
99 bottles of beer on the wall
program rem Initialize "count" set 99 store count rem Initialize "bottles" because it saves time rem Notice the two spaces in between "set" and "bottles." This ensures that the string starts with a leading space. set bottles of beer store bottles rem Main loop loop rem Print it once (with the little bit at the end too) load count print load bottles print say on the wall, print newline rem Print it twice, load count print load bottles print say . print newline say Take one down, pass it around, rem Decrement count load count subtract 1 rem When we're at the end... if 0 say There are no more bottles of beer on the wall! print newline exit program end if rem Otherwise... print store count load bottles print say . print newline end loop end program
Interpreter
The interpreter can be found at https://github.com/all-other-usernames-were-taken/stupidBASIC.