[antlr-interest] Dynamically decide rule navigation

Jim Idle jimi at temporal-wave.com
Thu Jan 12 18:37:59 PST 2012


You cannot create a C# pre-processor as a parser, it must be done directly
in the lexer, as per the language specification. Sorry to disappoint.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Christian
> Sent: Thursday, January 12, 2012 6:22 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Dynamically decide rule navigation
>
> 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
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list