[antlr-interest] Context Sensitive Keyword Support?

chris king kingces95 at gmail.com
Thu Feb 17 14:52:29 PST 2011


Jim, thanks! I'll try that. Yes, I'm trying to build a C# antlr grammar.
It's a learning exercise at the moment. I'm hoping to open source it so I
don't want to be peeking at any commercial code but I'd love to pick your
brain! :)

How did you implement the pre-processor? To embed the language grammar in
the pre-processor grammar I created a subclass of a C# TextReader that looks
for lines starting with # and then hands those lines off to a pre-processor
grammar to determine if the block of code should be returned to the language
parser. This way the TextReader is generating only the text that is not
#ifdefed out. I tried to create a unified grammar but failed. Did you manage
to have a unified pre-processor and language grammar?

For my 2c I like Scott's proposal. Build a lexer that generates tokens given
(1) a lexical grammar and (2) the set of possible tokens the parser could
consume. Seems that would be an especially elegant way to embed one grammar
(C#) in another (C# pre-processor) as well the keyword context problem.

Thanks,
Chris


More information about the antlr-interest mailing list