English 中文(简体)
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 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

alt text

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签