@@ -98,19 +98,15 @@ private void analizeLine(String line) {
9898 lexeme = "" ;
9999 }
100100 if (isOperator (Character .toString (chars [index ]))) {
101- if (index != tokenList .size () - 1 ) {
102- if (isOperator (Character .toString (chars [index + 1 ]))) {
103- column = index + 1 ;
104- tokenList .add (
105- new Token (Character .toString (chars [index ]) + Character .toString (chars [index + 1 ]),
106- TokenType .DESCONOCIDO , row , column ));
107- index ++;
108- } else {
109- column = index + 1 ;
110- tokenList .add (
111- new Token (Character .toString (chars [index ]), TokenType .DESCONOCIDO , row , column ));
112- }
101+ column = index + 1 ;
102+ String lex ;
103+ if (index < chars .length - 1 && isOperator (Character .toString (chars [index + 1 ]))) {
104+ lex = Character .toString (chars [index ]) + Character .toString (chars [index + 1 ]);
105+ index ++;
106+ } else {
107+ lex = Character .toString (chars [index ]);
113108 }
109+ tokenList .add (new Token (lex , TokenType .DESCONOCIDO , row , column ));
114110 } else if (isDelimiter (Character .toString (chars [index ]))) {
115111 column = index + 1 ;
116112 tokenList .add (new Token (Character .toString (chars [index ]), TokenType .DESCONOCIDO , row , column ));
@@ -212,25 +208,25 @@ private boolean isDelimiter(String lexeme) {
212208 */
213209 private boolean isIdentifier (String lexeme , int tknIndex ) {
214210 boolean val = false ;
215- try {
216- if (tokenList .get (tknIndex + 1 ).getLexeme ().equals ("=" )) {
217- if (tokenList .get (tknIndex + 2 ).getLexeme ().equals ("{" )) {
218- tokenType = TokenType .IDENTIFICADOR_CONJUNTO ;
219- } else if (tokenList .get (tknIndex + 2 ).getLexeme ().equals ("(" )) {
220- tokenType = TokenType .IDENTIFICADOR_TUPLA ;
221- } else if (tokenList .get (tknIndex + 2 ).getLexeme ().equals ("[" )) {
222- tokenType = TokenType .IDENTIFICADOR_LISTA ;
223- } else {
224- tokenType = TokenType .IDENTIFICADOR ;
225- }
226- variableNames .add (lexeme );
227- val = !val ;
228- } else if (variableNames .contains (lexeme )) {
211+ if (tknIndex >= 1 && tokenList .get (tknIndex - 1 ).getToken () == TokenType .EXCEPT ) {
212+ tokenType = TokenType .IDENTIFICADOR_EXCEPCION ;
213+ val = !val ;
214+ }
215+ if (tknIndex < tokenList .size () - 1 && tokenList .get (tknIndex + 1 ).getLexeme ().equals ("=" )) {
216+ if (tknIndex < tokenList .size () - 2 && tokenList .get (tknIndex + 2 ).getLexeme ().equals ("{" )) {
217+ tokenType = TokenType .IDENTIFICADOR_CONJUNTO ;
218+ } else if (tknIndex < tokenList .size () - 2 && tokenList .get (tknIndex + 2 ).getLexeme ().equals ("(" )) {
219+ tokenType = TokenType .IDENTIFICADOR_TUPLA ;
220+ } else if (tknIndex < tokenList .size () - 2 && tokenList .get (tknIndex + 2 ).getLexeme ().equals ("[" )) {
221+ tokenType = TokenType .IDENTIFICADOR_LISTA ;
222+ } else {
229223 tokenType = TokenType .IDENTIFICADOR ;
230- val = !val ;
231224 }
232- } catch (IndexOutOfBoundsException e ) {
233-
225+ variableNames .add (lexeme );
226+ val = !val ;
227+ } else if (variableNames .contains (lexeme )) {
228+ tokenType = TokenType .IDENTIFICADOR ;
229+ val = !val ;
234230 }
235231 return val ;
236232 }
@@ -247,21 +243,17 @@ private boolean isIdentifier(String lexeme, int tknIndex) {
247243 */
248244 private boolean isClassIdentifier (String lexeme , int tknIndex ) {
249245 boolean val = false ;
250- try {
251- if (tokenList .get (tknIndex - 1 ).getToken () == TokenType .CLASS ) {
252- if (!variableNames .contains (lexeme )) {
253- tokenType = TokenType .IDENTIFICADOR_CLASE ;
254- val = !val ;
255- }
256- } else if (tokenList .get (tknIndex - 1 ).getToken () == TokenType .FOR ) {
257- tokenType = TokenType .IDENTIFICADOR ;
258- val = !val ;
259- } else if (tokenList .get (tknIndex - 1 ).getToken () == TokenType .DEF ) {
260- tokenType = TokenType .IDENTIFICADOR_FUNCION ;
246+ if (tknIndex < tokenList .size () - 1 && tokenList .get (tknIndex - 1 ).getToken () == TokenType .CLASS ) {
247+ if (!variableNames .contains (lexeme )) {
248+ tokenType = TokenType .IDENTIFICADOR_CLASE ;
261249 val = !val ;
262250 }
263- } catch (IndexOutOfBoundsException e ) {
264-
251+ } else if (tknIndex < tokenList .size () - 1 && tokenList .get (tknIndex - 1 ).getToken () == TokenType .FOR ) {
252+ tokenType = TokenType .IDENTIFICADOR ;
253+ val = !val ;
254+ } else if (tknIndex < tokenList .size () - 1 && tokenList .get (tknIndex - 1 ).getToken () == TokenType .DEF ) {
255+ tokenType = TokenType .IDENTIFICADOR_FUNCION ;
256+ val = !val ;
265257 }
266258 return val ;
267259 }
0 commit comments