How to run the generated Morpher.java?

Skip to end of metadata
Go to start of metadata

Assuming that you run morph on a grammar G.g and get a generated GMorpher java class, you can use the following example to trigger the GMorpher.

Because morph replies on parse tree, you'll need to get the parse tree from the input grammar G. In addition, instead of using CommonTokenStream, you have to use TokenRewriteStream that morph may need it for doing some rewrite stuff.

Then, you can create a GMorpher instance via its default constructor which loads a TokenRewriteStream object as a parameter. For triggering the GMorpher, you should call the instance from its entry point walk and pass in the parse tree object.

Finally, you can get the rewriting result back from the parse tree which has been modified by morph.

Here is a full example: