PyBasic
PyBasic copied to clipboard
Execute Files Directly
Hello! I wanted to add a scirpt to the repo to allow directly running .bas files without having to interact with the REPL. I'd like to be able to use PyBasic on embedded devices and this would be a requirement to be able to invoke the interpreter without user input.
Here is sample code to do this located in run.py
Let me know if I can open a PR to add this functionality.
Thanks for reading!
import argparse
from lexer import Lexer
from program import Program
def main():
"""
Main function to run the BASIC interpreter.
"""
parser = argparse.ArgumentParser(description="BASIC Interpreter")
parser.add_argument("filename", help="Name of the BASIC program file to load and execute")
args = parser.parse_args()
lexer = Lexer()
program = Program()
try:
program.load(args.filename)
program.execute()
except Exception as e:
print("An error occurred:", e)
if __name__ == "__main__":
main()
Apologies @zakerytclarke, I know I haven’t responded to this yet. Got a lot on at the moment, please bear with me
Getting back to this, admittedly after a few months. I'm not actively supporting this project any more and my main aim was to recreate the experience of an old school home computer. I'm not quite sure how to fit what you want into the codebase without muddying things a bit, so I suggest that you fork the repo and do your thing!