Skip to content

Commit 8c7b806

Browse files
#TDP - 22 End solution translate C#
add string block_function instead file record data in file record the end function ( КП->}) add method replace malloc add private string: name array in function (only 1 array!) name function return array (only 1array!) It's for add [] instead '*' in C in var array Example -> int * a = b; -> int[] a = b; int name(arg)-> static int[] name(arg) int* n = (int*)mallloc(..)->int[] n = new int[]
1 parent 49afa39 commit 8c7b806

File tree

8 files changed

+193
-83
lines changed

8 files changed

+193
-83
lines changed

CodeCSharp.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using System;
66
{
77
//#include "stdio.h"
88
//#include <malloc.h>
9-
public int sizeNumber(int num)
9+
static int sizeNumber(int num)
1010
{
1111
int count = 0;
1212
while(num != 0)
@@ -17,10 +17,10 @@ using System;
1717
return count;
1818
}
1919
/*test comment*/
20-
public int setDigitNumber(int num)
20+
static int[] setDigitNumber(int num)
2121
{
2222
int size = sizeNumber(num);
23-
int* digits = (int*)malloc(size * sizeof(int));
23+
int[] digits = new int[size];
2424
int index = 0;
2525
while(num != 0)
2626
{
@@ -37,19 +37,18 @@ comment
3737
static void Main(string[] args)
3838
{
3939
int size = sizeNumber(36);
40-
int* digitsNumber = setDigitNumber(36);
40+
int[] digitsNumber = setDigitNumber(36);
4141
int sum7Digit7 = 0;
4242
for(int i = 0 ;i < size ;i++)
4343
{
4444
if(i < 100 && i > 0)
4545
{
46-
printf("array[%d] = %d \n",i,digitsNumber[i]) ;
46+
Console.WriteLine("array[%d] = %d \n",i,digitsNumber[i]) ;
4747
}
4848
sum7Digit7 += digitsNumber[i] ;
4949
}
50-
printf("Summa digit: %d",sum7Digit7);
51-
free(digitsNumber);
52-
return 0;
50+
Console.WriteLine("Summa digit: %d",sum7Digit7);
51+
5352
}
5453
}
5554
}

RPN.txt

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
W8 I10
2-
W8 I11
1+
W8 I0
2+
W8 I1
33

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

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

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

5252

ReversePolishNotation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool ReversePolishNotation::isExistsComma(std::string line)
6363
}
6464
bool ReversePolishNotation::isBeginFunctionName(std::string word)
6565
{
66-
return word[0] == 'I' || word == "W9" || word == "W10" ? true : false;
66+
return word[0] == 'I' || word == "W9" || word == "W10" || word == "W20" ? true : false;
6767
}
6868

6969
bool ReversePolishNotation::isExistsFunctionExpression(std::vector<std::map<std::string, int>>& stack)

Translator.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Translator
1414
virtual std::map<std::string, std::string> getSymbols();
1515
virtual void initialize(std::map<std::string, std::string> identifier, std::map<std::string, std::string> numberConst, std::map<std::string, std::string> symbolsConst);
1616
protected:
17-
#define SIZE_serviceWord 19
17+
#define SIZE_serviceWord 20
1818
#define SIZE_separators 9
1919
#define SIZE_operation 20
2020
#define SIZE_columns 2
@@ -38,7 +38,8 @@ class Translator
3838
{"float*","W16"},
3939
{"double*","W17"},
4040
{"char*","W18"},
41-
{"const","W19"}
41+
{"const","W19"},
42+
{"free","W20"}
4243
};
4344
std::string const separators[SIZE_separators][SIZE_columns] =
4445
{

lexical.txt

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
W8 I10
2-
W8 I11
1+
W8 I0
2+
W8 I1
33

4-
W1 I3 R3 W1 I12 R4
4+
W1 I2 R3 W1 I3 R4
55
R5
6-
W1 I13 O5 N1 R7
7-
W7 R3 I12 O10 N1 R4
6+
W1 I4 O5 N0 R7
7+
W7 R3 I3 O10 N0 R4
88
R5
9-
I12 O5 I12 O4 N3 R7
10-
I13 O20 R7
9+
I3 O5 I3 O4 N1 R7
10+
I4 O20 R7
1111
R6
12-
W11 I13 R7
12+
W11 I4 R7
1313
R6
1414
/*test comment*/
15-
W1 I5 R3 W1 I12 R4
15+
W1 I5 R3 W1 I3 R4
1616
R5
17-
W1 I2 O5 I3 R3 I12 R4 R7
18-
W15 I14 O5 R3 W15 R4 W9 R3 I2 O3 W10 R3 W1 R4 R4 R7
19-
W1 I15 O5 N1 R7
20-
W7 R3 I12 O10 N1 R4
17+
W1 I6 O5 I2 R3 I3 R4 R7
18+
W15 I7 O5 R3 W15 R4 W9 R3 I6 O3 W10 R3 W1 R4 R4 R7
19+
W1 I8 O5 N0 R7
20+
W7 R3 I3 O10 N0 R4
2121
R5
22-
I14 R1 I15 R2 O5 I12 O6 N3 R7
23-
I12 O13 N3 R7
24-
I15 O20 /*--*/ R7
22+
I7 R1 I8 R2 O5 I3 O6 N1 R7
23+
I3 O13 N1 R7
24+
I8 O20 /*--*/ R7
2525
R6
26-
W11 I14 R7
26+
W11 I7 R7
2727
R6
2828
// Main
2929
/* double
3030
comment
3131
*/
32-
W1 W4 R3 W1 I0 R8 W19 W18 I1 R1 R2 R4
32+
W1 W4 R3 W1 I9 R8 W19 W18 I10 R1 R2 R4
3333
R5
34-
W1 I2 O5 I3 R3 N0 R4 R7
35-
W15 I4 O5 I5 R3 N0 R4 R7
36-
W1 I6 O5 N1 R7
37-
W12 R3 W1 I7 O5 N1 R7 I7 O8 I2 R7 I7 O20 R4
34+
W1 I6 O5 I2 R3 N2 R4 R7
35+
W15 I11 O5 I5 R3 N2 R4 R7
36+
W1 I12 O5 N0 R7
37+
W12 R3 W1 I13 O5 N0 R7 I13 O8 I6 R7 I13 O20 R4
3838
R5
39-
W5 R3 I7 O8 N2 O17 I7 O7 N1 R4
40-
I8 R3 C0 R8 I7 R8 I4 R1 I7 R2 R4 R7
41-
I6 O14 I4 R1 I7 R2 R7
39+
W5 R3 I13 O8 N3 O17 I13 O7 N0 R4
40+
I14 R3 C0 R8 I13 R8 I11 R1 I13 R2 R4 R7
41+
I12 O14 I11 R1 I13 R2 R7
4242
R6
43-
I8 R3 C1 R8 I6 R4 R7
44-
I9 R3 I4 R4 R7
45-
W11 N1 R7
43+
I14 R3 C1 R8 I12 R4 R7
44+
W20 R3 I11 R4 R7
45+
W11 N0 R7
4646
R6

test.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
int setDigitNumber(int num)
2+
{
3+
int size = sizeNumber(num);
4+
int* digits = (int*)malloc(size * sizeof(int));
5+
int index = 0;
6+
while (num != 0)
7+
{
8+
digits[index] = num % 10;
9+
num /= 10;
10+
index++/*--*/;
11+
}
12+
return digits;
13+
}
14+
// Main
15+
/* double
16+
comment
17+
*/
118
int main(int argc, const char* argv[])
219
{
320
int size = sizeNumber(36);

0 commit comments

Comments
 (0)