On Tue, Oct 9, 2012 at 8:33 AM, Giovanni Gherdovich <g.gherdovich@xxxxxxxxx> wrote: > > Is anybody familiar with the GCC lexer, locate at libcpp/lex.c in the > GCC source tree? > http://gcc.gnu.org/viewcvs/trunk/libcpp/ > http://gcc.gnu.org/onlinedocs/cppinternals/Lexer.html#Lexer > > I'd like to do lexical analysis on some C source code for educational purposes, > but I am having troubles in finding entry points to the libcpp library. > > As I read at http://gcc.gnu.org/onlinedocs/cppinternals/Lexer.html#Lexer , > cpp_get_token() should be the main API call, defined at libcpp/macro.c , > but I can't locate client code in GCC sources (which is, where the > lexer is called), > nor testcases that could illustrate me, for instance, > how to cook the input to get it into a cpp_reader struct > (the type required for cpp_get_token()'s input). > > So: what's the entry point to libcpp? Where do I find examples of calls, if any? In current mainline, the main call from gcc to libcpp is in gcc/c-family/c-lex.c, which calls cpp_get_token and cpp_get_token_with_location. The cpp_reader is set up by the call to cpp_create_reader in c_common_init_options in c-family/c-opts.c. Ian