antlr/tool/playground/TestT.java

31 lines
863 B
Java
Raw Normal View History

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenFactory;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;
2012-06-18 07:56:26 +08:00
import org.antlr.v4.runtime.UnbufferedCharStream;
import java.io.FileInputStream;
import java.io.InputStream;
public class TestT {
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 input = new UnbufferedCharStream(is);
2012-06-18 07:56:26 +08:00
TLexer lex = new TLexer(input);
lex.setTokenFactory(new CommonTokenFactory(true));
2012-06-18 07:56:26 +08:00
CommonTokenStream tokens = new CommonTokenStream(lex);
TParser parser = new TParser(tokens);
ParserRuleContext tree = parser.s();
tree.save(parser, "/tmp/t.ps");
}
}