forked from leethater/ADS4_2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
58 lines (49 loc) · 1.32 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main {
private static void initAndShow(String filename) {
JFrame frame = new JFrame("ADS4");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setPreferredSize(new Dimension(800,600));
frame.getContentPane().add(new MyCanvas(filename));
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
initAndShow(args[0]);
}
});
}
}
@SuppressWarnings("serial")
class MyCanvas extends JComponent {
String filename;
public MyCanvas(String fname) {
filename = fname;
}
@Override
public void paintComponent(Graphics g) {
if (g instanceof Graphics2D)
{
Graphics2D g2d = (Graphics2D)g;
File input = new File(filename);
try {
Reader reader = new FileReader(input);
Lexer lexer = new Lexer(reader);
LookAhead1 look = new LookAhead1(lexer);
Parser parser = new Parser(look);
AST ast=parser.progNotTerm();
ast.exec(g2d);
System.out.println("The file is correct");
}
catch (Exception e){
System.out.println("The file is not correct");
System.out.println(e);
}
}
}
}