Languages and Compilers                               (Carol Zander, CSS 343)
=======================

Big Picture:
-----------

             +-----------+                      +----------+
  source --> | front end | --> intermediate --> | back end | --> machine code
  program    +-----------+      language        +----------+
                machine                           machine
              independent                        dependent



Phases of a Compiler:
--------------------

                     stream of chars  (source program)
                            |
                            v                All tokens are described 
                     +------------------+    by regular expressions. 
                  . >| lexical analyzer |    Regular expressions generate 
                 .   +------------------+    regular languages.
                 .          |
                 .   stream of tokens  (Token: a meaningful grouping of chars,
                  .         |               e.g., ==  <=  ]  while  SIZE  ,  )
                   .        v
 +--------+     +------------------------+  All programming languages are
 | symbol |<--->| syntactical/semantical |  described by context-free grammars. 
 | table  |     |   analyzer (parser)    |  Context-free grammars generate
 +--------+     +------------------------+  context-free languages.
        ^                   |
         \        intermediate code  (represented as tree, triple, or quadruple)
          \                 |
           \                v
            \       +----------------+
             +----> |  optimization  |
                    +----------------+
                            |
              improved intermediate code  
                            |
                            v
                    +----------------+
                    | code generator |
                    +----------------+
                            |
                       object code
                            |
                            v
                  +---------------------+
                  | linking and loading |
                  +---------------------+
                            |
                            v
                 executable object program


While the phases looks linear, in a compiler program, the lexical analyzer
and parser phases are really more of a loop. The lexical analyzer keeps
feeding the parser tokens, one at a time, while the parser puts the tokens
together to try to recognize a statement in the language.

