Can I use eclipse JDT/AST for other programming languages?
Can I use the AST / JDT for other languages? For example to write my own parser for C# that uses somehow the 开发者_JAVA技巧AST technology?
If you look at the article "Eclipse JDT - Abstract Syntax Tree (AST) and the Java Model - Tutorial", JDT and its AST are tailored for Java.
The Eclipse Java Development Tools (JDT) provide APIs to access and manipulate Java source code.
The AST is a detailed tree representation of Java source code. The AST defines API to modify, create, read and delete source code.
The package for AST isorg.eclipse.jdt.core.dom
in the Eclipseorg.eclipse.jdt.core
plugin.
Other AST exists for other languages, and for generating your own, you could use XText
alt text http://www.eclipse.org/Xtext/images/screenshot-title.png
But the one in a jdt package is speicialized for Java.
It can be viewed through an ASTView
See also the Exploring Eclipse's ASTParser article as another illustration of the Java-oriented aspect of eclipse AST manipulations.
You can not use JDT for other languages(unless you define an embedded grammar, see comments from Mark), it is for Java only as its name indicates. If you want to build a parser for C#, antlr is a nice tool which can give you a visible tree after feeding in the grammar. Here is a grammar used in Antlr for C#.
you May use ANTLR(ANother Tool for Language Recognition) it is a very powerful that generates lexer and parser out from your grammar file. the good news is that you will find open source grammar files available on github. https://www.antlr.org/ https://github.com/antlr/grammars-v4
You will need to create your own AST model.
精彩评论