Skip to content

Commit 49afa39

Browse files
#TDP - 21 Realize class Translate to C#
printf->Console.WriteLine I,N,W,C -> get name (method)
1 parent eb019d2 commit 49afa39

15 files changed

+380
-283
lines changed

CodeCSharp.txt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,52 @@ using System;
44
{
55
class Program
66
{
7-
//W8 I1
8-
//W8 I2
9-
public int I3 (int I4)
7+
//#include "stdio.h"
8+
//#include <malloc.h>
9+
public int sizeNumber(int num)
1010
{
11-
int I5 = N1;
12-
while(I4 != N1)
11+
int count = 0;
12+
while(num != 0)
1313
{
14-
I4 = I4 / N2;
15-
I5++ ;
14+
num = num / 10;
15+
count++ ;
1616
}
17-
W11 I5;
17+
return count;
1818
}
1919
/*test comment*/
20-
public int I6 (int I4)
20+
public int setDigitNumber(int num)
2121
{
22-
int I7 = I3(I4);
23-
int* I8 = (int*)W9(I7 * W10(int));
24-
int I9 = N1;
25-
while(I4 != N1)
22+
int size = sizeNumber(num);
23+
int* digits = (int*)malloc(size * sizeof(int));
24+
int index = 0;
25+
while(num != 0)
2626
{
27-
I8[I9] = I4 % N2;
28-
I4 /= N2;
29-
I9++ ;
27+
digits[index] = num % 10;
28+
num /= 10;
29+
index++ ;
3030
}
31-
W11 I8;
31+
return digits;
3232
}
3333
// Main
3434
/* double
3535
comment
3636
*/
3737
static void Main(string[] args)
3838
{
39-
int I7 = I3(N3);
40-
int* I12 = I6(N3);
41-
int I13 = N1;
42-
for(int I14 = N1 ;I14 < I7 ;I14++)
39+
int size = sizeNumber(36);
40+
int* digitsNumber = setDigitNumber(36);
41+
int sum7Digit7 = 0;
42+
for(int i = 0 ;i < size ;i++)
4343
{
44-
if(I14 < N4 && I14 > N1)
44+
if(i < 100 && i > 0)
4545
{
46-
I15(C1,I14,I12[I14]) ;
46+
printf("array[%d] = %d \n",i,digitsNumber[i]) ;
4747
}
48-
I12[I14] += I13 ;
48+
sum7Digit7 += digitsNumber[i] ;
4949
}
50-
I15(C2,I13);
51-
I16(I12) ;
52-
W11 N1;
50+
printf("Summa digit: %d",sum7Digit7);
51+
free(digitsNumber);
52+
return 0;
5353
}
5454
}
5555
}

RPN.txt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1-
W8 I1
2-
W8 I2
1+
W8 I10
2+
W8 I11
33

4-
I3 1 int I4 1 int
4+
I3 1 int I12 1 int
55
1 1 ��
6-
I5 1 int N1 O5
7-
I4 N1 O10
6+
I13 1 int N1 O5
7+
I12 N1 O10
88
��1 ���
9-
I4 I4 N2 O4 O5
10-
I5 O20
9+
I12 I12 N3 O4 O5
10+
I13 O20
1111
��1:
12-
I5 W11
12+
I13 W11
1313
��
1414

1515
/*test comment*/
16-
I6 1 int I4 1 int
16+
I5 1 int I12 1 int
1717
2 1 ��
18-
I7 1 int I3 I4 2� O5
19-
I8 1 int* W9 I7 W10 1 int 2� O3 2� 1 int* O5
20-
I9 1 int N1 O5
21-
I4 N1 O10
18+
I2 1 int I3 I12 2� O5
19+
I14 1 int* W9 I2 W10 1 int 2� O3 2� 1 int* O5
20+
I15 1 int N1 O5
21+
I12 N1 O10
2222
��1 ���
23-
I8 I9 2��� I4 N2 O6 O5
24-
I4 N2 O13
25-
I9 O20
23+
I14 I15 2��� I12 N3 O6 O5
24+
I12 N3 O13
25+
I15 O20
2626
��1:
27-
I8 W11
27+
I14 W11
2828
��
2929

3030
// Main
3131
/* double
3232
comment
3333
*/
34-
W4 1 int I10 1 int I11 1��� 1 const char*
34+
W4 1 int I0 1 int I1 1��� 1 const char*
3535
3 1 ��
36-
I7 1 int I3 N3 2� O5
37-
I12 1 int* I6 N3 2� O5
38-
I13 1 int N1 O5
39-
I14 1 int N1 O5 I14 I7 O8 I14 O20
36+
I2 1 int I3 N0 2� O5
37+
I4 1 int* I5 N0 2� O5
38+
I6 1 int N1 O5
39+
I7 1 int N1 O5 I7 I2 O8 I7 O20
4040
���1 ���
41-
I14 N4 O8 I14 N1 O7 O17
41+
I7 N2 O8 I7 N1 O7 O17
4242
�1 ���
43-
I15 C1 I14 I12 I14 2��� 4�
43+
I8 C0 I7 I4 I7 2��� 4�
4444
�1:
45-
I13 I12 I14 2��� O14
45+
I6 I4 I7 2��� O14
4646
���1:
47-
I15 C2 I13 3�
48-
I16 I12 2�
47+
I8 C1 I6 3�
48+
I9 I4 2�
4949
N1 W11
5050
��
5151

