-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
53 lines (35 loc) · 1.06 KB
/
main.cpp
File metadata and controls
53 lines (35 loc) · 1.06 KB
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
46
47
48
49
50
51
52
53
#include <iostream>
#include<fstream>
#include <vector>
#include "parser.hpp"
#include "tokenizer.hpp"
#include "codegen.hpp"
using namespace std;
int main(int argc,char *argv[]){
string cmd;
Tokenizer tokenizer;
Parser parser;
//Activate myscript command line
if(argc == 1)
while(true){
cout <<"xxxscript verson 0.0.0\n"<<"This is xxxscript command line.\n";
cout << "Type 'exit' or press 'Ctrl + c' to end this command line."<<std::endl;
cout <<">>";
cin >> cmd;
if(cmd == "exit")
exit(1);
}
// Load myscript file
ifstream ifs(argv[1]);
if(ifs.fail()){
cerr << "Error : Failed to open file "<<argv[1]<<endl;
return -1;
}
string input = string(istreambuf_iterator<char>(ifs),istreambuf_iterator<char>());
//Tokenize file content
vector<Token> tokens = tokenizer.tokenize(input.c_str());
//Parse token
vector<Node*> nodes = parser.parse(tokens);
codegen(nodes);
return 0;
}