ANTLR - Remove node from AST -


I am making my first AST. I want to remove '=' from it.

I like something:

  block | | ----------- | Statements Returns | Assignment | | ----- | ----- | Field = value Removal from my grammar file: Pars: block EOF - & gt; Block; Block: (Statement) * (Identifier ';' -> ^ (Block ^ (Statement of Statement *) ^ (Return Identifier?); Statement: Assignment ';' - & gt; Assignment; Assignment: Expression - & gt; ; ^ (Assignment expression); Expression: NAME '=' Identifier;   

So, how can I remove '=' node which is printed in a tree?

By using inline operator ! , which removes nodes from the tree: / P>

  Expression: NAME '='! Identifier;   

Or using the rewriter operator:

  Expression: NAME '=' identifier -> NAME identifier;   

Questions told by respective operators:

Note that in your grammar there is no assignment token if you inject this kind of token If you want to do this, then put it in your token {...} and enter it in the rewrite rule:

  grammar t; option {//. .} Token {assignment; } Statement: Assignment ';' - & gt; Assignments; Expression: NAME '=' identifier - & gt; ^ (Assignment name identifier);    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -