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
loadloads a variable into the accumulator.storestores the accumulator to a variable.setsets the accumulator to a certain value.getgets a "special" variable and puts the result in the accumulator. See Special Variables for more information.printprints the accumulator to the screen, or ifnewlineis specified, then it prints a new line.sayprints text to the screen.askprompts the user with a string to input a value/string. The output is stored in the accumulator.newlineappends the accumulator with a new line, since there is no other way to do so.appendappends the accumulator.
Control and branching
ifexecutes the code inside the block, ending withend if, if the accumulator is equal to the argument.ifeqis an alias for this.ifneruns the block if the two are not equal.ifltruns the block if the accumulator is less than the argument.ifgtruns the block if the accumulator is more than the argument.ifleruns the block if the accumulator is less than or equal to the argument.ifgeruns the block if the accumulator is more than or equal to the argument.ifidkruns the block if the interpreter feels like it.
loopexecutes the code inside the block, ending withend loop, continuously until anexit loopis called.programdefines 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
onresetin stupidc ormain()in C/C++.
- If no value is specified, the code block is the default code block to run, much like
enddefines 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 whenexitis used with a specific block name.
- Possible values are
exitexits 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 usingendwith no argument can screw up the interpreter badly whenexitis used with a specific block name.
- Possible values are
doruns the corresponding code defined byprogram, then returns.
Math
addadds to the accumulator.subtractsubtracts from the accumulator.multiplymultiplies the accumulator. [2]dividedivides the accumulator. [2]modulodoes a modulo operation on the accumulator. [2]
Other
remis a comment.
Special Variables
Special variables are variables that can be accessed via the get command. So far, there are five special variables:
randomgenerates a random floating-point number between 0-1.keyis 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 waitwaits for a key press and then puts it in the accumulator.timeris the time since the program started in seconds.timeis 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.