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

c# - passing input text from view to contoller with FacebookContext using Facebook app -

ios - Does Core Data autoupdate a many to many relationship on saving -

Calling a C++ function from C# by passing a string with variable size to it -