如何在java swing中运行ANTLR GUI?

时间:2014-02-03 17:00:38

标签: java swing antlr4 abstract-syntax-tree antlrworks

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 swing中做到这一点?感谢你们。

1 个答案:

答案 0 :(得分:0)

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 );