2012-10-12 11:23:15 +08:00
|
|
|
import org.antlr.v4.runtime.ANTLRInputStream;
|
2012-02-27 14:07:45 +08:00
|
|
|
import org.antlr.v4.runtime.CharStream;
|
2012-07-01 07:40:16 +08:00
|
|
|
import org.antlr.v4.runtime.CommonTokenFactory;
|
2011-11-29 11:16:45 +08:00
|
|
|
import org.antlr.v4.runtime.CommonTokenStream;
|
2012-07-22 07:27:00 +08:00
|
|
|
import org.antlr.v4.runtime.DiagnosticErrorListener;
|
2012-07-15 07:32:04 +08:00
|
|
|
import org.antlr.v4.runtime.ParserRuleContext;
|
2012-06-18 07:56:26 +08:00
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.InputStream;
|
2011-10-21 11:12:32 +08:00
|
|
|
|
2011-10-22 02:58:00 +08:00
|
|
|
public class TestT {
|
2012-07-01 07:40:16 +08:00
|
|
|
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);
|
|
|
|
}
|
2012-10-12 11:23:15 +08:00
|
|
|
CharStream input = new ANTLRInputStream(is);
|
2012-06-18 07:56:26 +08:00
|
|
|
|
2012-07-01 07:40:16 +08:00
|
|
|
TLexer lex = new TLexer(input);
|
|
|
|
lex.setTokenFactory(new CommonTokenFactory(true));
|
2012-06-18 07:56:26 +08:00
|
|
|
|
2012-07-01 07:40:16 +08:00
|
|
|
CommonTokenStream tokens = new CommonTokenStream(lex);
|
|
|
|
TParser parser = new TParser(tokens);
|
|
|
|
|
2012-07-22 07:27:00 +08:00
|
|
|
parser.addErrorListener(new DiagnosticErrorListener());
|
2012-07-15 07:32:04 +08:00
|
|
|
|
2012-08-28 02:25:54 +08:00
|
|
|
// parser.getInterpreter().setSLL(true);
|
|
|
|
// parser.setTrace(true);
|
2012-08-04 09:12:52 +08:00
|
|
|
|
2012-10-12 11:23:15 +08:00
|
|
|
ParserRuleContext tree = parser.s();
|
2012-07-30 00:49:35 +08:00
|
|
|
System.out.println(tree.toStringTree(parser));
|
2012-07-22 07:27:00 +08:00
|
|
|
// tree.save(parser, "/tmp/t.ps");
|
2012-07-01 07:40:16 +08:00
|
|
|
}
|
2011-06-15 08:29:02 +08:00
|
|
|
}
|