java - delete node in AST base on condition -


i new use antlr. have antlr grammar creates ast. want check if comparisonexpr contains fuzzyexpr want delete comparisonexpr node , conjunction (“and”, “or”) in front of comparisonexpr(if has) ast. please suggest me how it. don’t know can normal rewrite rule of antlr or not?

for example

given input: $gpa = #high , age = 25 want output this: age = 25 (delete conjunction "and" , comparisonexpr=>"$gpa = #high") because has fuzzyexpr=>"#hight") 

this part of grammar.

grammar test; options{ output=ast; astlabeltype=commontree; }  whereclause      :="where" exprsingle; exprsingle       :orexpr; orexpr           :andexpr ("or" andexpr)*; andexpr          :comparisonexpr ("and" comparisonexpr)*; comparisonexpr   :valueexpr((valuecomp)valueexpr)?; valueexpr        :validateexpr                  |pathexpr                   |extensionexpr                   |fuzzyexpr; fuzzyexpr        :"#" literal; 

thank you. pannipa

you can rewrite rules. here's sketch assuming root trees operator:

^(or e1=expr e2=expr)   -> {isfuzzy($e1) && isfuzzy($e2)}? /* empty */  -> {isfuzzy($e1)}?                 $e2  -> {isfuzzy($e2)}?                 $e1  ->                                 ^(or $e1 $e2) ; 

you put semantic predicates in front of tree building statements. first predicate match choose tree written. if nothing matches last 1 used.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -