1+ #ifndef _WIN64
2+
3+ void file_run (char * _fileName) {
4+
5+ STR input_;
6+ std::string u8input;
7+ std::string line;
8+
9+ std::ifstream fileContent (_fileName);
10+ if (!fileContent.is_open ()) {
11+ prnt (L" لا يمكن فتح الملف او انه غير موجود - تاكد من اسم الملف -" );
12+ exit (-1 );
13+ }
14+
15+ while (std::getline (fileContent, line))
16+ {
17+ if (line != " " and line != " \r " )
18+ {
19+ u8input += line;
20+ u8input += " \n " ;
21+ }
22+ }
23+ fileContent.close ();
24+
25+ int fnLength = sizeof (_fileName) / sizeof (char ) + 6 ;
26+ STR fileName (&_fileName[0 ], &_fileName[fnLength]); // تحويل من char الى wchar_t
27+
28+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >, wchar_t > convert;
29+ /*
30+ تحويل utf-8
31+ الى utf-16
32+ لكي يقوم بحساب الحرف الواحد على انه 2 بايت وليس 1 بايت
33+ حيث نظام utf-8 يأخذ اول بايت من الحرف فقط ويترك البايت الثاني
34+ ** يجب مراجعة جدول بايتات نظام utf-8
35+ */
36+ input_ = convert.from_bytes (u8input);
37+
38+ // المعرب اللغوي
39+ // ///////////////////////////////////////////////////////////////
40+
41+ Lexer lexer (fileName, input_);
42+ lexer.make_token ();
43+
44+ // المحلل اللغوي
45+ // ///////////////////////////////////////////////////////////////
46+
47+ Parser parser = Parser (&lexer.tokens_ , fileName, input_);
48+ parser.parse_file ();
49+ }
50+
51+ void terminal_run () {
52+
53+ STR fileName = L" <طرفية>" ;
54+ const STR about_ = L" ألف نـ5.0.0" ;
55+ STR input_;
56+ prnt (about_);
57+
58+ while (true ) {
59+
60+ std::wcout << L" ألف -> " ;
61+ std::getline (std::wcin, input_);
62+
63+ if (input_ == L" خروج" )
64+ {
65+ exit (0 );
66+ }
67+
68+ // المعرب اللغوي
69+ // ///////////////////////////////////////////////////////////////
70+
71+ Lexer lexer (fileName, input_);
72+ lexer.make_token ();
73+
74+ // المحلل اللغوي
75+ // ///////////////////////////////////////////////////////////////
76+
77+ Parser parser = Parser (&lexer.tokens_ , fileName, input_);
78+ parser.parse_terminal ();
79+
80+ // std::wcin.ignore(); // لمنع ارسال قيمة فارغة في المتغير input_
81+
82+
83+ }
84+ }
85+
86+ #else
87+
188std::wstring utf8_decode (const std::string& str)
289{
90+ /*
91+ تحويل utf-8
92+ الى utf-16
93+ لكي يقوم بحساب الحرف الواحد على انه 2 بايت وليس 1 بايت
94+ حيث نظام utf-8 يأخذ اول بايت من الحرف فقط ويترك البايت الثاني
95+ ** يجب مراجعة جدول بايتات نظام utf-8
96+ */
397 int size_ = MultiByteToWideChar (CP_UTF8, 0 , &str[0 ], (int )str.size (), NULL , 0 );
498 std::wstring strToWstr (size_, 0 );
599 MultiByteToWideChar (CP_UTF8, 0 , &str[0 ], (int )str.size (), &strToWstr[0 ], size_);
@@ -21,8 +115,6 @@ void file_run(wchar_t* _fileName) {
21115 std::string line;
22116
23117 std::ifstream fileContent (_fileName);
24- // std::ifstream fileContent(L"../source/AlifCode.alif5"); // للتجربة فقط
25- // _fileName = new wchar_t(L'test'); // للتجربة فقط
26118 if (!fileContent.is_open ()) {
27119 prnt (L" لا يمكن فتح الملف او انه غير موجود - تاكد من اسم الملف -" );
28120 exit (-1 );
@@ -90,10 +182,6 @@ void terminal_run() {
90182 Parser parser = Parser (&lexer.tokens_ , fileName, input_);
91183 parser.parse_terminal ();
92184
93- #ifndef _WIN64
94- std::wcin.ignore (); // لمنع ارسال قيمة فارغة في المتغير input_
95- #endif // !_WIN64
96-
97-
98185 }
99- }
186+ }
187+ #endif // !_WIN64
0 commit comments