blob: eda37143c321fdb063680e5472053a90e07e987a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "runtime.h"
using namespace std;
int g_argc;
char **g_argv;
string readfile(ifstream stream){
stream.seekg(0,ios::end);
size_t len=stream.tellg();
stream.seekg(0,ios::beg);
string contents;
contents.resize(len);
stream.read(&*contents.begin(),len);
return contents;
}
int main(int argc,char **argv){
if(argc<2){
cerr<<"Call this interpreter with the Postrun source file"<<endl;
return 1;
}
g_argc=argc-2;
g_argv=argv+2; //skip this executable and the postrun file
ifstream srcf(argv[1]);
if(!srcf){
cerr<<"Could not open file '"<<argv[1]<<"'"<<endl;
return 1;
}
//string source=readfile(srcf);
try {
const vector<string> tokens=tokenise(srcf);
//for(const string &tok : tokens)cerr<<'['<<tok<<"] "; cerr<<endl;
run(tokens);
srcf.close();
} catch(string e){
cerr<<"ERROR: "<<e<<endl;
return 1;
}
}
|