2

A simple Translator

What you will learn in this chapter

  • Grammar of a simple high level language
  • A lexical analyzer for that language
  • A Recursive-descent Parser
  • Intermediate code
  • How to generate code for a target machine?
  • A target virtual machine
  • Need for optimization
  • Simulator for the virtual machine

Key Words

simple, Scanner, parser, RDP, intermediate code, virtual machine, simulator, optimization

In this chapter, we discuss a very simple C-like language called simple and its compiler. Though due to pedagogic necessity the language is kept as simple as possible, it will illustrate all the significant issues of a compiler construction. Concentration will be on exposing the compiler writing steps rather than power of the language being compiled. The language can be extended to some extent, to make it more “practical”.

We shall carry our discussion up to and including code generation. This requires specification of the target language. We have selected to have a simple target language for a virtual machine, VM1. A real-life processor has a highly optimized instruction set, which is not suitable for introducing and illustrating basic ideas. Our virtual machine simulator displays information useful for understanding what is going on inside it while a program is being executed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.14.132