ANTLRInputStream input = new ANTLRInputStream(System.in);
CLexer lexer = new CLexer(input);
CommonTokenStream tokens=new CommonTokenStream(lexer);
CParser parser = new CParser(tokens);
ParseTree tree=parser.translationUnit(0);
System.out.println(tree.toStringTree(parser));
我已经从Antlr那里获得了AST,我想以GUI方式看一下AST。但是如何在Java秋千中做到这一点呢?感谢你们。
JFrame frame = new JFrame();
frame.setContentPane( new JScrollPane( new TreeViewer( null, tree ) ) );
frame.setPreferredSize( new Dimension( 800, 600 ) );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible( true );