[antlr-interest] How an alternative rule can emit code conditionally on the type of the parent node?

Aggelos Biboudis biboudis at gmail.com
Wed Sep 26 04:12:05 PDT 2012


Dear all,

I am using the C grammar with rewrite option on. I would like to know if it
is possible for my alternative rule (after the "->"), to emit code
depending on the type of the parent node. I want to rewrite the token
buffer in-place (following the book for source-to-source translations when
performing slight modifications/instrumentation) only in compound
statements. My intention is to emit a preamble after the first "{" only if
the compound statement originates from a selection, iteration or jump
statement. For example: I would like to rewrite the if (expr) {
statement1;} to if (expr) { my_statement; statement1;}. Is that conditional
rewriting possible, following the token-buffer edit way?

I am using the usual ANSI C
grammar<http://www.antlr.org/grammar/1153358328744/C.g>and following
the definitive ANTLR reference.

Any help appreciated.
Aggelos B.


More information about the antlr-interest mailing list