Fwd: [antlr-interest] C++ parser usage ideas

Jim Crafton jim.crafton at gmail.com
Thu Oct 13 07:20:17 PDT 2005


Well here's the problem, say you have the following C++ code:

class MY_API Foo {

};


Now somewhere else MY_API is defined as a macro, that uses #defines to
determine whether or not to define it as empty or use the Microsoft
specific __declspec() syntax for exporting a class in a DLL.

However, if the fragment above is parsed as is, it will cause the
parser to throw an exception as it's not syntactically correct. So the
only solution (as I understand it) is to either put logic in the C++
grammar to gracefully skip over macro bits (which is understandably
pretty hard to do), or pre-process it first before passing it over to
the C++ parser.

> "cpp user_file_name temp_file_name extra_cpp_options -nostdinc"
>
> and then I 'system' it (on Unix), and compile the resulting

Keep in mind that I am not compiling anything - I am doing to to be
able to analyze the code a user is writing. Stuff like showing the
classes/methods/members in a tree view, refactoring, etc. So I really
don't want to have to shell out stuff like this if I can avoid it.

> Does the IDE need to know about #include files?
Yes it would. But that would be setup as part of your project anyways,
so it would be that big of a deal.


More information about the antlr-interest mailing list