-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
65 lines (55 loc) · 1.85 KB
/
main.cpp
File metadata and controls
65 lines (55 loc) · 1.85 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
#include <iostream>
#include <fstream>
#include <string>
#include <locale>
#include <codecvt>
#include "lexer.h"
#include "parser.h"
#include "interpreter.h"
void printUsage() {
std::cout << "Kullanım: ./feyz <dosya.feyz>" << std::endl;
}
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cout << "Hata: Dosya adı belirtilmedi." << std::endl;
printUsage();
return 1;
}
std::string filename = argv[1];
std::ifstream file(filename);
if (!file.is_open()) {
std::cout << "Hata: '" << filename << "' dosyası açılamadı." << std::endl;
return 1;
}
// UTF-8 dosyasını oku
std::string sourceCode((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
file.close();
// UTF-8 karakter setini kullan
try {
// Türkçe locale'i ayarla
std::locale::global(std::locale("tr_TR.UTF-8"));
} catch (const std::exception& e) {
// Eğer tr_TR.UTF-8 bulunamazsa, varsayılan locale'i kullan
std::locale::global(std::locale(""));
std::cerr << "Uyarı: Türkçe locale yüklenemedi, varsayılan locale kullanılıyor." << std::endl;
}
std::ios_base::sync_with_stdio(false);
std::cout.imbue(std::locale());
std::cerr.imbue(std::locale());
try {
// Lexer ile kaynak kodu token'lara ayır
Lexer lexer(sourceCode);
std::vector<Token> tokens = lexer.tokenize();
// Parser ile token'ları AST'ye çevir
Parser parser(tokens);
std::unique_ptr<ProgramNode> ast = parser.parse();
// Interpreter ile AST'yi yorumla ve çalıştır
Interpreter interpreter;
interpreter.interpret(ast.get());
} catch (const std::exception& e) {
std::cerr << "Hata: " << e.what() << std::endl;
return 1;
}
return 0;
}