antlr: How to rewrite only specific

Posted by user1293945 on Stack Overflow See other posts from Stack Overflow or by user1293945
Published on 2012-03-26T23:26:50Z Indexed on 2012/03/26 23:29 UTC
Read the original article Hit count: 144

Filed under:

I am sure antlr can solve my problem, but can't figure out how to implement it, even high level. I rapidly got caught into syntax problems of antlr itself. My grammar is quite simple and made of following tokens and rules. Don't really need to go in their details here. The evaluator resolves to expressions, which finally resolve to IDENT:

evaluator
:   expression EOF!
;
...
...
term
:   PARTICIPANT_TYPE(IDENT  |   '('! expression ')'!    |   max | min   | if_   |   NUMBER)+
;

Now, I would like to analyse and rewrite the 'term', so that IDENT tokens (and them only) get re-written with the PARTICIPANT_TYPE. All the others should simply remain the same.

© Stack Overflow or respective owner

Related posts about antlr3