[antlr-interest] Dynamically decide rule navigation

Christian chwchw at gmx.de
Thu Jan 12 18:21:51 PST 2012


Hi everybody,

I write a C# preprocessor parser that analyzes the token stream and
possibly deletes single tokens (the ones inside an if-directive with a
conditional expression evaluated to false). That is, the parser deletes
token according to the result of the expression. The actual parser
should do its job after the preprocessor parser. Thus, I want to process
the token stream multiple times.

Here is my rule for this use case:

conditional_section[boolean enter]
  : {$enter}? input_section // preserve
  | skipped_section -> // delete
  ;

It looks straightforward to me but ANTLR expects semantic predicates to
be free of side-effects---in my case: to be independent of the rule
parameter that holds the evaluated conditional expression.

Should I take a different approach or is there a way to change only a
little piece of my code in order to reach my goal?

Regards,
Christian


More information about the antlr-interest mailing list