ReversePolishNotation.cpp

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,6 @@ bool ReversePolishNotation::isFunctionDeclaration(std::string line)
4545
}
4646
return false;
4747
}
48-
//bool ReversePolishNotation::isTypeDeclaration(std::string word)
49-
//{
50-
// return word=="W1" || word=="W2" || word=="W3" || word=="W14" || word == "W15" || word == "W16" || word == "W17" ||
51-
// word=="W18" || word=="W19" || word=="W13" || word == "W19 W1"
52-
// || word == "W19 W2" || word == "W19 W3" || word == "W19 W17" || word == "W19 W18" || word == "W19 W16" || word == "W19 W15" ? true : false;
53-
//}
54-
//bool ReversePolishNotation::isCycle(std::string word)
55-
//{
56-
// return word == "W7" || word == "W12" ? true : false;
57-
//}
58-
//
59-
//bool ReversePolishNotation::isIFCondition(std::string word)
60-
//{
61-
// return word == "W5" ? true : false;
62-
//}
63-
//bool ReversePolishNotation::isELSECondition(std::string word)
64-
//{
65-
// return word == "W6" ? true : false;
66-
//}
6748

6849
bool ReversePolishNotation::upElemNotNameExpression(std::string upElem)
6950
{
@@ -109,44 +90,6 @@ size_t ReversePolishNotation::positionTypeConversion(std::string line)
10990
return -1;
11091
}
11192

