fix: specify start, allow parse file as cmd arg

This commit is contained in:
Eatswap 2022-12-11 20:20:49 +08:00
parent 7f11aaf21e
commit a529b6e3f6
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
3 changed files with 9 additions and 3 deletions

View File

@ -96,6 +96,8 @@ namespace DragonLisp {
%define parse.error verbose %define parse.error verbose
%start S
%% %%
S S

View File

@ -14,8 +14,10 @@ DLDriver::~DLDriver() {
int DLDriver::parse(const std::string& f) { int DLDriver::parse(const std::string& f) {
std::ifstream in(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 1;
}
return this->parse(in, f); return this->parse(in, f);
} }

View File

@ -2,7 +2,9 @@
#include "DragonLispDriver.hh" #include "DragonLispDriver.hh"
int main() { int main(int argc, char** argv) {
DragonLisp::DLDriver driver; DragonLisp::DLDriver driver;
if (argc <= 1)
return driver.parse(std::cin); return driver.parse(std::cin);
return driver.parse(argv[1]);
} }