From 0b3eda5f5e94ffe85734a11bf56cc19bd582c9b2 Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Wed, 18 Sep 2024 10:38:49 +0800 Subject: [PATCH] Program execution by argument invocation list. --- src/Zhivo.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Zhivo.cpp b/src/Zhivo.cpp index b87914e..e4534a3 100644 --- a/src/Zhivo.cpp +++ b/src/Zhivo.cpp @@ -25,15 +25,22 @@ #include #include -auto interpreter() -> int { - SymbolTable symbols; +auto printBanner() -> void { + std::cout << "Zhivo Programming Language" << std::endl; +} +auto interpreter(int argc, char** argv) -> int { try { - Parser parser = Parser::fromFile("test.zhv"); - parser.parse(); + SymbolTable symbols; + + for(int i = 1; i < argc; i++) { + Parser parser = Parser::fromFile(argv[i]); + parser.parse(); + + for(const auto& statement : parser.getGlobalStatements()) + statement->visit(symbols); + } - for(const auto& statement : parser.getGlobalStatements()) - statement->visit(symbols); return 0; } catch(const LexicalAnalysisException& lexAnlExc) { @@ -71,6 +78,10 @@ auto interpreter() -> int { return 1; } -decltype(interpreter()) main() { - return interpreter(); +auto main(int argc, char** argv) -> int { + if(argc > 1) + return interpreter(argc, argv); + + printBanner(); + return 1; }