-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTigerMain.java
More file actions
24 lines (21 loc) · 949 Bytes
/
TigerMain.java
File metadata and controls
24 lines (21 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
import java.io.FileInputStream;
import java.io.InputStream;
public class TigerMain {
public static void main(String[] args) throws Exception {
String inputFile = null;
if ( args.length>0 ) inputFile = args[0];
InputStream is = System.in;
if ( inputFile!=null ) is = new FileInputStream(inputFile);
CharStream reader = CharStreams.fromStream(is);
TigerLLKLexer lexer = new TigerLLKLexer(reader);
CommonTokenStream tokens = new CommonTokenStream(lexer);
TigerLLKParser parser = new TigerLLKParser(tokens);
ParseTree tree = parser.tigerprogram(); // start parse walk at non-terminal tigerprogram
// tigerprogram() calls the production rule specified in the grammar
TigerLLKExtendedVisitor tiger = new TigerLLKExtendedVisitor();
tiger.visit(tree);
System.out.println(tree.toStringTree(parser));
}
}