This code is meant for study only. And for fun as well. This is my first human readable programming language interpreter. The BASIC dialect was chosen just because it is kind of easy to implement.
This dialect works with integer numbers and supports only general BASIC commands, at the moment:
PRINT <string>/<expr>; ...
print text strings and/or expression resultsINPUT <string>; <var>
print prompt string and request number for inputGOTO <expr>
go to line, which number is evaluated as expressionGOSUB <expr>
go to subroutineRETURN
return from subroutineIF <expr> THEN <command>
if conditional expression is true, execute whatever command is afterLET <var> = <expr>
evaluate expression and store the result into variable. This operator is optional.END
stop executionSTOP
stop executionDIM <var> (<expr>)
declare an array
You can add comments to code by writing '
character at the beginning
of the line (after line number).
Order of operations is left-to-right, sequentual. If you wish to mark the order of calculations, use parenthesis. Keep this in mind, especially when writing conditionals, as all operators are treated equal.
In interactive mode you can:
RUN
run the entered programLIST
program's source codeNEW
clear the programSYSTEM
exit to OS
No comments:
SimpleBasic
Ok
10 PRINT "Hello, World!"
20 END
RUN
Hello, World!
Ok
Usually, when you write an interpreter or a compiler, you read the source code line by line and convert it to some internal representation (like AST) and only then you run it or translate to machine codes. For an interpreter you would have some sort of virtual machine implemented, apart from the parser. But here I decided to remove the unnecessary step and run the code directly from source! I guess this is bad, but it works, eh.
Tonns of them. But if it is something that does not stick out, I consider it a hidden feature.
GNU GPL v3