Reputation: 105037
I am building an AST tree by hand to use with my application. I currently have a lot of data in my program's memory using a standard OO approach, that will use to form an AST.
I was wondering if by chance there are already any frameworks / code generators that could help me with this task.
I am not looking for a compiler compiler. I don't want to define a grammar and have the code generator generate me a parser for it. I intend to instantiate the nodes of the tree by myself, I am only looking for a faster and cheaper way to build the .java files themselves (a plus would be having options for the node's attributes, optional beginVisit()
/ endVisit()
methods, etc).
Upvotes: 2
Views: 2167
Reputation: 105037
This seems to be the answer to the question:
The major goal of MPS is to allow extending languages. This is because every existing language already has a strict language syntax defined, which limits its flexibility.
The problem in extending language syntax is mainly the textual presentation of code. This is especially true if we want to use different language extensions, where each one may have its own syntax.
This naturally leads to the idea of non-textual presentation of program code. A major benefit of this approach is that it eliminates the need for code parsing. Our solution is to have code always maintained in an Abstract Syntax Tree (AST), which consists of nodes with properties, children and references, and fully describes the program code.
At the same time, MPS offers an efficient way to keep writing code in a text-like manner.
In creating a language, you define the rules for code editing and rendering. You can also specify the language type-system and constraints. This allows MPS to verify program code on the fly, and thus makes programming with the new language easy and less error-prone.
MPS uses a generative approach. You can also define generators for their language to transform code in the custom language to compilable code in some conventional language. Currently, MPS is particularly good for, but is not limited to, generating Java code. You can also generate XML, HTML, JavaScript, and more.
Upvotes: 1
Reputation: 6087
I would highly recommend that you take a look at Eclipse's Java Development Tools. It includes a very robust AST framework.
My understanding is that with using this API, you would have access to all attributes of the various types of AST Nodes and you can also create visitors with beginVisit()
and endVisit()
methods.
Upvotes: 4