From 342f6c1c2143c7639514d402c6a8e7ba0a8682e8 Mon Sep 17 00:00:00 2001 From: Alvin <524715@vistacollege.nl> Date: Tue, 22 Jul 2025 18:32:34 +0200 Subject: [PATCH] feat: Update main.py to accept file path as command-line argument --- src/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index e205f27..3747df7 100644 --- a/src/main.py +++ b/src/main.py @@ -1,10 +1,20 @@ +import sys from lexer import Lexer from parser import Parser from interpreter import Interpreter def main(): - with open('../examples/variables.fem', 'r') as f: - text = f.read() + if len(sys.argv) < 2: + print("Usage: python3 main.py ") + sys.exit(1) + + file_path = sys.argv[1] + try: + with open(file_path, 'r') as f: + text = f.read() + except FileNotFoundError: + print(f"Error: File not found: {file_path}") + sys.exit(1) lexer = Lexer(text) tokens = lexer.tokenize()