I have this formula:
negationExpr
: NEGATION^* atom
;
atom
: ‘a’..’z’ | ‘A’..’Z’;
With grammer rules above, if I input formula ¬¬a, I would get this tree structure:
¬ being the root node,
¬ being left child; a being right child
However, What I would like to have is:
¬ being the root node,
second ¬ being the only child of the above node
a being the only child of the second ¬
Basically, I wat all the NEGATION sign have only have one child, it is possible? I know we could probabely use “rewrite rule” to restructure the tree, but I dont know how to do this.
Any help or advises is appreciated! Thanks!
Rewrite rules can follow each alternative for your parser rule.
You’ll find that even after your parser grammar is working, you may need to restructure it to generate the correct tree. To address your specific problem, I suggest the following:
This will add a level in the tree for each negation operator. The ^ will create a root for the token immediately following the parentheses and add the result of the next negationExpr rule as the child.