Ok... this is what I want to do.....
- Generate Java classes from some expression language....
- Assume Step#1 is done... I have Java file. I have created JavaLaxer and JavaParser using Java.g file after modifying Java.g little bit (http://jumbleagilemanuals.blogspot.com/2008/03/10-steps-to-beginning-to-parsing-with.html)
- I am using antlr-3.3-complete.jar for obtaining AST tree. Now I have wrote Test class where I am obtaining CommonTree object (see the code below this list)...
- Now I want to convert AST tree to XML output so that I can save it in DB...
- I want to write Reader class which can read XML file and create Java source..
- Use that Java Source to create Object at Runtime...
static final TreeAdaptor adaptor = new CommonTreeAdaptor() {
@Override
public Object create(Token payload) {
CommonTree cTree = new CommonTree();
cTree.token = payload;
return cTree;
}
};
CharStream c = new ANTLRFileStream(
"C:/Documents and Settings/kkk/IBM/rationalsdp/workspace17"+
"/myproject/src/main/java/com/xyz/abc/infrastructure/"+
"email/service/impl/EmailServiceImpl.java");
JavaLexer lexer = new JavaLexer(c);
CommonTokenStream tokens = new CommonTokenStream();
tokens.setTokenSource(lexer);
JavaParser parser = new JavaParser(tokens);
parser.setTreeAdaptor(adaptor);
/* AST tree for my java code */
CommonTree tree = (CommonTree) parser.compilationUnit().getTree();
I am struggling with step-4 to step-6... I couldn't find solution yet!!