public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* how to use libcpp (GCC c lexer)
@ 2012-10-09 15:33 Giovanni Gherdovich
  2012-10-09 16:34 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Giovanni Gherdovich @ 2012-10-09 15:33 UTC (permalink / raw)
  To: gcc-help

Hi all.

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?

Cheers,
Giovanni

PS: please CC your reply to me, since I am not a subscriber of gcc-help.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to use libcpp (GCC c lexer)
  2012-10-09 15:33 how to use libcpp (GCC c lexer) Giovanni Gherdovich
@ 2012-10-09 16:34 ` Ian Lance Taylor
  2012-10-09 16:40   ` Giovanni Gherdovich
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2012-10-09 16:34 UTC (permalink / raw)
  To: Giovanni Gherdovich; +Cc: gcc-help

On Tue, Oct 9, 2012 at 8:33 AM, Giovanni Gherdovich
<g.gherdovich@gmail.com> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to use libcpp (GCC c lexer)
  2012-10-09 16:34 ` Ian Lance Taylor
@ 2012-10-09 16:40   ` Giovanni Gherdovich
  0 siblings, 0 replies; 3+ messages in thread
From: Giovanni Gherdovich @ 2012-10-09 16:40 UTC (permalink / raw)
  To: gcc-help; +Cc: Ian Lance Taylor

Hello Ian,

2012/10/9 Ian Lance Taylor <iant@google.com>:
> [...]
> 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

thank you very much for your answer.

Cheers,
Giovanni

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-10-09 16:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-09 15:33 how to use libcpp (GCC c lexer) Giovanni Gherdovich
2012-10-09 16:34 ` Ian Lance Taylor
2012-10-09 16:40   ` Giovanni Gherdovich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).