-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
36 lines (25 loc) · 1.1 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
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.List;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
public class Main {
public static void main(String[] args) throws Exception {
ANTLRInputStream is = new ANTLRInputStream(readFile(new File("input.txt"),Charset.forName("UTF-8")));
controlLexer lexer = new controlLexer(is);
TokenStream tokens = new CommonTokenStream(lexer);
controlParser parser = new controlParser(tokens);
Analyzer a = new Analyzer(parser);
parser.addParseListener(a);
System.out.println(parser.getTokenTypeMap());
controlBaseVisitor visitor = new controlBaseVisitor();
visitor.visit(parser.line());
}
private static String readFile(File file, Charset encoding) throws IOException {
byte[] encoded = Files.readAllBytes(file.toPath());
return new String(encoded, encoding);
}
}