112-
std::string ReversePolishNotation::nameType(std::string token)
113-
{
114-
if (token == "W1")
115-
return "int";
116-
if (token == "W2")
117-
return "float";
118-
if (token == "W3")
119-
return "char";
120-
if (token == "W14")
121-
return "double";
122-
if (token == "W15")
123-
return "int*";
124-
if (token == "W16")
125-
return "float*";
126-
if (token == "W17")
127-
return "double*";
128-
if (token == "W18")
129-
return "char*";
130-
if (token == "W19 W1")
131-
return "const int";
132-
if (token == "W19 W2")
133-
return "const float";
134-
if (token == "W19 W3")
135-
return "const char";
136-
if (token == "W19 W14")
137-
return "const double";
138-
if (token == "W19 W15")
139-
return "const int*";
140-
if (token == "W19 W16")
141-
return "const float*";
142-
if (token == "W19 W17")
143-
return "const double*";
144-
if (token == "W19 W18")
145-
return "const char*";
146-
return "";
147-
}
148-
149-
15093
void ReversePolishNotation::reversePolishNotationAnalyze(std::string fileName_lexical, std::string fileName_RPN)
15194
{
15295
std::ifstream lexical;
@@ -307,7 +250,7 @@ void ReversePolishNotation::reversePolishNotationAnalyze(std::string fileName_le
307250
auto upElemStack = stack.back().rbegin();
308251
if (upElemStack->first == "PROC")
309252
{
310-
fileAnalysis << intToStr(upElemStack->second) << " ÍÏ" << " ";
253+
fileAnalysis << intToStrWithSpace(upElemStack->second) << " ÍÏ" << " ";
311254
continue;
312255
}
313256
if (isIFCondition(upElemStack->first) == true)
@@ -369,7 +312,7 @@ void ReversePolishNotation::reversePolishNotationAnalyze(std::string fileName_le
369312
{
370313
stack.pop_back();
371314
upElemStack = stack.back().rbegin();
372-
fileAnalysis << intToStr(upElemStack->second) << " ÊÎ";
315+
fileAnalysis << intToStrWithSpace(upElemStack->second) << " ÊÎ";
373316
}
374317
if (stack.size() != 0 && isFor==false && lastCommndIFFORWHILE_withoutTHEN.find("End") != std::string::npos)
375318
{
@@ -660,4 +603,3 @@ void ReversePolishNotation::reversePolishNotationAnalyze(std::string fileName_le
660603
lexical.close();
661604
fileAnalysis.close();
662605
}
663-

ReversePolishNotation.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ class ReversePolishNotation : public Translator
1515
mystack stack;
1616
int getPriority(std::string word);
1717
bool isFunctionDeclaration(std::string line);
18-
/*bool isTypeDeclaration(std::string word);
19-
bool isCycle(std::string word);
20-
bool isIFCondition(std::string word);
21-
bool isELSECondition(std::string word);*/
22-
std::string nameType(std::string token);
2318
bool isExistsComma(std::string line);
2419
size_t positionTypeConversion(std::string line);
2520
bool upElemNotNameExpression(std::string upElem);

SyntaxAnalisator.cpp

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ SyntaxAnalisator::~SyntaxAnalisator()
1111
{
1212
}
1313

14-
System::String^ StlWStringToString(std::string const& os)
15-
{
16-
System::String^ str = gcnew System::String(os.c_str());
17-
//String^ str = gcnew String("");
18-
return str;
19-
}
14+
2015

2116
std::string SyntaxAnalisator::getServiceWordCode(std::string str)
2217
{
@@ -66,40 +61,22 @@ std::string SyntaxAnalisator::getSymbolsConstCode(std::string str)
6661
return "\0";
6762
}
6863

64+
System::String^ StlWStringToString(std::string const& os)
65+
{
66+
System::String^ str = gcnew System::String(os.c_str());
67+
//String^ str = gcnew String("");
68+
return str;
69+
}
6970

70-
void SyntaxAnalisator::addCode(std::string str, std::map<std::string, std::string> & table, int numTable)
71+
void SyntaxAnalisator::addCode(std::string str, std::map<std::string, std::string>& table, int numTable)
7172
{
72-
int indexCode = 0;
73-
for (const auto& word : table)
74-
{
75-
indexCode++;
76-
}
77-
indexCode++;
78-
if (numTable == 1)
79-
{
80-
if(isIdentifier(str)==true)
81-
table.insert(std::pair<std::string, std::string>(str, "I" + std::to_string(indexCode)));
82-
else
83-
{
84-
85-
System::String^ temp = StlWStringToString(str);
86-
System::Windows::Forms::MessageBox::Show("Error with identifier", temp, System::Windows::Forms::MessageBoxButtons::OK, System::Windows::Forms::MessageBoxIcon::Error);
87-
return;
88-
}
89-
}
90-
if (numTable == 2)
73+
std::string result = fillTable(str, table, numTable);
74+
if (result.find("Error") != std::string::npos)
9175
{
92-
if(isNumber(str)==true)
93-
table.insert(std::pair<std::string, std::string>(str, "N" + std::to_string(indexCode)));
94-
else
95-
{
96-
System::String^ temp = StlWStringToString(str);
97-
System::Windows::Forms::MessageBox::Show("Error with number", temp, System::Windows::Forms::MessageBoxButtons::OK, System::Windows::Forms::MessageBoxIcon::Error);
98-
return;
99-
}
76+
System::String^ temp = StlWStringToString(str);
77+
System::String^ tempResult = StlWStringToString(result);
78+
System::Windows::Forms::MessageBox::Show(tempResult, temp, System::Windows::Forms::MessageBoxButtons::OK, System::Windows::Forms::MessageBoxIcon::Error);
10079
}
101-
if (numTable == 3)
102-
table.insert(std::pair<std::string, std::string>(str, "C" + std::to_string(indexCode)));
10380
}
10481

10582
int SyntaxAnalisator::checkStringSingleElem(std::string const& word)
@@ -190,7 +167,7 @@ bool SyntaxAnalisator::skipAnalyzeOneLineComment(bool readComment, std::string l
190167
return false;
191168
}
192169

193-
bool skipAnalyzeComment(bool& readComment, std::string line, __int64& index, std::ofstream& file, std::string& word)
170+
bool SyntaxAnalisator::skipAnalyzeComment(bool& readComment, std::string line, __int64& index, std::ofstream& file, std::string& word)
194171
{
195172
if (readComment == true && isComment((int)line[index + 1], (int)line[index]) == true)
196173
{
@@ -205,7 +182,10 @@ bool skipAnalyzeComment(bool& readComment, std::string line, __int64& index, std
205182
}
206183
return false;
207184
}
208-
185+
bool SyntaxAnalisator::isLibrary_header(std::string const& word)
186+
{
187+
return (int)word[0] == 34 && (int)word[word.length() - 1] == 34 && (int)word[word.length() - 2] == 104 && (int)word[word.length() - 3] == 46 ? true : false;
188+
}
209189

210190
void SyntaxAnalisator::analyze(std::string filePathOrName_C, std::string fileName_Path_SaveAnalis)
211191
{
@@ -304,7 +284,7 @@ void SyntaxAnalisator::analyze(std::string filePathOrName_C, std::string fileNam
304284
if (isLetter((int)stringLanguageC[i]) == true && (isLetter((int)stringLanguageC[i + 1]) == false && isDigit((int)stringLanguageC[i + 1]) == false))
305285
{
306286
word += stringLanguageC[i];
307-
if (isType(word) && (stringLanguageC[i + 1] == '*' || stringLanguageC[i + 2] == '*'))
287+
if (isTypeDeclaration(word) && (stringLanguageC[i + 1] == '*' || stringLanguageC[i + 2] == '*'))
308288
{
309289
word += '*';
310290
if (stringLanguageC[i + 2] == '*')
@@ -366,4 +346,10 @@ void SyntaxAnalisator::analyze(std::string filePathOrName_C, std::string fileNam
366346

367347
fileC.close();
368348
fileAnalysis.close();
369-
}
349+
}
350+
351+
void SyntaxAnalisator::initialize()
352+
{
353+
}
354+
355+

0 commit comments

Comments
 (0)