diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
@@ -1,11 +1,48 @@ #include <iostream> +#include <fstream> +#include <cstring> #include "parser.h" using namespace std; +string readstream(istream &in){ + string res; + char buf[4096]; + while(true){ + in.read(buf,sizeof(buf)); + if(in.gcount()==0)break; + res.append(buf,in.gcount()); + } + return res; +} + int main(int argc,char **argv){ - (void)argc; - (void)argv; + string source,filename; + bool fromstdin=false; + if(argc==1)fromstdin=true; + else if(argc==2){ + if(strcmp(argv[1],"-")==0)fromstdin=true; + else filename=argv[1]; + } else { + cerr<<"Pass source on stdin, or filename as argument (or '-' for stdin)"<<endl; + return 1; + } + if(fromstdin){ + source=readstream(cin); + filename="<stdin>"; + } else { + ifstream f(filename); + source=readstream(f); + } + + StatementList stl; + try { + stl=parse(source,filename); + } catch(ParseError e){ + cerr<<e.what()<<endl; + return 1; + } + cout<<stl<<endl; return 0; } |