ch 10 programming language translators

Cards (20)

  • Assembly code is a low-level language, with each instruction in assembly code almost always being equivalent to one machine code instruction.
  • The machine code instructions that a particular computer can execute (the instruction set) are completely dependent on its hardware, and therefore each different type of processor will have a different instruction set and a different assembly code.
  • Several lines of low-level code are required to achieve the same result as a single line of high-level code.
  • An assembly code program must be translated into the equivalent machine code, or in an intermediate form called byte code, before it can be executed.
  • The assembler program takes each assembly code instruction and converts it to the 0s and 1s of the corresponding machine code instruction.
  • The input to the assembler is called source code and the output (machine code) the object code.
  • A compiler is a program that translates a high-level language such as Visual Basic, Python, etc. into machine code.
  • The code written by the programmer, the source code, is input as data to the compiler which scans through it several times, each time performing different checks and building up tables of information needed to produce the final object code.
  • Different hardware platforms will require different compilers, since the resulting object code will be hardware specific. For example, Windows and Intel microprocessors comprise one platform, Apple and PowerPC processors another, so separate compilers are required for each.
  • The compiled object code can then be saved and run whenever needed without the presence of the compiler.
  • The interpreter looks at each line of the source program, analyses it and, if it contains no syntax errors, translates it into machine code and runs it.
  • If a interpreter runs a Python program with a runtime error, it will execute the lines up to that point and then crash. However, if there is a syntax error in the program, the interpreter does not attempt to run any of the program until this is fixed.
  • Many languages are not only compiled or only interpreted, but also both.
  • Interpreting each line of code just before executing has become much less common. Most interpreted languages such as Python and Java use an intermediate representation which combines compiling and interpreting. The resulting bytecode is then executed by a bytecode interpreter.
  • An advantage of bytecode is that you can achieve platform independence; any computer that can run Java programs has a Java Virtual Machine (JVM), a piece of software which masks inherent difference between different computer architectures and operating systems. The JVM understands bytecode and converts it into the machine code for that particular computer.
  • It is possible to compile from Python into Java bytecode using the Jython compiler and then use the Java interpreter to interpret and execute it.
  • Compiler adv: The object code can be saved on disk and run whenever required without the need to recompile. Disadv: If an error is discovered in the program, the whole program has to be recompiled.
  • Compiler adv: the object code executes faster than interpreted code.
  • Compiler adv: The object code produced by a compiler can be distributed or executed without having to have the compiler present.
  • Compiler adv: the object code is more secure, as it cannot be read without a great deal of reverse engineering.