HI, here is where we are going to put a bunch of stuff about getting started. We also have back entries underneath this page.
What is ANTLRMorph?
- Allow programmers to define translators in terms of concrete syntax rewrite rules.
- These rules are independent of the original parser grammar and take the form: "this" -> "that".
- Be able to define rewrite strategy on each morph rule.
How it works?
- ANTLRMorph engine reads in a script in which rewrite rules are defined. The script should follow the morph grammar syntax.
- Morph engine translates the script into a corresponding ANTLR grammar file.
- It also generates a supporting java file which can be used for executing the rewrite task.
How do I use ANTLRMorph?
1. Get ANTLRMorph
Download ANTLRMorph from the wiki download page. Please make sure that you also have ANTLR v3.1 or later jar and StringTemplate 3.2 or later jar in your CLASSPATH.
Try the following command:
If you can see the usage message as below, then you're good to start the next step.
2. Quick start
Generally speaking, there are 2 categories of term rewriting:
- input language conforms to output language, e.g. mathematical expression to mathematical expression.
- input language does not conform to output language, e.g. C to Java.
Both cases are acceptable in Morph, and you can tell morph which type the language is with the syntax:
By default, morph assumes the rewritten result conforms to the input.
Let's start from a very simple mathematical expression grammar:
Before writing a morph script, remember to run ANTLR tool on the input grammar L.g first.
The goal is to simplify an expression when adding/subtracting or multiplying with 0. Here is the morph script for this example (L.morph):
Then, run morph Tool on the script and L_morph.g and LMorpher.java will be generated.
Note that you have to run ANTLR tool with the debug option on the generated grammar.
Finally, let's use a test rig to trigger the morph rewrite task:
Compile all Java files and run the test rig.
Then you should receive the following result:
3. More examples
In the Examples page, Symbolic differentiation is a conforming translation; Property files to xml and Adding Closures to a Java-like language are non-conforming.
Start with Property files to xml, which is a simple not-conform case. After that you can try Symbolic differentiation to see the difference between these two modes.