开发者

Can I use eclipse JDT/AST for other programming languages?

开发者 https://www.devze.com 2022-12-13 10:35 出处:网络
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 Tr

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 is org.eclipse.jdt.core.dom in the Eclipse org.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

Can I use eclipse JDT/AST for other programming languages?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号