-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (73 loc) · 1.42 KB
/
main.cpp
File metadata and controls
77 lines (73 loc) · 1.42 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <Windows.h>
#include <fstream>
#include "checkers.h"
#include "lexer.h"
#include "parser.h"
using namespace std;
template<class T>
wostream& operator<<(wostream& os, const vector<T>& vec)
{
os << "{";
if (vec.size() == 1)
{
os << *(vec.begin());
}
else if (vec.size() == 2)
{
os << *(vec.begin()) << ", " << *(vec.begin() + 1);
}
else if (vec.size() > 2)
{
for (auto iter = vec.begin(); iter != vec.end() - 1; iter++)
{
os << *iter << ", ";
}
os << *(vec.end() - 1);
}
os << "}";
return os;
}
wostream& operator<<(wostream& os, const Token& token)
{
os << token.type << " : " << token.value << endl;
return os;
}
int main(int argc, char *argv[])
{
if (argc == 1)
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
wcout << L"Welcome to SimpleScript!\nLet's write this code!\n";
while (true)
{
wcout << ">>> ";
wchar_t in[256];
wcin.getline(in, 256);
vector<Token> tokens = tokenize(in + wstring(L" \n"));
wcout << tokens << endl;
wcout << endl;
}
}
else
{
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
wifstream out(argv[1]);
vector<wstring> temp_vec;
wstring temp;
wstring str = L"";
while (getline(out, temp, L'\n'))
{
temp_vec.push_back(temp);
}
for (wstring temp : temp_vec)
{
str += temp + L"\n";
}
vector<Token> tokens = tokenize(str);
wcout << tokens << endl;
wcout << L"END OF TOKENS" << endl << endl;
system("pause");
}
}