Adding an Antlr4 parse tree to another Antlr4 parse tree -
i need implement generics antlr4. in order this, need able take class and, used, dynamically generate code macro, tokenize code, generate tree, , add new tree original parse tree.
i saw these 2 classes
http://www.antlr.org/api/javatool/org/antlr/v4/runtime/rulecontext.html
http://www.antlr.org/api/javatool/org/antlr/v4/runtime/parserrulecontext.html
however, i'm not sure do, nor sure how use constructor.
parserrulecontext(parserrulecontext parent, int invokingstatenumber)
rulecontext(rulecontext parent, int invokingstate)
specifically, these classes represent new tree, , should pass invokingstate/invokingstatenumber?
apparently easy this
when walking first tree, correctly displays information both files.
public class program { private static parserrulecontext gettree(string file) throws exception { inputstream input = new fileinputstream(file); reader reader = new inputstreamreader(input); antlrinputstream inputstream = new antlrinputstream(reader); javalexer lexer = new javalexer(inputstream); commontokenstream tokens = new commontokenstream(lexer); javaparser parser = new javaparser(tokens); parserrulecontext tree = parser.compilationunit(); // parse return tree; } public static void main(string args[]) throws exception { parserrulecontext tree1 = gettree("e:\\users\\nessy\\ideaprojects\\antlrtest\\src\\in1.java"); parserrulecontext tree2 = gettree("e:\\users\\nessy\\ideaprojects\\antlrtest\\src\\in2.java"); tree1.addchild(tree2); parsetreewalker walker = new parsetreewalker(); // create standard walker javawalker extractor = new javawalker(); walker.walk(extractor, tree1); // initiate walk of tree listener } }
Comments
Post a Comment