2011-10-12 08:16:29 +08:00
|
|
|
import org.antlr.v4.runtime.ANTLRFileStream;
|
|
|
|
import org.antlr.v4.runtime.CommonTokenStream;
|
|
|
|
import org.antlr.v4.runtime.ParserRuleContext;
|
2011-09-09 08:52:30 +08:00
|
|
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
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-10-12 08:16:29 +08:00
|
|
|
p.setBuildParseTree(true);
|
2011-09-09 05:45:05 +08:00
|
|
|
TParser.sContext tree = p.s();
|
2011-09-12 08:20:42 +08:00
|
|
|
|
2011-09-09 05:45:05 +08:00
|
|
|
System.out.println(tree.toStringTree(p));
|
|
|
|
|
2011-09-09 08:52:30 +08:00
|
|
|
ParseTreeWalker walker = new ParseTreeWalker();
|
2011-09-09 05:45:05 +08:00
|
|
|
TListener listener = new BlankTListener() {
|
|
|
|
public void enterEveryRule(ParserRuleContext ctx) {
|
|
|
|
System.out.println("enter rule "+TParser.ruleNames[ctx.ruleIndex]);
|
|
|
|
}
|
2011-09-12 08:20:42 +08:00
|
|
|
public void exitRule(TParser.DoIfContext ctx) { // specific to rule ifstat
|
|
|
|
System.out.println("exit rule ifstat");
|
2011-09-09 05:45:05 +08:00
|
|
|
}
|
|
|
|
};
|
2011-09-09 08:52:30 +08:00
|
|
|
walker.walk(listener, tree);
|
2011-06-15 08:29:02 +08:00
|
|
|
}
|
|
|
|
}
|