Skip to content

Commit 711cafa

Browse files
#TDP-10 Add read comment
Add method bool check comment one line or many line Write to Analyse file comment - view : many line /* comm */ one line // comm
1 parent 101633c commit 711cafa

File tree

5 files changed

+117
-81
lines changed

5 files changed

+117
-81
lines changed

C.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ int sizeNumber(int num)
1111
}
1212
return count;
1313
}
14+
/*test comment*/
1415
int setDigitNumber(int num)
1516
{
1617
int size = sizeNumber(num);
@@ -20,11 +21,14 @@ int setDigitNumber(int num)
2021
{
2122
digits[index] = num % 10;
2223
num /= 10;
23-
index++;
24+
index++/*--*/;
2425
}
2526
return digits;
2627
}
27-
28+
// Main
29+
/* double
30+
comment
31+
*/
2832
int main(int argc, const char* argv[])
2933
{
3034
int size = sizeNumber(36);

MethodsDevelopmentTranslator.cpp

Lines changed: 92 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -36,130 +36,146 @@ int main(int argc, char* argv[])
3636

3737
if (fileC.is_open())
3838
{
39+
bool readComment = false;
40+
string temp = "";
3941
while (!fileC.eof())
4042
{
4143
string stringLanguageC = "";
42-
string temp = "";
4344
getline(fileC, stringLanguageC);
4445
for (unsigned int i = 0; i < stringLanguageC.length(); i++)
4546
{
4647
if (isServiceSymbols((int)stringLanguageC[i]) == true)
4748
continue;
48-
49-
if (isSeparators((int)stringLanguageC[i]) == true && temp[0] != '\"')
49+
if (isComment((int)stringLanguageC[i], (int)stringLanguageC[i + 1]) == true)
50+
readComment = true;
51+
if (readComment == false && isOneStringComment((int)stringLanguageC[i], (int)stringLanguageC[i + 1]) == true)
5052
{
51-
if (temp.length() != 0)
52-
fileAnalysis << getCodeWord(temp) << " ";
53-
temp = stringLanguageC[i];
54-
fileAnalysis << getCodeWord(temp) << " ";
53+
string temp2 = "";
54+
temp2.assign(stringLanguageC, i, stringLanguageC.length() - i);
55+
fileAnalysis << temp2 << " ";
56+
break;
57+
}
58+
if (readComment == true && isComment((int)stringLanguageC[i + 1], (int)stringLanguageC[i]) == true)
59+
{
60+
readComment = false;
61+
temp += stringLanguageC[i];
62+
temp += stringLanguageC[i + 1];
63+
if (temp != "\0" && temp!= "/**/")
64+
fileAnalysis << temp << " ";
5565
temp = "";
66+
i++;
5667
continue;
68+
5769
}
58-
59-
// <library.h> and "string"
60-
if (stringLanguageC[i] == '<' || stringLanguageC[i] == '\"')
70+
71+
if (readComment == false)
6172
{
62-
int posClose = 0;
63-
int countSymbols = 0;
64-
if (stringLanguageC[i] == '<')
65-
posClose = stringLanguageC.find(">", 1);
66-
else
67-
posClose = stringLanguageC.rfind('\"');
68-
69-
if (posClose != -1)
73+
if (isSeparators((int)stringLanguageC[i]) == true && temp[0] != '\"')
7074
{
71-
countSymbols = posClose + 1 - i;
72-
temp.assign(stringLanguageC, i, countSymbols);
73-
if (temp.find(".h") != -1)
74-
{
75+
if (temp.length() != 0)
7576
fileAnalysis << getCodeWord(temp) << " ";
76-
temp = "";
77-
if (stringLanguageC[posClose + 1] == '\0')
78-
break;
79-
else
80-
i = posClose;
81-
}
77+
temp = stringLanguageC[i];
78+
fileAnalysis << getCodeWord(temp) << " ";
79+
temp = "";
80+
continue;
81+
}
82+
83+
// <library.h> and "string"
84+
if (stringLanguageC[i] == '<' || stringLanguageC[i] == '\"')
85+
{
86+
int posClose = 0;
87+
int countSymbols = 0;
88+
if (stringLanguageC[i] == '<')
89+
posClose = stringLanguageC.find(">", 1);
8290
else
91+
posClose = stringLanguageC.rfind('\"');
92+
93+
if (posClose != -1)
8394
{
84-
if (temp[0] == '\"')
95+
countSymbols = posClose + 1 - i;
96+
temp.assign(stringLanguageC, i, countSymbols);
97+
if (temp.find(".h") != -1)
8598
{
8699
fileAnalysis << getCodeWord(temp) << " ";
87-
i = posClose;
100+
temp = "";
101+
if (stringLanguageC[posClose + 1] == '\0')
102+
break;
103+
else
104+
i = posClose;
105+
}
106+
else
107+
{
108+
if (temp[0] == '\"')
109+
{
110+
fileAnalysis << getCodeWord(temp) << " ";
111+
i = posClose;
88112

113+
}
89114
}
115+
temp = "";
90116
}
91-
temp = "";
92-
//continue;
93117
}
94-
}
95118

96-
if (isOperation(stringLanguageC, i) == true || isLogicalOperation(stringLanguageC, i) == true)
97-
{
98-
if (isIncrement(stringLanguageC, i) == true || isDoubleOperation(stringLanguageC, i) == true)
119+
if (isOperation(stringLanguageC, i) == true || isLogicalOperation(stringLanguageC, i) == true)
99120
{
121+
if (isIncrement(stringLanguageC, i) == true || isDoubleOperation(stringLanguageC, i) == true)
122+
{
123+
temp += stringLanguageC[i];
124+
i++;
125+
}
100126
temp += stringLanguageC[i];
101-
i++;
127+
fileAnalysis << getCodeWord(temp) << " ";
128+
temp = "";
129+
continue;
102130
}
103-
temp += stringLanguageC[i];
104-
fileAnalysis << getCodeWord(temp) << " ";
105-
temp = "";
106-
continue;
107-
}
108-
109-
if (stringLanguageC[i] != ' ')
110-
{
111-
if (isLetter((int)stringLanguageC[i]) == true && (isLetter((int)stringLanguageC[i+1])==false && isDigit((int)stringLanguageC[i+1])==false))
131+
132+
if (stringLanguageC[i] != ' ')
112133
{
113-
/*if (temp[0] == '\"')
134+
if (isLetter((int)stringLanguageC[i]) == true && (isLetter((int)stringLanguageC[i + 1]) == false && isDigit((int)stringLanguageC[i + 1]) == false))
114135
{
115-
if (stringLanguageC[i] == '\"' && stringLanguageC[i + 1] == ' ' && stringLanguageC[i + 1] == '\0')
116-
{
117-
temp += stringLanguageC[i];
118-
fileAnalysis << getCodeWord(temp) << " ";
119-
temp = "";
120-
continue;
121-
}
122-
else
136+
137+
temp += stringLanguageC[i];
138+
fileAnalysis << getCodeWord(temp) << " ";
139+
temp = "";
140+
continue;
141+
}
142+
else
143+
{
144+
if (stringLanguageC[i] == '#')
123145
{
124146
temp += stringLanguageC[i];
125147
continue;
126148
}
149+
127150
}
128-
else
129-
{*/
130-
temp += stringLanguageC[i];
131-
fileAnalysis << getCodeWord(temp) << " ";
132-
temp = "";
133-
continue;
134-
151+
temp += stringLanguageC[i];
135152
}
136153
else
137154
{
138-
if (stringLanguageC[i] == '#')
139-
{
140-
temp += stringLanguageC[i];
155+
if (temp == "\0")
141156
continue;
157+
else
158+
{
159+
fileAnalysis << getCodeWord(temp) << " ";
160+
temp = "";
142161
}
143-
144162
}
145-
temp += stringLanguageC[i];
146163
}
147164
else
148165
{
149-
if (temp == "\0")
150-
continue;
151-
else
152-
{
153-
fileAnalysis << getCodeWord(temp) << " ";
154-
temp = "";
155-
}
166+
temp += stringLanguageC[i];
156167
}
168+
157169
}
158170
if (temp != "\0")
159171
{
160-
fileAnalysis << getCodeWord(temp);
172+
if (readComment == false)
173+
fileAnalysis << getCodeWord(temp);
174+
else
175+
temp += '\n';
161176
}
162-
fileAnalysis << "\n";
177+
if(readComment==false)
178+
fileAnalysis << "\n";
163179
}
164180
}
165181

function.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ bool isDoubleOperation(string const& str, int const& ind)
3838
(str[ind] == '*' && str[ind + 1] == '=') || (str[ind] == '/' && str[ind + 1] == '=') ? true : false;
3939
}
4040

41+
bool isComment(int const &slash, int const& star)
42+
{
43+
return slash == 47 && star == 42? true : false;
44+
}
45+
bool isOneStringComment(int const& slash, int const& slash2)
46+
{
47+
return slash == 47 && slash2 == 47 ? true : false;
48+
}
49+
50+
4151
bool isLetter(int const &elem)
4252
{
4353
return (elem >= 65 && elem <= 90) || (elem >= 97 && elem <= 122) ? true : false;
@@ -176,7 +186,7 @@ string getCodeWordLengthGreaterOne(string word)
176186
}
177187
else
178188
{
179-
if ((int)word[0] == 34)
189+
if ((int)word[0] == 34)// \"
180190
{
181191
if (isLibrary_header(word) == false)
182192
{

function.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ bool isOperation(string const &str, int const &ind);
99
bool isLogicalOperation(string const& str, int const& ind);
1010
bool isIncrement(string const& str, int const& ind);
1111
bool isDoubleOperation(string const& str, int const& ind);
12+
bool isComment(int const& slash, int const& star);
13+
bool isOneStringComment(int const& slash, int const& slash2);
1214
bool isDigit(int const &);
1315
bool isLetter(int const &);
1416
bool isLibrary_header(string const &);

lexical.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ I5 O20 R7
1111
R6
1212
W11 I5 R7
1313
R6
14+
/*test comment*/
1415
W1 I6 R3 W1 I4 R4
1516
R5
1617
W1 I7 O5 I3 R3 I4 R4 R7
@@ -20,11 +21,14 @@ W7 R3 I4 O5 N1 R4
2021
R5
2122
I8 R1 I9 R2 O5 I4 O6 N2 R7
2223
I4 O13 N2 R7
23-
I9 O20 R7
24+
I9 O20 /*--*/ R7
2425
R6
2526
W11 I8 R7
2627
R6
27-
28+
// Main
29+
/* double
30+
comment
31+
*/
2832
W1 W4 R3 W1 I10 R8 I11 W3 O3 I12 R1 R2 R4
2933
R5
3034
W1 I7 O5 I3 R3 N3 R4 R7

0 commit comments

Comments
 (0)