MethodsDevelopmentTranslator
/
TranslatorFromCToCSharp.cpp
89 строк · 2.6 Кб
1#include "TranslatorFromCToCSharp.h"
2using namespace System;
3
4TranslatorFromCToCSharp::TranslatorFromCToCSharp()
5{
6}
7
8TranslatorFromCToCSharp::~TranslatorFromCToCSharp()
9{
10}
11
12//System::String^ StlWStringToString(std::string const& os)
13//{
14// System::String^ str = gcnew System::String(os.c_str());
15// //String^ str = gcnew String("");
16// return str;
17//}
18
19void TranslatorFromCToCSharp::lexicalAnalyze(std::string source_file)
20{
21
22try
23{
24makeLexicalAnalyze(source_file, "./translator_file/lexical.txt");
25lexicalAnalyzeIsCompleted = true;
26}
27catch (const std::exception&)
28{
29System::Windows::Forms::MessageBox::Show("Problem with lexical analyze", "Error", System::Windows::Forms::MessageBoxButtons::OK, System::Windows::Forms::MessageBoxIcon::Error);
30lexicalAnalyzeIsCompleted = false;
31}
32
33}
34
35void TranslatorFromCToCSharp::reversePolishNotAnalyze()
36{
37try
38{
39if (lexicalAnalyzeIsCompleted == true)
40reversePolishNotationAnalyze("./translator_file/lexical.txt", "./translator_file/RPN.txt");
41else
42{
43System::Windows::Forms::MessageBox::Show("LexicalAnaylyze don't completed!", "Error", System::Windows::Forms::MessageBoxButtons::OK, System::Windows::Forms::MessageBoxIcon::Error);
44return;
45}
46
47reversePolishNotationIsCompleted = true;
48}
49catch (const std::exception&)
50{
51System::Windows::Forms::MessageBox::Show("Problem with RPN analyze", "Error", System::Windows::Forms::MessageBoxButtons::OK, System::Windows::Forms::MessageBoxIcon::Error);
52reversePolishNotationIsCompleted = false;
53}
54}
55
56bool TranslatorFromCToCSharp::syntaxAnalyze()
57{
58try
59{
60syntaxAnalyzeIsCompleted = makeSyntaxAnalyze();
61return syntaxAnalyzeIsCompleted;
62}
63catch (const std::exception&)
64{
65System::Windows::Forms::MessageBox::Show("Problem with syntax analyze!", "Error", System::Windows::Forms::MessageBoxButtons::OK, System::Windows::Forms::MessageBoxIcon::Error);
66syntaxAnalyzeIsCompleted = false;
67}
68}
69
70void TranslatorFromCToCSharp::translateToCSharp()
71{
72try
73{
74if (reversePolishNotationIsCompleted == true && syntaxAnalyzeIsCompleted == true)
75{
76transalteToCSharp("./translator_file/RPN.txt", "./translator_file/CodeCSharp.cs");
77}
78else
79{
80System::Windows::Forms::MessageBox::Show("Don't execution RPN || syntax analyze!", "Error", System::Windows::Forms::MessageBoxButtons::OK, System::Windows::Forms::MessageBoxIcon::Error);
81return;
82}
83}
84catch (std::string err)
85{
86System::Windows::Forms::MessageBox::Show("Problem with translate to C# program!" + StlWStringToString(err), "Error", System::Windows::Forms::MessageBoxButtons::OK, System::Windows::Forms::MessageBoxIcon::Error);
87}
88
89}