1.0 Introduction

1.1 History

1.2 Characteristics

1.3 Scanner Generators

1.4 Parser Generators

1.5 Semantic Analyzer Generators

1.6 Optimization

1.7 Code Generation

1.8 Summary

Web References

Exercises

Module 1 Exercise Solutions

  1.  
  2. (a)   -  (v)
    (b)   -  (i)
    (c)   -  (iv)
    (d)   -  (iii)
    (e)   -  (vi)
    (f)   -  (ii)
     
  3.  
  4. Scanner:  (Id, "Max")  (Op, ":=")  (Id, "Min")  (Op, "+")  (Lit, 4)  (Op, *)  (Lit, 3)
  5. Parser:

     
    Semantic analyzer:
     
     
    Optimizer:
     
     

    Preparation for code generation

    (Lots of other possibilities)


     

    Code Generation
     
    PushAddr Max
    Push Min
    Load (StackTop, Reg1 Reg1 = Min
    Add #12, Reg1 Reg1 = 12*Min
    Store Reg1, @1(StackTop) Max = Reg1

  6. A := 12 * (Ex + E1/Em)
  7. (a)
  8. (b)
  9. (a)  Token = Basic lexical unit

  10. (b)  Syntax analysis = Parsing
    (c)  Parse tree = Syntax tree
    (d)  Intermediate representation = Intermediate code
    (e)  Abstract syntax tree = Abstract structure tree
    (f)  Analysis Phase = Front end

  11. (a)  Run the X0 program (that takes X programs to M programs) through the X0 compiler (the M program which takes X0 programs to m programs).  The output is M code, but it is m code which takes X programs to M programs.  Thus, we have a program written in M which takes X programs to M programs.  This is an X compiler.

  12. (b)  Take the M program which translates L programs to N code and run the L program which translates L programs to N code through it.  The resulting N code is a program which takes L programs to N code.  This is an L compiler for machine N.