summaryrefslogtreecommitdiff
path: root/src/Main.java
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-06-30 13:45:57 +0200
committerGitHub <noreply@github.com>2024-06-30 13:45:57 +0200
commit8aa8b5834953cab15c0687608f4fafea2e6c61be (patch)
tree1835ae7c789136b4a6c44c12efd4247a0b96d893 /src/Main.java
parent7125bb27fedaafd5a56b5122e4251b182448ddac (diff)
parent06d7c8dee25c065b1a569337f34d3cd5e892a31d (diff)
Merge pull request #10 from boozec/check-semantics
Co-Authored-By: geno <gabriele.genovese2@studio.unibo.it> Co-Authored-By: L0P0P <grassoemanuele@live.com>
Diffstat (limited to 'src/Main.java')
-rw-r--r--src/Main.java26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/Main.java b/src/Main.java
index afad5b1..f53b410 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,6 +1,4 @@
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
+
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.*;
@@ -11,6 +9,7 @@ import ast.*;
import ast.nodes.*;
import parser.*;
import semanticanalysis.*;
+import semanticanalysis.Share;
public class Main {
@@ -25,7 +24,7 @@ public class Main {
try {
String fileStr = args[0];
System.out.println(fileStr);
- System.out.println(readFile(fileStr));
+ System.out.println(Share.readFile(fileStr));
CharStream cs = CharStreams.fromFileName(fileStr);
Python3Lexer lexer = new Python3Lexer(cs);
CommonTokenStream tokens = new CommonTokenStream(lexer);
@@ -36,7 +35,7 @@ public class Main {
JPanel panel = new JPanel();
TreeViewer viewer = new TreeViewer(Arrays.asList(parser.getRuleNames()),
tree);
- viewer.setScale(1.5);
+ viewer.setScale(1); // Zoom factor
panel.add(viewer);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -53,9 +52,10 @@ public class Main {
Python3VisitorImpl visitor = new Python3VisitorImpl();
SymbolTable ST = new SymbolTable();
Node ast = visitor.visit(tree);
- ArrayList<SemanticError> errors = ast.checkSemantics(ST, 0);
- if (errors.size() > 0) {
- System.out.println("You had: " + errors.size() + " errors:");
+ ArrayList<SemanticError> errorsWithDup = ast.checkSemantics(ST, 0);
+ ArrayList<SemanticError> errors = Share.removeDuplicates(errorsWithDup);
+ if (!errors.isEmpty()) {
+ System.out.println("You had " + errors.size() + " errors:");
for (SemanticError e : errors) {
System.out.println("\t" + e);
}
@@ -68,14 +68,4 @@ public class Main {
}
}
- private static String readFile(String filePath) throws IOException {
- StringBuilder content = new StringBuilder();
- try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
- String line;
- while ((line = reader.readLine()) != null) {
- content.append(line).append("\n");
- }
- }
- return content.toString();
- }
}