44// ( ) [ ] { } ;
55bool isSeparators (int const &elem)
66{
7- return elem == 40 || elem == 41 || elem == 91 || elem == 93 || elem == 123 || elem == 125 || elem == 59 ? true : false ;
7+ return elem == 40 || elem == 41 || elem == 91 || elem == 93 || elem == 123 || elem == 125 || elem == 59 || elem == 44 ? true : false ;
88}
99
1010// \a \b \t \n \v \f \r
1111bool isServiceSymbols (int const &elem)
1212{
1313 return elem == 7 || elem == 8 || elem == 9 || elem == 10 || elem == 11 || elem == 12 || elem == 13 ? true : false ;
1414}
15- /* +- * / % */
16- bool isOperation (string const &str, int const &ind )
15+ /* +- * / % = */
16+ bool isOperation (int const & elem )
1717{
18- return str[ind] == ' + ' || str[ind] == ' - ' || str[ind] == ' / ' || str[ind] == ' * ' || str[ind] == ' = ' || str[ind] == ' % ' ? true : false ;
18+ return elem == 43 || elem == 45 || elem == 47 || elem == 42 || elem == 61 || elem == 37 ? true : false ;
1919}
2020
21- /* < > == >= <= != */
22- bool isLogicalOperation (string const & str, int const & ind )
21+ /* < > */
22+ bool isLogicalSingleOperation ( int const & elem )
2323{
24- return str[ind] == ' <' || str[ind] == ' >' || (str[ind] == ' =' && str[ind + 1 ] == ' =' ) ||
25- (str[ind] == ' >' && str[ind + 1 ] == ' =' ) || (str[ind] == ' <' && str[ind + 1 ] == ' =' ) || (str[ind] == ' !' && str[ind + 1 ] == ' =' ) ? true : false ;
24+ return elem == 60 || elem == 62 ? true : false ;
25+ }
26+ /* == >= <= != && ||*/
27+ bool isLogicalDoubleOperation (int const & elem, int const & nextElem)
28+ {
29+ return (elem == 61 && nextElem == 61 ) || (elem == 62 && nextElem == 61 ) || (elem == 60 && nextElem == 61 )
30+ || (elem == 33 && nextElem == 61 ) || (elem == 38 && nextElem == 38 ) || (elem == 124 && nextElem == 124 ) ? true : false ;
2631}
2732
2833// ++ --
29- bool isIncrement (string const & str , int const & ind )
34+ bool isIncrement (int const & elem , int const & nextElem )
3035{
31- return (str[ind] == ' +' && str[ind + 1 ] == ' +' ) || (str[ind] == ' -' && str[ind + 1 ] == ' -' ) ? true : false ;
36+ return (elem == ' +' && nextElem == ' +' ) || (elem == ' -' && nextElem == ' -' ) ? true : false ;
3237}
3338
3439/* += -= *= /= */
35- bool isDoubleOperation (string const & str , int const & ind )
40+ bool isDoubleOperation (int const & elem , int const & nextElem )
3641{
37- return (str[ind] == ' +' && str[ind + 1 ] == ' =' ) || (str[ind] == ' -' && str[ind + 1 ] == ' =' ) ||
38- (str[ind] == ' *' && str[ind + 1 ] == ' =' ) || (str[ind] == ' /' && str[ind + 1 ] == ' =' ) ? true : false ;
42+ return (elem == ' +' && nextElem == ' =' ) || (elem == ' -' && nextElem == ' =' ) ||
43+ (elem == ' *' && nextElem == ' =' ) || (elem == ' /' && nextElem == ' =' ) ? true : false ;
3944}
4045
4146bool isComment (int const &slash, int const & star)
@@ -135,52 +140,71 @@ void addCode(string str, map<string, string> &table, int numTable)
135140 table.insert (pair<string, string>(str, " C" + to_string (indexCode)));
136141}
137142
143+ int checkStringSingleElem (string const & word)
144+ {
145+ if (isDigit ((int )word[0 ]) == true )
146+ return 1 ;
147+ if (isOperation ((int )word[0 ]) == true || isLogicalSingleOperation ((int )word[0 ]) == true )
148+ return 2 ;
149+ if (isSeparators ((int )word[0 ]) == true )
150+ return 3 ;
151+ if (isLetter ((int )word[0 ]) == true )
152+ return 4 ;
153+ }
138154
139155string getCodeWordLength_1 (string word)
140156{
157+ switch (checkStringSingleElem (word))
158+ {
159+ case 1 :
160+ if (getNumberConstCode (word) == " \0 " )
161+ addCode (word, numberConst, 2 );
162+ return getNumberConstCode (word);
163+ case 2 :
164+ return getOperationsCode (word);
165+ case 3 :
166+ return getSeparatorsCode (word);
167+ case 4 :
168+ if (getIdentifierCode (word) == " \0 " )
169+ addCode (word, identifier, 1 );
170+ return getIdentifierCode (word);
171+ default :
172+ return " " ;
173+ }
174+ /*
141175 string code = getOperationsCode(word);
142176 if (code == "\0")
143177 code = getSeparatorsCode(word);
144178 if (code=="\0")
145179 {
146180 if (isDigit((int)word[0]) == true)
147181 {
148- code = getNumberConstCode (word);
149- if (code ==" \0 " )
182+ if (getNumberConstCode(word) == "\0")
150183 addCode(word, numberConst, 2);
151184 return getNumberConstCode(word);
152185 }
153186 if (isLetter((int)word[0]) == true)
154187 {
155- code = getIdentifierCode (word);
156- if (code==" \0 " )
188+ if(getIdentifierCode(word) =="\0")
157189 addCode(word,identifier,1);
158190 return getIdentifierCode(word);
159191 }
160192 }
161193 else
162- {
163- return code;
164- }
194+ return code;*/
165195}
166196
167197
168198string getCodeWordLengthGreaterOne (string word)
169199{
170- /* if (word == "p*")
171- {
172- word.erase(0, 1);
173- return getSeparatorsCode(word);
174- }*/
175200 string code = getServiceWordCode (word);
176201 if (code == " \0 " )
177202 code = getOperationsCode (word);
178203 if (code == " \0 " )
179204 {
180205 if (isNumber (word) == true )
181206 {
182- code = getNumberConstCode (word);
183- if (code==" \0 " )
207+ if (getNumberConstCode (word) ==" \0 " )
184208 addCode (word, numberConst, 2 );
185209 return getNumberConstCode (word);
186210 }
@@ -190,23 +214,14 @@ string getCodeWordLengthGreaterOne(string word)
190214 {
191215 if (isLibrary_header (word) == false )
192216 {
193- code = getSymbolsConstCode (word);
194- if (code == " \0 " )
217+ if (getSymbolsConstCode (word) == " \0 " )
195218 addCode (word, symbolsConst, 3 );
196219 return getSymbolsConstCode (word);
197- }
198- else
199- goto addCodeIdentifier;
220+ }
200221 }
201- else
202- {
203- addCodeIdentifier:
204- code = getIdentifierCode (word);
205- if (code == " \0 " )
206- addCode (word, identifier, 1 );
207- return getIdentifierCode (word);
208- }
209-
222+ if (getIdentifierCode (word) == " \0 " )
223+ addCode (word, identifier, 1 );
224+ return getIdentifierCode (word);
210225 }
211226 }
212227 else
0 commit comments