-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathyolang.cpp
More file actions
51 lines (48 loc) · 2.04 KB
/
yolang.cpp
File metadata and controls
51 lines (48 loc) · 2.04 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
#include <iostream>
#include "offical_ysh/ysh.h"
using std::cout;
using std::endl;
int main(int argc, char *argv[]){
ysh_offical::YolangShellOffical ysh;
ysh.front.setupVM();
try{
if(argc == 1) yvm::start(&ysh);
else{
if(argc > 1 && argc <= 2) {
std::string arg1 = std::string(argv[1]);
if(arg1 == "--version" || arg1 == "-v");
else if(arg1 == "--help" || arg1 == "-h") {
cout<<"Yolang parameter help"<<endl;
cout<<"--version\t-v ................. Get the current version of Yolang"<<endl;
cout<<"--help \t-h ................. Get help with command line arguments"<<endl;
cout<<"--run <file> ................. Run the yolang file named 'file'"<<endl;
}
}
else if(argc > 2 && argc <= 3) {
std::string arg1 = std::string(argv[1]);
std::string arg2 = std::string(argv[2]);
if(arg1 == "--run") {
auto name = arg2;
if(yvm::tools::compareFileType(name, ".yo")){
std::ifstream file(name);
std::istreambuf_iterator<char> begin(file);
std::istreambuf_iterator<char> end;
std::string str(begin, end);
auto tg = ysh.makeTokenGroup(str);
ysh.yparser = parser::Parser(tg);
auto stmts = ysh.yparser.parse();
ygen::byteCodeGenerator bcg;
bcg.visit(stmts);
ysh.front.resetVM(bcg.getCodes(), bcg.getConstPool());
ysh.front.setupVM().runVM("program").clearVM().setupVM();
}
else
throw yoexception::YoError("FileError", "Not any file that can be run", -1, -1);
}
}
}
}
catch(yoexception::YoError e){
cout<<e.what()<<endl;
}
}