[antlr-interest] real-life programs

Jim Idle jimi at temporal-wave.com
Thu Feb 7 06:57:49 PST 2008


> -----Original Message-----
> From: Johannes Luber [mailto:jaluber at gmx.de]
 
> Yes, I'm working on a C# grammar myself, so I can say that it is
> possible to parse C#. The only exception is a corner case of the C#
> preprocessor, but the likelyhood of appearing is small, as it can't be
> really abused (although one should check if the corner case actually
> appeared and tell the programmer to rewrite it).
> 
> #ifdef A
> /*
> #else
> */
> #endif
> 
> showcases the problem.

This is not actually an issue. It just needs careful consideration in 
the lexer, which is where the pre-processing must be performed, not in 
the parser. Getting this right has nothing to do with ANTLR per se ;-)

It actually points out though that sometimes you must step away from 
trying to get a grammar to do something that seems difficult or 
impossible. If it does, then there is a good chance that you are missing 
something about the implementation. While the way some other tools such 
as yacc and lex work can guide implementations to different solutions 
than ANTLR does, in general WHERE things are implemented cannot really 
be changed. Hence the C# pre-processor must be implemented in the lexer 
(though a separate pre-processing grammar could also do it with extra 
overhead).

Jim




More information about the antlr-interest mailing list