2011-09-09 04:12:51 +08:00
|
|
|
import org.antlr.v4.runtime.ANTLRFileStream;
|
|
|
|
import org.antlr.v4.runtime.CommonTokenStream;
|
2011-09-09 05:45:05 +08:00
|
|
|
import org.antlr.v4.runtime.ParserRuleContext;
|
|
|
|
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
2011-06-15 08:29:02 +08:00
|
|
|
|
2011-06-29 09:51:39 +08:00
|
|
|
public class TestT {
|
2011-06-15 08:29:02 +08:00
|
|
|
public static void main(String[] args) throws Exception {
|
2011-06-30 02:42:23 +08:00
|
|
|
TLexer t = new TLexer(new ANTLRFileStream(args[0]));
|
|
|
|
CommonTokenStream tokens = new CommonTokenStream(t);
|
2011-09-04 03:52:23 +08:00
|
|
|
// tokens.fill();
|
|
|
|
// for (Object tok : tokens.getTokens()) {
|
|
|
|
// System.out.println(tok);
|
|
|
|
// }
|
2011-06-30 02:42:23 +08:00
|
|
|
TParser p = new TParser(tokens);
|
2011-09-04 03:52:23 +08:00
|
|
|
p.setBuildParseTrees(true);
|
2011-09-09 05:45:05 +08:00
|
|
|
TParser.sContext tree = p.s();
|
|
|
|
System.out.println(tree.toStringTree(p));
|
|
|
|
|
|
|
|
ParseTreeVisitor visitor = new ParseTreeVisitor();
|
|
|
|
TListener listener = new BlankTListener() {
|
|
|
|
public void enterEveryRule(ParserRuleContext ctx) {
|
|
|
|
System.out.println("enter rule "+TParser.ruleNames[ctx.ruleIndex]);
|
|
|
|
}
|
|
|
|
public void exitRule(TParser.sContext ctx) { // specific to rule s
|
|
|
|
System.out.println("exit rule s");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
visitor.visit(listener, tree);
|
2011-06-15 08:29:02 +08:00
|
|
|
}
|
|
|
|
}
|