Skip to content

Commit

Permalink
Execute file with python file as argument
Browse files Browse the repository at this point in the history
You must call the file with

```
java -cp lib/antlr-4.13.1-complete.jar:out Main <file.py>
```
  • Loading branch information
boozec committed Jun 27, 2024
1 parent 54b2c77 commit a6343cc
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,28 @@
public class Main {

public static void main(String[] args) {
if (args.length != 1) {
System.err
.println(
"You must execute this program with a file parameter.\nUsage: java -cp lib/antlr-4.13.1-complete.jar:out Main <file.py>");
return;
}

// for (File file : Objects.requireNonNull(new File("./progs/").listFiles())) {
try {
// String fileStr = file.getPath();
// FIXME: use the fileStr above
String fileStr = "./progs/test.py";
String fileStr = args[0];
System.out.println(fileStr);
System.out.println(readFile(fileStr));
CharStream cs = CharStreams.fromFileName(fileStr);
Python3Lexer lexer = new Python3Lexer(cs);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Python3Parser parser = new Python3Parser(tokens);
Python3Parser.RootContext tree = parser.root();
// DEBUG
// {
// tokens.fill();
// for (Token token : tokens.getTokens()) {
// System.out.println(token.toString());
// }
//
// System.out.println("Tree: " + tree);
// }

JFrame frame = new JFrame("Parse Tree");
JPanel panel = new JPanel();
TreeViewer viewer = new TreeViewer(Arrays.asList(parser.getRuleNames()),
tree);
viewer.setScale(1.5); // Zoom factor
viewer.setScale(1.5);
panel.add(viewer);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Expand Down Expand Up @@ -71,7 +66,6 @@ public static void main(String[] args) {
} catch (Exception e) {
e.printStackTrace();
}
// }
}

private static String readFile(String filePath) throws IOException {
Expand Down

0 comments on commit a6343cc

Please sign in to comment.