Skip to content

Commit 69788d0

Browse files
committed
[UPDATE] Change methods and refactor logic
1 parent 45b6b70 commit 69788d0

File tree

12 files changed

+190
-9
lines changed

12 files changed

+190
-9
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class example:
2+
num = 1
3+
# FOR
4+
for i in range(150):
5+
if i % 2 == 0:
6+
print("El valor es: ", i)
7+
8+
# IF
9+
if (num > 0 and num < 10) or (num == 100):
10+
print("Valor correcto :D")
11+
12+
# WHILE
13+
while num != 20:
14+
print("Posición: ", num)
15+
num += 1
16+
17+
# MATCH (SWITCH)
18+
match 400, 404:
19+
case 400, 401:
20+
print("No cumple el segundo valor.")
21+
case 401, 404:
22+
print("No cumple el primer valor.")
23+
case 400, 404:
24+
print("VALORES CORRECTOS.")
25+
case _:
26+
print("Ningun valor cumple.")

src/main/java/Files/TestFiles/prueba2.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@
44
while True:
55
suma2 += contador
66
contador += 1
7-
7+
88
if contador > 10:
99
break
1010

11+
12+
def sum():
13+
print("clase aparte")
14+
15+
16+
def sum2():
17+
print("clase aparte 2")
18+
19+
20+
def sum3():
21+
print("clase aparte 3")
22+
23+
1124
print("La suma total es:", suma2)

src/main/java/ParserOperations/Assignments.java

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,76 @@ public boolean isAssignment() {
1818
}
1919

2020
public boolean isArithmeticOperation() {
21+
if (isExpression() || isTerm()) {
22+
return true;
23+
} else {
24+
return false;
25+
}
26+
}
27+
28+
private boolean isExpression() {
2129
boolean flag = false;
22-
// TO-DO
30+
if (isTerm()) {
31+
tool.incrementIndex();
32+
if (tool.verifyToken(TokenType.SUMA) || tool.verifyToken(TokenType.RESTA)) {
33+
tool.incrementIndex();
34+
if (isExpression()) {
35+
flag = true;
36+
} else if (tool.getIndex() < tool.getTokenList().size() - 1
37+
&& tool.getTokenList().get(tool.getIndex() + 1).getRow() != tool.getCurrentToken().getRow()) {
38+
flag = true;
39+
} else {
40+
tool.showError("Se esperaba una expresión");
41+
}
42+
} else {
43+
tool.showError("Se esperaba operador (+, -)");
44+
}
45+
} else {
46+
tool.showError("Se esperaba termino");
47+
}
48+
return flag;
49+
}
50+
51+
private boolean isTerm() {
52+
boolean flag = false;
53+
if (isFactor()) {
54+
tool.incrementIndex();
55+
if (tool.verifyToken(TokenType.MULTIPLICACION) || tool.verifyToken(TokenType.DIVISION)) {
56+
tool.incrementIndex();
57+
if (isTerm()) {
58+
flag = true;
59+
} else if (tool.getIndex() < tool.getTokenList().size() - 1
60+
&& tool.getTokenList().get(tool.getIndex() + 1).getRow() != tool.getCurrentToken().getRow()) {
61+
flag = true;
62+
} else {
63+
tool.showError("Se esperaba un termino");
64+
}
65+
} else {
66+
tool.showError("Se esperaba operador (*, /)");
67+
}
68+
}
69+
return flag;
70+
}
71+
72+
private boolean isFactor() {
73+
boolean flag = false;
74+
if (tool.verifyToken(TokenType.ENTERO) || tool.verifyToken(TokenType.DECIMAL)) {
75+
flag = true;
76+
} else if (tool.verifyToken(TokenType.IDENTIFICADOR)) {
77+
flag = true;
78+
} else if (tool.verifyToken(TokenType.PARENTESIS_APERTURA)) {
79+
tool.incrementIndex();
80+
if (isExpression()) {
81+
if (tool.verifyToken(TokenType.PARENTESIS_CIERRE)) {
82+
tool.incrementIndex();
83+
flag = true;
84+
} else {
85+
tool.showError("Se esperaba ')");
86+
}
87+
}
88+
} else {
89+
tool.showError("Se esperaba un factor");
90+
}
2391
return flag;
2492
}
2593

