Skip to content

Commit 9faeacc

Browse files
committed
[UPDATE] Safe Point to refactor code
1 parent b0c2943 commit 9faeacc

File tree

6 files changed

+42
-23
lines changed

6 files changed

+42
-23
lines changed

src/main/java/ParserOperations/ConditionalParser.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,4 @@ public void parseIf(ArrayList<Token> tokenList, int currentRow, JTextArea consol
2828
}
2929
}
3030
}
31-
32-
public void parseAssignment(ArrayList<Token> tokenList, int currentRow, JTextArea console) {
33-
34-
}
35-
36-
public void parseClassDeclaration(ArrayList<Token> tokenList, int currentRow, JTextArea console) {
37-
if (tool.verifyToken(TokenType.CLASS, tokenList)) {
38-
tool.incrementIndex();
39-
if (tool.verifyToken(TokenType.IDENTIFICADOR_CLASE, tokenList)) {
40-
tool.incrementIndex();
41-
if (tool.verifyToken(TokenType.DOS_PUNTOS, tokenList)) {
42-
// Fin del arbol sintáctico
43-
} else {
44-
tool.showError("Se esperaba ':'", currentRow, console);
45-
}
46-
} else {
47-
tool.showError("Se esperaba identificador de clase", currentRow, console);
48-
}
49-
}
50-
}
5131
}

src/main/java/ParserOperations/Parser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ public class Parser {
1212
private Utilities tool;
1313
private ConditionalParser conditionalParser;
1414
private LoopParser loopParser;
15+
private ReservedParser resParser;
1516

1617
public Parser(ArrayList<Token> tokenList, JTextArea console) {
1718
this.tokenList = tokenList;
1819
this.console = console;
1920
tool = new Utilities();
2021
conditionalParser = new ConditionalParser();
2122
loopParser = new LoopParser();
23+
resParser = new ReservedParser();
2224
}
2325

2426
public void parseCode() {
@@ -29,11 +31,10 @@ public void parseCode() {
2931
currentRow = tkn.getRow();
3032
switch (tkn.getToken()) {
3133
case IDENTIFICADOR:
32-
conditionalParser.parseAssignment(tokenList, currentRow, console);
33-
// PENDIENTE
34+
resParser.parseAssignment(tokenList, currentRow, console);
3435
break;
3536
case CLASS:
36-
conditionalParser.parseClassDeclaration(tokenList, currentRow, console);
37+
resParser.parseClassDeclaration(tokenList, currentRow, console);
3738
break;
3839
case IF:
3940
conditionalParser.parseIf(tokenList, currentRow, console);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ParserOperations;
2+
3+
import java.util.ArrayList;
4+
5+
import javax.swing.JTextArea;
6+
7+
import Tokens.Token;
8+
import Tokens.TokenType;
9+
10+
public class ReservedParser {
11+
private Utilities tool;
12+
private ExpressionParser expParser;
13+
14+
public ReservedParser() {
15+
tool = new Utilities();
16+
expParser = new ExpressionParser();
17+
}
18+
19+
public void parseAssignment(ArrayList<Token> tokenList, int currentRow, JTextArea console) {
20+
21+
}
22+
23+
public void parseClassDeclaration(ArrayList<Token> tokenList, int currentRow, JTextArea console) {
24+
if (tool.verifyToken(TokenType.CLASS, tokenList)) {
25+
tool.incrementIndex();
26+
if (tool.verifyToken(TokenType.IDENTIFICADOR_CLASE, tokenList)) {
27+
tool.incrementIndex();
28+
if (tool.verifyToken(TokenType.DOS_PUNTOS, tokenList)) {
29+
// Fin del arbol sintáctico
30+
} else {
31+
tool.showError("Se esperaba ':'", currentRow, console);
32+
}
33+
} else {
34+
tool.showError("Se esperaba identificador de clase", currentRow, console);
35+
}
36+
}
37+
}
38+
}
-494 Bytes
Binary file not shown.
123 Bytes
Binary file not shown.
1.53 KB
Binary file not shown.

0 commit comments

Comments
 (0)