I'm having a trouble about rewrite rule to convert from parsing tree into AST tree in antlr.
Here's my antlr code:
grammar MyGrammar;
options {
output= AST;
ASTLabelType=CommonTree;
backtrack = true;
}
tokens {
NP;
NOUN;
ADJ;
}
//NOUN PHRASE
np : ( (adj)* n+ (adj)* -> ^(ADJ adj)* ^(NOUN n)+ ^(ADJ adj)* )
;
adj : 'adj1'|'adj2';
n : 'noun1';
When I input "adj1 noun1 adj2" , the result of parse tree like this:
But the AST tree after rewrite rule seem not exactly like the parse tree, the adj is double and not in order, like this:
So my question is how can I rewrite rule to have a result like the parsing tree above?