@@ -33,7 +101,6 @@ public boolean isValueAssign() {
33101
flag = true;
34102
System.out.println("VARIABLE DECLARADA");
35103
tool.incrementIndex();
36-
37104
} else {
38105
tool.showError("Se esperaba valor");
39106
}
@@ -43,7 +110,6 @@ public boolean isValueAssign() {
43110
System.out.println("VARIABLE AUGASSIGN");
44111
flag = true;
45112
tool.incrementIndex();
46-
47113
} else {
48114
tool.showError("Se esperaba valor");
49115
}
@@ -79,7 +145,6 @@ public boolean isDataCollection() {
79145
tool.showError("Se esperaba ')'");
80146
}
81147
}
82-
83148
} else {
84149
tool.showError("Se esperaba valor");
85150
}
@@ -102,7 +167,6 @@ public boolean isDataCollection() {
102167
tool.showError("Se esperaba '}'");
103168
}
104169
}
105-
106170
} else {
107171
tool.showError("Se esperaba valor");
108172
}

src/main/java/ParserOperations/CompoundStatements.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public boolean isFunctionDef() {
3535
tool.incrementIndex();
3636
if (tool.verifyToken(TokenType.DOS_PUNTOS)) {
3737
tool.incrementIndex();
38+
flag = true;
3839
}
3940
}
4041
}

src/main/java/ParserOperations/ExpressionParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private boolean isSimpleExpression() {
105105
tool.incrementIndex();
106106
result = true;
107107
} else {
108-
tool.showError("Se esperaba ')' - METHOD");
108+
tool.showError("Se esperaba ')'");
109109
return false;
110110
}
111111
} else if (tool.isValueToken(tool.getCurrentToken())) {

src/main/java/ParserOperations/SimpleStatements.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public SimpleStatements() {
1414

1515
public boolean isSimpleStatement() {
1616
tool.setCurrentRow(tool.getCurrentToken().getRow());
17-
if (assigns.isAssignment() || isImportStatement()
17+
if (assigns.isAssignment() || isImportStatement() || isPrint()
1818
|| tool.verifyToken(TokenType.PASS) || tool.verifyToken(TokenType.BREAK)
1919
|| tool.verifyToken(TokenType.CONTINUE)) {
2020
return true;
@@ -23,6 +23,44 @@ public boolean isSimpleStatement() {
2323
}
2424
}
2525

26+
public boolean isPrint() {
27+
boolean flag = false;
28+
if (tool.verifyToken(TokenType.PRINT)) {
29+
tool.incrementIndex();
30+
if (tool.verifyToken(TokenType.PARENTESIS_APERTURA)) {
31+
tool.incrementIndex();
32+
if (tool.isValueToken(tool.getCurrentToken())) {
33+
tool.incrementIndex();
34+
if (tool.verifyToken(TokenType.PARENTESIS_CIERRE)) {
35+
flag = true;
36+
tool.incrementIndex();
37+
} else if (tool.verifyToken(TokenType.COMA)) {
38+
tool.incrementIndex();
39+
if (tool.isValueToken(tool.getCurrentToken())) {
40+
tool.incrementIndex();
41+
if (tool.verifyToken(TokenType.PARENTESIS_CIERRE)) {
42+
tool.incrementIndex();
43+
flag = true;
44+
}
45+
tool.showError("Se esperaba ')'");
46+
flag = false;
47+
} else {
48+
tool.showError("Se esperaba ','");
49+
flag = false;
50+
}
51+
} else {
52+
tool.showError("Se esperaba cierre de expresión");
53+
}
54+
} else {
55+
tool.showError("Se esperaba valor");
56+
}
57+
} else {
58+
tool.showError("Se esperaba '('");
59+
}
60+
}
61+
return flag;
62+
}
63+
2664
public boolean isImportStatement() {
2765
boolean flag = false;
2866

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class example:
2+
num = 1
3+
# FOR
4+
for i in range(150):
5+
if i % 2 == 0:
6+
print("El valor es: ", i)
7+
8+
# IF
9+
if (num > 0 and num < 10) or (num == 100):
10+
print("Valor correcto :D")
11+
12+
# WHILE
13+
while num != 20:
14+
print("Posición: ", num)
15+
num += 1
16+
17+
# MATCH (SWITCH)
18+
match 400, 404:
19+
case 400, 401:
20+
print("No cumple el segundo valor.")
21+
case 401, 404:
22+
print("No cumple el primer valor.")
23+
case 400, 404:
24+
print("VALORES CORRECTOS.")
25+
case _:
26+
print("Ningun valor cumple.")

target/classes/Files/TestFiles/prueba2.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@
44
while True:
55
suma2 += contador
66
contador += 1
7-
7+
88
if contador > 10:
99
break
1010

11+
12+
def sum():
13+
print("clase aparte")
14+
15+
16+
def sum2():
17+
print("clase aparte 2")
18+
19+
20+
def sum3():
21+
print("clase aparte 3")
22+
23+
1124
print("La suma total es:", suma2)
1.37 KB
Binary file not shown.
6 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)