Skip to content

Commit f76778c

Browse files
committed
[UPDATE] Parser class, new classes for parsing methods
1 parent 05f6a89 commit f76778c

File tree

31 files changed

+232
-434
lines changed

31 files changed

+232
-434
lines changed

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/LexerOperations/Lexer.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ private void analizeLine(String line) {
9595
lexeme = "";
9696
}
9797
if (isOperator(Character.toString(chars[index]))) {
98-
if (isOperator(Character.toString(chars[index + 1]))) {
99-
column = index + 1;
100-
tokenList.add(new Token(Character.toString(chars[index]) + Character.toString(chars[index + 1]), TokenType.DESCONOCIDO, row, column));
101-
index++;
102-
} else {
103-
column = index + 1;
104-
tokenList.add(new Token(Character.toString(chars[index]), TokenType.DESCONOCIDO, row, column));
98+
if (index != tokenList.size() - 1) {
99+
if (isOperator(Character.toString(chars[index + 1]))) {
100+
column = index + 1;
101+
tokenList.add(new Token(Character.toString(chars[index]) + Character.toString(chars[index + 1]), TokenType.DESCONOCIDO, row, column));
102+
index++;
103+
} else {
104+
column = index + 1;
105+
tokenList.add(new Token(Character.toString(chars[index]), TokenType.DESCONOCIDO, row, column));
106+
}
105107
}
106108
} else if (isDelimiter(Character.toString(chars[index]))) {
107109
column = index + 1;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package ParserOperations;
2+
public class ConditionalParser {
3+
4+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package ParserOperations;
2+
3+
import Tokens.Token;
4+
import Tokens.TokenType;
5+
import java.util.ArrayList;
6+
import javax.swing.JTextArea;
7+
8+
public class ExpressionParser {
9+
10+
private Utilities tool;
11+
12+
public ExpressionParser() {
13+
tool = new Utilities();
14+
}
15+
16+
public void parseIf(ArrayList<Token> tokenList, int index, int currentRow, JTextArea console) {
17+
if (tool.verifyToken(TokenType.IF, tokenList, index)) {
18+
index++;
19+
if (isSimpleExpression(tokenList, index, currentRow, console)) {
20+
System.out.println("IF SIMPLE");
21+
}
22+
}
23+
}
24+
25+
private boolean isSimpleExpression(ArrayList<Token> tokenList, int index, int currentRow, JTextArea console) {
26+
boolean result = false;
27+
if (tool.verifyToken(TokenType.PARENTESIS_APERTURA, tokenList, index)) {
28+
index++;
29+
if (tool.isValueToken(tokenList.get(index))) {
30+
index++;
31+
if (tool.isRelationalOperator(tokenList.get(index))) {
32+
index++;
33+
if (tool.isValueToken(tokenList.get(index))) {
34+
index++;
35+
if (tool.verifyToken(TokenType.PARENTESIS_CIERRE, tokenList, index)) {
36+
// FIN
37+
result = true;
38+
} else {
39+
tool.showError("Se esperaba ')'", currentRow, console);
40+
}
41+
} else {
42+
tool.showError("Se esperaba valor", currentRow, console);
43+
}
44+
} else {
45+
tool.showError("Se esperaba operador relacional", currentRow, console);
46+
}
47+
} else {
48+
tool.showError("Se esperaba valor", currentRow, console);
49+
}
50+
} else if (tool.isValueToken(tokenList.get(index))) {
51+
index++;
52+
if (tool.isRelationalOperator(tokenList.get(index))) {
53+
index++;
54+
if (tool.isValueToken(tokenList.get(index))) {
55+
// FIN
56+
result = true;
57+
} else {
58+
tool.showError("Se esperaba valor", currentRow, console);
59+
}
60+
} else {
61+
tool.showError("Se esperaba un operador relacional", currentRow, console);
62+
}
63+
} else {
64+
tool.showError("Se esperaba expresión condicional", currentRow, console);
65+
}
66+
return result;
67+
}
68+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package ParserOperations;
2+
public class LoopParser {
3+
4+
}

0 commit comments

Comments
 (0)