Skip to content

Commit b7e295b

Browse files
committed
:c
1 parent 607b746 commit b7e295b

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

src/main/java/LexerOperations/Lexer.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,29 +208,41 @@ private boolean isDelimiter(String lexeme) {
208208
*/
209209
private boolean isIdentifier(String lexeme, int tknIndex) {
210210
boolean val = false;
211+
212+
// Verifica si el token anterior es una excepción
211213
if (tknIndex >= 1 && tokenList.get(tknIndex - 1).getToken() == TokenType.EXCEPT) {
212214
tokenType = TokenType.IDENTIFICADOR_EXCEPCION;
213215
val = !val;
214216
}
217+
218+
// Verifica si el siguiente token es '=' y si hay un valor válido después
215219
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-
tokenType = TokenType.IDENTIFICADOR;
221-
} else if (tknIndex < tokenList.size() - 2 && tokenList.get(tknIndex + 2).getLexeme().equals("[")) {
222-
tokenType = TokenType.IDENTIFICADOR_LISTA;
220+
if (tknIndex < tokenList.size() - 2) {
221+
String nextLexeme = tokenList.get(tknIndex + 2).getLexeme();
222+
if (nextLexeme.equals("{")) {
223+
tokenType = TokenType.IDENTIFICADOR_CONJUNTO;
224+
} else if (nextLexeme.equals("(")) {
225+
tokenType = TokenType.IDENTIFICADOR;
226+
} else if (nextLexeme.equals("[")) {
227+
tokenType = TokenType.IDENTIFICADOR_LISTA;
228+
} else if (tokenList.get(tknIndex + 2).getRow() == tokenList.get(tknIndex + 1).getRow()) { // Verifica que haya un valor válido después del '='
229+
tokenType = TokenType.IDENTIFICADOR;
230+
} else {
231+
tokenType = TokenType.DESCONOCIDO; // No hay valor después del '='
232+
}
233+
variableNames.add(lexeme);
234+
val = !val;
223235
} else {
224-
tokenType = TokenType.IDENTIFICADOR;
236+
tokenType = TokenType.DESCONOCIDO; // No hay tokens después del '='
225237
}
226-
variableNames.add(lexeme);
227-
val = !val;
228238
} else if (variableNames.contains(lexeme)) {
229239
tokenType = TokenType.IDENTIFICADOR;
230240
val = !val;
231241
}
242+
232243
return val;
233244
}
245+
234246

235247
/**
236248
* Este método compara los valores anteriores o posteriores de un token en

src/main/java/SemanticOperations/VariableAssignment.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ private void evalExpressions() {
4545
for (Variable variable : variables) {
4646
if (variable.getVarName().equals(value)) {
4747
if (variable.getRow() < entry.getKey()) {
48-
values.set(i, variable.getValue());
49-
break;
48+
if (variable.getValue().isBlank()) {
49+
variable.setType(TokenType.NONE);
50+
variable.setState(State.INDEFINIDO);
51+
showError("[SEMANTICO] No se reconoce '" + value + "'", entry.getKey());
52+
} else {
53+
values.set(i, variable.getValue());
54+
break;
55+
}
5056
} else {
5157
showError("[SEMANTICO] No se reconoce '" + value + "'", entry.getKey());
5258
}
@@ -102,6 +108,7 @@ private void evalExpressions() {
102108
}
103109
// Asignar Tipo a cada variable
104110
assignDataTypes(entry.getKey(), contInt, contDec, contBool, contString, error);
111+
105112
}
106113

107114
for (Variable variable : variables) {
@@ -187,11 +194,8 @@ private TokenType evalDataType(String value) {
187194
type = TokenType.DECIMAL;
188195
} else if (dots == 0 && cont == value.length()) {
189196
type = TokenType.ENTERO;
190-
} else {
191-
type = TokenType.NONE;
192197
}
193198
}
194-
195199
return type;
196200
}
197201

78 Bytes
Binary file not shown.
68 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)