[antlr-interest] real-life programs
Johannes Luber
jaluber at gmx.de
Thu Feb 7 03:46:03 PST 2008
Peter Bulychev schrieb:
> Hello.
>
> Thank for answering my previous question. I want to reformulate it more
> generally now. Of course, I can get the answers on some points by
> myself, but if you answer me, it will save my time great and maybe it
> will be useful to somebody else in future.
>
> 1. Is ANTRL suitable to parse real-life programs? For instance, is it
> possible to write a grammar, using which I will be able to parse
> all C# projects from SourceForge? I agree with fact of missing
> some details such as preprocessing directives but I want all files
> to be parsed. Maybe, the grammar should be less strict than the
> programming language.
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.
> 2. Can I modify this grammar to generate AST representations of
> real-life programs?
Yes.
> 3. Is it possible to work with scopes of variables?
Yes.
> I want to "glue
> together" all leaves with the same variable.
You want to turn the tree into a graph then? Not sure if you have to do
it that way. I suppose putting the same reference into the leaves will
suffice and you don't lose information about the original position of
the token.
Johannes
More information about the antlr-interest
mailing list