home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] Re: Parsing when compiling C - generalized understanding question?

  • Subject: Re: [OCLUG-Tech] Re: Parsing when compiling C - generalized understanding question?
  • From: Martin Hicks <mort [ at ] bork [ dot ] org>
  • Date: Thu, 29 Sep 2005 13:05:17 -0400
On Thu, Sep 29, 2005 at 12:24:45PM -0400, William Case wrote:
> Hi;
> I've done my homework; read the info, RedHat Manuals, googled and
> searched Wikipedia regarding the gcc compiler.  I have gotten most of
> the overview that I wanted.  However, I have one question that wasn't
> answered, or if answered, I missed its importance.
> I am trying to develop an overview understanding of what happens when
> parsing any little C program I have written.  Where would I find the
> rules that the parser uses to translate specific symbols?  For example,
> I would like to see exactly what happens with the "{ }" braces or the
> ";" semi-colon when translated from source code to object code or
> binary.  But my question is not only about those two symbols alone.  I
> would like to be able to go to some source other than the ANSI C
> Standards and see exactly how ANSI C is implemented by the parser (Flex
> and/or Yacc ??).

Wow.  So this isn't just an easy question that someone can answer.  What
happens during parsing of a source language?  Lots.  Far too much to try
to explain, but here's a little summary of stuff you should go look

When you try to parse any kind of grammar ("C" is a language that has a
grammar, as is "english") there has to be a description of that
language.  The normal technique is to use a Context Free Grammar to
break down the bits of the statements into something that can be

The most common way to define a language is by using BNF or EBNF
(Extended Backus Naur Form).

If you *really* want to know more about how compilers work you should:

Read the dragon book
Read o'reilly's Lex and Yacc
Take an undergrad compilers course at university
Read the gcc sources and be prepared to welcome death

> I have a couple of other short dumb questions about compiling. If
> someone is willing to answer them they can email me directly and I will
> send them to you?  I just think they might be boring for the people on
> this list, and embarrassingly stupid for me.  To be honest, most of
> these questions I could probably sort out for myself but I have already
> spent more than a day on getting a compiling overview and a little help
> would be gratefully received.

Ask the list.  If dumb questions get answered once then maybe, just
maybe, the next person who wants to ask the same dumb question will
search the archives first.


Martin Hicks || mort [ at ] bork [ dot ] org || PGP/GnuPG: 0x4C7F2BEE