How a compiler works

When compiling, the compiler goes through three main stages to turn the source code into object/machine code. Each stage is described further on.

• Stage 1 - Lexical Analysis (divides the input file into separated strings)
• Stage 2 - Syntax Analysis (recognizes tokens and creates symbol tables)
• Stage 3 - Code Generation (creates the output program)


How DC3 compiler works


In order to compile complex programs DC3 uses a parser created with
GOLD Parser Builder. This program accepts in input a BNF sintax (see the GOLD Parser Site for documentation) and creates a VB6 scheleton module that can parse (Step 1 and the base of Step 2 above) the code and find sintax errors. Then I've modified the generated parser to make a more complex compiler with functions, subs, global and local variables, recursion, etc...

DC3 BNF grammar is defined in the file 'dc3.grm' and the compiled grammar (that is loaded by GOLD Parser Builder) is defined in the file 'dc3.cgt'.
Copyright 2005 by Lorenzi Davide, created using Dynamic HTML Editor
Introduction