Compiling -- gcc -- Lex & Yacc

Patrick O'Callaghan pocallaghan at gmail.com
Tue Jul 22 20:46:14 UTC 2008


On Tue, 2008-07-22 at 13:38 -0400, William Case wrote:
> Hi;
> 
> I am working my way through the compiling process.  I want to be precise
> about my question so that responders do not waste time on answering the
> wrong question.
> 
> Where can I find/see which preprocessor, lexical analysiser, parser etc.
> the gcc compliler is using in Fedora?  What order are they being used in
> and any other instructions or agruments that are being passed to them by
> gcc (the compiler) besides the original/modified code?

Bill, you seem to have some misconceptions. Although lexical analysis
and parsing are inevitably involved in compilation, it doesn't mean they
are visible as separate processes. In fact the 'gcc' manual says
"Compilation can involve up to four stages: preprocessing, compilation
proper, assembly and linking, always in that order." Note that it
doesn't mention lexing and parsing, since these are subsumed under
"compilation proper".

> I have gone through 'info gcc' but that does not seem to lead to the
> answer of my specific question.  I have read as much as I could
> regarding 'make'.  That didn't seem to have an answer either.  Maybe I
> missed it!

'Make' just calls other programs according to a recipe, some of the
rules for which are built-in. It has nothing specific to do with the
actual mechanics of compiling.

> I know the answers, from reading patches and pieces (cpp, lex and Yacc
> -- I think).

'cpp' is the preprocessor, which handles things like #defines and
#includes. However 'lex' and 'yacc' are *not* the lexical analysis and
parsing phases (in the GNU universe the equivalents are actually 'flex'
and 'bison'). They are tools used some time in the past when the
compiler itself was being written to *generate* a lexical analyzer and
parser. In fact I don't remember offhand if gcc even uses them but I
suspect not (some features of C and C++ syntax make it tricky to handle
with yacc, though it can be done). Even if it does, you won't see them
being invoked when compiling a program.

>  But seeing is believing.  Somewhere (which I can't seem to
> find) there must be a declaration, or official text or manual that says
> for sure that I have a certain version of gcc that definetly calls on
> these specific programs.

"gcc -v prog.c" will show you what's happening in excruciating detail.

Looking at the source code for 'gcc' is an illuminating experience. Note
that it's a very large complex program but patience is rewarded.

poc




More information about the fedora-list mailing list