From a529b6e3f6662e06a580541d2b21f57770cdb30f Mon Sep 17 00:00:00 2001 From: Eatswap Date: Sun, 11 Dec 2022 20:20:49 +0800 Subject: [PATCH] fix: specify start, allow parse file as cmd arg --- DragonLisp.y | 2 ++ DragonLispDriver.cpp | 4 +++- main.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/DragonLisp.y b/DragonLisp.y index 2a5f8e0..e937c93 100644 --- a/DragonLisp.y +++ b/DragonLisp.y @@ -96,6 +96,8 @@ namespace DragonLisp { %define parse.error verbose +%start S + %% S diff --git a/DragonLispDriver.cpp b/DragonLispDriver.cpp index aba1dc1..6fc9488 100644 --- a/DragonLispDriver.cpp +++ b/DragonLispDriver.cpp @@ -14,8 +14,10 @@ DLDriver::~DLDriver() { int DLDriver::parse(const std::string& f) { std::ifstream in(f); - if (!in.good()) + if (!in.good()) { + std::printf("Could not open file %s\n", f.c_str()); return 1; + } return this->parse(in, f); } diff --git a/main.cpp b/main.cpp index 48997e1..42a62b9 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,9 @@ #include "DragonLispDriver.hh" -int main() { +int main(int argc, char** argv) { DragonLisp::DLDriver driver; - return driver.parse(std::cin); + if (argc <= 1) + return driver.parse(std::cin); + return driver.parse(argv[1]); }