Translators

Cards (21)

  • For computers to process any computer language , it first needs to be translated
  • In high level languages, (e.g. Python or C++) the source code is easy for humans to write , but computers need to translate it before they can read and run it
  • Low-level languages are tricky for humans to read and write but are easier for a computer to run
  • Low level languages consist of machine code and assembly languages
  • Binary machine code is very tricky for humans to understand
  • Assembly code is more readable for humans and easier to understand
  • In assembly code, ADD is the operation code , and the rest of the code tells you what to perform the operation code on
  • High level languages are popular with programmers
  • The advantages of High-Level Languages are:
    • One instruction of high-level code represents many instructions of machine code  
    • The same code will work for many different machines and processors  
    • The programmer can easily store data in lots of different structures (e.g. lists and arrays)  
    • Code is easy to read , understand and modify  
  • The disadvantages of High-Level Languages are:
    • Must be translated before a computer is able to understand it  
    • You don’t have much control over what the CPU actually does , so programs will be less memory efficient and slower 
  • The advantages of Low-Level Languages are:
    • Commands in machine code can be executed directly without the need for a translator  
    • You control exactly what the CPU does, and how it uses memory , so programs will be more memory efficient and faster 
  • The disadvantages of Low-Level Languages are:
    • One instruction of assembly code usually only represents one instruction of machine code  
    • Usually written for one type of machine or processor , and won’t work on any others  
    • The programmer needs to know about the internal structures of the CPU and how it manages energy  
    • Code is very difficult to read , understand and modify 
  • Computers only understand instructions given to them as machine code - so high level languages need to be translated before a computer is able to execute instructions
  • The 2 types of translator are compilers and interpreters
  • Compilers translate high level code directly into machine code , and create an executable file
  • Interpreters don't translate directly into machine code
  • Interpreters take each instruction in the code and call machine code subroutines within their own code to carry out that instruction
  • Characteristics of a Compiler:
    • Translates all of the source code at the same time and creates one executable file  
    • Only needed once to create the executable file  
    • Returns a list of errors for the entire program once compiling is complete  
    • Once compiled, the program runs quickly , but compiling can take a long time 
  • Characteristics of an Interpreter:
    • Translates and runs the source code one instruction at a time, but doesn't create an executable file  
    • Needed every time you want to run the program  
    • The interpreter will return the first error it finds, and then stops – this is useful for debugging  
    • Programs will run more slowly because the code is being translated as the program is running 
  • The type of translator used will depend on which programming language and IDE you're using
  • If the program is stored over multiple source code files then a linker is used to join all of the separate compiled codes into one executable program