COMPILATION - IMPLEMENTATION METHODS

  • Programming languages can be implemented by any of three general methods.
  • At one extreme, programs can be translated into machine language, which can be executed directly on the computer.
  • This method is called a compiler implementation and has the advantage of very fast program execution, once the translation process is complete.
  • Most production implementations of languages, such as C, COBOL, C++, and Ada, are by compilers.
  • Language that a compiler translates is called the source language.
  • The process of compilation and program execution takes place in several phases, the most important of which are shown in below Figure.
  • Fig: Compilation Process
  • The lexical analyzer gathers the characters of the source program into lexical units.
  • The lexical units of a program are identifiers, special words, operators, and punctuation symbols.
  • The lexical analyzer ignores comments in the source program because the compiler has no use for them.
  • The syntax analyzer takes the lexical units from the lexical analyzer and uses them to construct hierarchical structures called parse trees.
  • These parse trees represent the syntactic structure of the program.
  • The intermediate code generator produces a program in a different language, at an intermediate level between the source program and the final output of the compiler: the machine language program.
  • Intermediate languages sometimes look very much like assembly languages, and in fact, sometimes are actual assembly languages.
  • The semantic analyzer is an integral part of the intermediate code generator.
  • The semantic analyzer checks for errors, such as type errors, that are difficult, if not impossible, to detect during syntax analysis.
  • Optimization, which improves programs by making them smaller or faster or both, is often an optional part of compilation.
  • Compilers are incapable of doing any significant optimization.
  • This type of compiler would be used in situations where execution speed of the translated program is far less important than compilation speed.
  • An example a computing laboratory for beginning programmers. In most commercial and industrial situations, execution speed is more important than compilation speed, so optimization is routinely desirable.
  • The code generator translates the optimized intermediate code version of the program into an equivalent machine language program.
  • The symbol table serves as a database for the compilation process. The primary contents of the symbol table are the type and attribute information of each user-defined name in the program.
  • This information is placed in the symbol table by the lexical and syntax analyzers and is used by the semantic analyzer and the code generator.
  • The machine language generated by a compiler can be executed directly on the hardware, it must nearly always be run along with some other code.
  • The user and system code together are sometimes called a load module, or executable image.
  • The process of collecting system programs and linking them to user programs is called linking and loading, or sometimes just linking.
  • user programs must often be linked to previously compiled user programs that reside in libraries.
  • The linker not only links a given program to system programs, but also it may link it to other user programs.
  • The speed of the connection between a computer’s memory and its processor usually determines the speed of the computer, because instructions often can be executed faster than they can be moved to the processor for execution.
  • This connection is called the von Neumann bottleneck; it is the primary limiting factor in the speed of von Neumann architecture computers.
  • The von Neumann bottleneck has been one of the primary motivations for the research and development of parallel computers.

Comments