File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include "stdio.h"
2+ #include <malloc.h>
3+
4+ int sizeNumber(int num)
5+ {
6+ int count = 0;
7+ while (num != 0)
8+ {
9+ num = num / 10;
10+ count++;
11+ }
12+ return count;
13+ }
14+ int setDigitNumber(int num)
15+ {
16+ int size = sizeNumber(num);
17+ int* digits = (int*)malloc(size * sizeof(int));
18+ int index = 0;
19+ while (num != 0)
20+ {
21+ digits[index] = num % 10;
22+ num /= 10;
23+ index++;
24+ }
25+ return digits;
26+ }
27+
28+ int main(int argc, const char* argv[])
29+ {
30+ int size = sizeNumber(36);
31+ int *digitsNumber = setDigitNumber(36);
32+ int sumDigit = 0;
33+ for (int i = 0; i < size; i++)
34+ {
35+ printf("array[%d] = %d \n", i, digitsNumber[i]);
36+ sumDigit += digitsNumber[i];
37+ }
38+ printf("Summa digit: %d", sumDigit);
39+ free(digitsNumber);
40+ return 0;
41+ }
Original file line number Diff line number Diff line change 1- #include " const.h"
2- #include " workWithTable.h"
3- #include < iostream>
4- #include < string>
5- #include < fstream>
6- #include < vector>
7-
1+ #include " function.h"
82
93using namespace std ;
104
@@ -33,7 +27,9 @@ using namespace std;
3327
3428int main ()
3529{
36- ifstream fileC;
30+ cout << getServiceWordCode (" w" );
31+ /* ifstream fileC;
32+ ofstream fileAnalysis;
3733 fileC.exceptions(ifstream::badbit);
3834 try
3935 {
@@ -52,7 +48,7 @@ int main()
5248 {
5349 cout << " Exception opening/reading file";
5450 }
55- fileC.close ();
51+ fileC.close();*/
5652
5753 return 0 ;
5854}
Original file line number Diff line number Diff line change 151151 </Link >
152152 </ItemDefinitionGroup >
153153 <ItemGroup >
154+ <ClCompile Include =" function.cpp" />
154155 <ClCompile Include =" MethodsDevelopmentTranslator.cpp" />
155- <ClCompile Include =" workWithTable.cpp" />
156156 </ItemGroup >
157157 <ItemGroup >
158158 <Text Include =" C.txt" />
159159 </ItemGroup >
160160 <ItemGroup >
161- <ClInclude Include =" const.h" />
162- <ClInclude Include =" workWithTable.h" />
161+ <ClInclude Include =" function.h" />
162+ <ClInclude Include =" table.h" />
163+ <ClInclude Include =" include.h" />
163164 </ItemGroup >
164165 <Import Project =" $(VCTargetsPath)\Microsoft.Cpp.targets" />
165166 <ImportGroup Label =" ExtensionTargets" >
Original file line number Diff line number Diff line change 1313 <UniqueIdentifier >{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier >
1414 <Extensions >rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions >
1515 </Filter >
16- <Filter Include =" Исходные файлы\function" >
17- <UniqueIdentifier >{c38185bb-a9c9-4f37-a0d4-470f3b91b101}</UniqueIdentifier >
18- </Filter >
1916 </ItemGroup >
2017 <ItemGroup >
2118 <ClCompile Include =" MethodsDevelopmentTranslator.cpp" >
2219 <Filter >Исходные файлы</Filter >
2320 </ClCompile >
24- <ClCompile Include =" workWithTable .cpp" >
25- <Filter >Исходные файлы\function </Filter >
21+ <ClCompile Include =" function .cpp" >
22+ <Filter >Исходные файлы</Filter >
2623 </ClCompile >
2724 </ItemGroup >
2825 <ItemGroup >
3128 </Text >
3229 </ItemGroup >
3330 <ItemGroup >
34- <ClInclude Include =" const.h" >
35- <Filter >Исходные файлы</Filter >
31+ <ClInclude Include =" include.h" >
32+ <Filter >Файлы заголовков</Filter >
33+ </ClInclude >
34+ <ClInclude Include =" table.h" >
35+ <Filter >Файлы заголовков</Filter >
3636 </ClInclude >
37- <ClInclude Include =" workWithTable .h" >
38- <Filter >Исходные файлы\function </Filter >
37+ <ClInclude Include =" function .h" >
38+ <Filter >Файлы заголовков </Filter >
3939 </ClInclude >
4040 </ItemGroup >
4141</Project >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ #include " table.h"
2+ #include " function.h"
3+
4+ string getServiceWordCode (string str)
5+ {
6+ for (int i = 0 ; i < SIZE_serviceWord; i++)
7+ if (serviceWord[i][0 ] == str)
8+ return serviceWord[i][1 ];
9+ return " \0 " ;
10+ }
11+
12+ string getOperationsCode (string str)
13+ {
14+ for (int i = 0 ; i < SIZE_operation; i++)
15+ if (operations[i][0 ] == str)
16+ return operations[i][1 ];
17+ return " \0 " ;
18+ }
19+
20+ string getSeparatorsCode (string str)
21+ {
22+ for (int i = 0 ; i < SIZE_separators; i++)
23+ if (separators[i][0 ] == str)
24+ return separators[i][1 ];
25+ return " \0 " ;
26+ }
27+
28+ string getIdentifierCode (string str)
29+ {
30+ for (const auto & word : identifier)
31+ if (word.first == str)
32+ return word.second ;
33+ return " \0 " ;
34+ }
35+
36+ string getNumberConstCode (string str)
37+ {
38+ for (const auto & word : numberConst)
39+ if (word.first == str)
40+ return word.second ;
41+ return " \0 " ;
42+ }
43+
44+ string getSymbolsConstCode (string str)
45+ {
46+ for (const auto & word : symbolsConst)
47+ if (word.first == str)
48+ return word.second ;
49+ return " \0 " ;
50+ }
Original file line number Diff line number Diff line change 1+ #pragma once
2+ #ifndef FUNCTION_H
3+ #define FUNCTION_H
4+ #include < iostream>
5+
6+ std::string getServiceWordCode (std::string);
7+ std::string getOperationsCode (std::string str);
8+ std::string getSeparatorsCode (std::string str);
9+ std::string getIdentifierCode (std::string str);
10+ std::string getNumberConstCode (std::string str);
11+ std::string getSymbolsConstCode (std::string str);
12+ #endif
Original file line number Diff line number Diff line change 1+ #pragma once
2+ #ifndef INCLUDE_H
3+ #define INCLUDE_H
4+
5+ #include < iostream>
6+ #include < string>
7+ #include < fstream>
8+ #include < vector>
9+ #include < map>
10+
11+ using namespace std ;
12+ #endif
Original file line number Diff line number Diff line change 1+ #pragma once
2+ #ifndef TABLE_H
3+ #define TABLE_H
4+
5+ #include "include.h"
6+
7+ #define SIZE_serviceWord 8
8+ #define SIZE_separators 10
9+ #define SIZE_operation 12
10+ #define SIZE_columns 2
11+
12+ string const serviceWord [SIZE_serviceWord ][SIZE_columns ] =
13+ {
14+ {"int" ,"W1" },
15+ {"float" ,"W2" },
16+ {"char" ,"W3" },
17+ {"main" ,"W4" },
18+ {"if" ,"W5" },
19+ {"else" ,"W6" },
20+ {"while" ,"W7" },
21+ {"return" ,"W8" }
22+ };
23+
24+ string const operations [SIZE_operation ][SIZE_columns ] =
25+ {
26+ {"+" ,"O1" },
27+ {"-" ,"O2" },
28+ {"*" ,"O3" },
29+ {"/" ,"O4" },
30+ {"=" ,"O5" },
31+ {">" ,"O6" },
32+ {"<" ,"O7" },
33+ {"==" ,"O8" },
34+ {"!=" ,"O9" },
35+ {">=" ,"O10" },
36+ {"<=" ,"O11" },
37+ {"++" ,"O12" }
38+ };
39+
40+ string const separators [SIZE_separators ][SIZE_columns ] =
41+ {
42+ {"[" ,"R1" },
43+ {"]" ,"R2" },
44+ {"(" ,"R3" },
45+ {")" ,"R4" },
46+ {"{" ,"R5" },
47+ {"}" ,"R6" },
48+ {";" ,"R7" },
49+ {"." ,"R8" },
50+ {"*" ,"R9" },
51+ {"" ,"R10" }
52+ };
53+
54+ map < string , string > identifier ;
55+ map < string , string > numberConst ;
56+ map < string , string > symbolsConst ;
57+
58+
59+ #endif
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments