RuntimeError
Published in

RuntimeError

What is the Compiler

Image from pexels.com
  • Introduction to the compiler
  • Types of compilers
  • Compiler architecture

Introduction

Types of Compilers

Classify the compilers according to the stages of the compiler

  1. One-pass compilers
  2. Two-pass compilers
  3. Multi-pass compilers

Classify compilers according to source code and target code.

  1. Cross compilers — These compilers run on some platform and produce code to run on another platform. As an example, the compiler runs on platform X and produces code to run on platform Y. Embedded system developers are using such compilers.
  2. Traditional compilers — We are most familiar with this type of compilers. These compilers transform high-level language source code into machine language source code. GCC compiler transforms these languages into low-level languages that are run on these platforms.
  3. Transpilers — Transpilers transform high-level language source code into another high-level language source code. As an example, the Babel transpiler converts ECMAScript 2015+ into JavaScript.
  4. Decompiler — Decompiler takes low-level source code as the input and attempts to create high-level source code which can be recompiled successfully.

Compiler Architecture

Diagram from Javatpoint.com — https://www.javatpoint.com/compiler-phases

Front End

  • Lexical analyzing
  • Syntax analyzing
  • Semantic analyzing
  • Intermediate code generation

Back End

  • Code optimization
  • Code generation

Lexical analyze

Diagram from http://quex.sourceforge.net

Syntax analyzing (Parsing)

Semantic analyzing

Intermediate code generation

  1. High-level IR — More close to high-level language
  2. Low-level IR — More close to machine code
  • AST — Abstract syntax tree (Graphical)
  • Postfix notation
  • Three address code
  • Two address code

Code optimization

  1. The output code must not, in any way change the meaning of the source code.
  2. Either reduce the time or resources or both
  3. The code optimizing phase will not take a long-time itself and make the whole compiling process slow
  1. Machine-independent optimization
  2. Machine-dependent optimization

Code generations

  • Instructions selection — Which instruction to use
  • Instruction scheduling — In which order the instructions should be ordered
  • Register allocation — Allocate variables into the processor registers
  • Debug data — With debug data code can be debugged

--

--

A Runtime error has occurred. Do you wish to Debug .. ?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store