Skip to content

Commit f2d4a6c

Browse files
#TDP - 27 Add Exception & Fixed bug
Add exception Message Box for Syntax Class Syntax add methods: declareMain breachOfCondition breachOfExpressionWithNumberConst Add Exception for class lexical : after = not should not exists identifier
1 parent c1603f1 commit f2d4a6c

17 files changed

+525
-190
lines changed

LexicalAnalisator.cpp

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ LexicalAnalisator::~LexicalAnalisator()
1111
{
1212
}
1313

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

2216
void LexicalAnalisator::addCode(std::string str, std::map<std::string, std::string>& table, int numTable)
2317
{
@@ -56,8 +50,16 @@ std::string LexicalAnalisator::getCodeWordLength_1(std::string word)
5650
case 3:
5751
return getSeparators(word,true);
5852
case 4:
59-
if (getCodeByName(identifier,word) == "\0")
60-
addCode(word, identifier, 1);
53+
if (getCodeByName(identifier, word) == "\0")
54+
{
55+
if (isEqual == false)
56+
addCode(word, identifier, 1);
57+
else
58+
{
59+
problemDetected("Expected known identifier!");
60+
return "error!";
61+
}
62+
}
6163
return getCodeByName(identifier, word);
6264
default:
6365
return "";
@@ -90,7 +92,15 @@ std::string LexicalAnalisator::getCodeWordLengthGreaterOne(std::string word)
9092
}
9193
}
9294
if (getCodeByName(identifier, word) == "\0")
93-
addCode(word, identifier, 1);
95+
{
96+
if(isEqual == false)
97+
addCode(word, identifier, 1);
98+
else
99+
{
100+
problemDetected("Expected known identifier!");
101+
return "error!";
102+
}
103+
}
94104
return getCodeByName(identifier, word);
95105
}
96106
}
@@ -101,7 +111,12 @@ std::string LexicalAnalisator::getCodeWordLengthGreaterOne(std::string word)
101111
std::string LexicalAnalisator::getCodeWord(std::string word)
102112
{
103113
if (word.length() == 1)
104-
return getCodeWordLength_1(word);
114+
{
115+
std::string temp = getCodeWordLength_1(word);
116+
if (temp == "R7")
117+
isEqual = false;
118+
return temp;
119+
}
105120
else
106121
return getCodeWordLengthGreaterOne(word);
107122
}
@@ -145,8 +160,8 @@ void LexicalAnalisator::makeLexicalAnalyze(std::string filePathOrName_C, std::st
145160
fileC.exceptions(std::ifstream::badbit);
146161
try
147162
{
163+
isEqual = false;
148164
fileC.open(filePathOrName_C);
149-
150165
if (fileC.is_open())
151166
{
152167
bool readComment = false;
@@ -225,6 +240,8 @@ void LexicalAnalisator::makeLexicalAnalyze(std::string filePathOrName_C, std::st
225240
i++;
226241
}
227242
word += stringLanguageC[i];
243+
if (word == "=")
244+
isEqual = true;
228245
fileAnalysis << getCodeWord(word) << " ";
229246
word = "";
230247
continue;
@@ -243,7 +260,12 @@ void LexicalAnalisator::makeLexicalAnalyze(std::string filePathOrName_C, std::st
243260
else
244261
i++;
245262
}
246-
fileAnalysis << getCodeWord(word) << " ";
263+
std::string check_err = getCodeWord(word);
264+
if (check_err.find("error!")!=std::string::npos)
265+
return;
266+
267+
268+
fileAnalysis << check_err << " ";
247269
word = "";
248270
continue;
249271
}

MethodsDevelopmentTranslator.vcxproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
<WarningLevel>Level3</WarningLevel>
103103
<Optimization>Disabled</Optimization>
104104
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
105-
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
106105
</ClCompile>
107106
<Link>
108107
<AdditionalDependencies />
@@ -137,8 +136,8 @@
137136
</ItemGroup>
138137
<ItemGroup>
139138
<ClCompile Include="function.cpp" />
140-
<ClCompile Include="ReversePolishNotation.cpp" />
141139
<ClCompile Include="LexicalAnalisator.cpp" />
140+
<ClCompile Include="ReversePolishNotation.cpp" />
142141
<ClCompile Include="SyntaxAnalisator.cpp" />
143142
<ClCompile Include="translate_csharp.cpp" />
144143
<ClCompile Include="Translator.cpp" />
@@ -148,8 +147,8 @@
148147
<ItemGroup>
149148
<ClInclude Include="function.h" />
150149
<ClInclude Include="include.h" />
151-
<ClInclude Include="ReversePolishNotation.h" />
152150
<ClInclude Include="LexicalAnalisator.h" />
151+
<ClInclude Include="ReversePolishNotation.h" />
153152
<ClInclude Include="SyntaxAnalisator.h" />
154153
<ClInclude Include="translate_csharp.h" />
155154
<ClInclude Include="Translator.h" />

MethodsDevelopmentTranslator.vcxproj.filters

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424
<ClCompile Include="Translator.cpp">
2525
<Filter>Исходные файлы</Filter>
2626
</ClCompile>
27-
<ClCompile Include="ReversePolishNotation.cpp">
27+
<ClCompile Include="TranslatorFromCToCSharp.cpp">
2828
<Filter>Исходные файлы</Filter>
2929
</ClCompile>
30-
<ClCompile Include="translate_csharp.cpp">
30+
<ClCompile Include="SyntaxAnalisator.cpp">
3131
<Filter>Исходные файлы</Filter>
3232
</ClCompile>
33-
<ClCompile Include="TranslatorFromCToCSharp.cpp">
33+
<ClCompile Include="ReversePolishNotation.cpp">
3434
<Filter>Исходные файлы</Filter>
3535
</ClCompile>
36-
<ClCompile Include="LexicalAnalisator.cpp">
36+
<ClCompile Include="translate_csharp.cpp">
3737
<Filter>Исходные файлы</Filter>
3838
</ClCompile>
39-
<ClCompile Include="SyntaxAnalisator.cpp">
39+
<ClCompile Include="LexicalAnalisator.cpp">
4040
<Filter>Исходные файлы</Filter>
4141
</ClCompile>
4242
</ItemGroup>
@@ -53,19 +53,19 @@
5353
<ClInclude Include="Translator.h">
5454
<Filter>Файлы заголовков</Filter>
5555
</ClInclude>
56-
<ClInclude Include="ReversePolishNotation.h">
56+
<ClInclude Include="translate_csharp.h">
5757
<Filter>Файлы заголовков</Filter>
5858
</ClInclude>
59-
<ClInclude Include="translate_csharp.h">
59+
<ClInclude Include="SyntaxAnalisator.h">
6060
<Filter>Файлы заголовков</Filter>
6161
</ClInclude>
62-
<ClInclude Include="TranslatorFromCToCSharp.h">
62+
<ClInclude Include="ReversePolishNotation.h">
6363
<Filter>Файлы заголовков</Filter>
6464
</ClInclude>
6565
<ClInclude Include="LexicalAnalisator.h">
6666
<Filter>Файлы заголовков</Filter>
6767
</ClInclude>
68-
<ClInclude Include="SyntaxAnalisator.h">
68+
<ClInclude Include="TranslatorFromCToCSharp.h">
6969
<Filter>Файлы заголовков</Filter>
7070
</ClInclude>
7171
</ItemGroup>

ReversePolishNotation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ void ReversePolishNotation::reversePolishNotationAnalyze(std::string fileName_le
155155
if (lineLexical.find("W8") != std::string::npos)
156156
{
157157
fileAnalysis << lineLexical << std::endl;
158-
countInclude++;
158+
if(lineLexical.find("I") != std::string::npos)
159+
countInclude++;
159160
continue;
160161
}
161162
if (lineLexical.length() > 2 && isComment((int)lineLexical[0], (int)lineLexical[1]) && lineLexical.find("*/") == std::string::npos)
@@ -191,7 +192,7 @@ void ReversePolishNotation::reversePolishNotationAnalyze(std::string fileName_le
191192
{
192193
if (positionTypeConversion(lineLexical) == 0)
193194
{
194-
token = lineLexical.substr(3, lineLexical.find("R4")-2);
195+
token = lineLexical.substr(3, lineLexical.find("R4")-4);
195196
lineLexical.erase(0,10);
196197
}
197198
else

0 commit comments

Comments
 (0)