Unit 1.2.2 Applications Generation
- 1 Open and Closed Source
- 2 Utilities
- 3 Translators
- 4 Linkers, Loaders and Libraries
Open and Closed Source
Closed source programs are ones where software is compiled and provided to the user, without revealing the source code. This prevents users altering the code for personal gain or malicious use. It is usually sold commercially, meaning it is thoroughly tested and usually has free support associated with it.
- Source code not available
- Users purchase a license to use the software
- Dedicated help or contact lines
- Adaptive, corrective and perfective maintenance
The source code of open source software is openly available to download. This means anybody is able to modify the code as they wish and help develop the software further. The most well known open source project is Linux, which was the basis for the Android OS. It is often free, however some companies will provide free software but charge a support fee. Open source projects tend to be produced by armies of volunteers, coders and testers. They can lack the polish and thorough testing of closed source programs, which could leave them feeling slightly clunky. However, if there are many people willing to contribute to them, they will receive regular updates and any flaw of one volunteer can be made up by another.
- Source code available
- Users can modify, amend, study or share
- Often large developer base
- Usually free
This means that a lot of the core functionality they need is already available (1) so the company just has to make amendments/additions specific to their system (1) saving time and money (1).
A utility is a relatively small program which has a single purpose, usually involving system maintenance. Examples include Antivirus, Antispam, Firewalls, Backups, Disk Defragmenters, Compressors and File Managers.
(i) -Software that is supplied with a piece of peripheral hardware
-Allows communication between the hardware and the operating system
-Converts commands from one into instructions that the other can carry out
Use: -Allow device to communicate with computer 
(ii) -Software that is loaded permanently in memory
-It checks the system continually for signs of viruses
-Works in the background
-If an indication is found that a virus is present the file is quarantined
-Example: Teacher would use it to check files imported by students for viruses
-keep system virus free
-if a virus found it is deleted / quarantined 
Translators convert source code to object code, whilst detecting errors in the source code.
Programs written in a high level language (such as Python, Basic, C++ or Ruby). These languages allow a halfway house between natural language and machine code - this is easier for development.
- However, the computer cannot run a source file
- It needs to translate it into machine code
Once a program has been converted into machine code it is called an object program, composed of object code. There is a one-to-one relationship between object/machine code and assembly code. Each opcode has a machine and assembly code equivalent. The only exception to this rule is labels, which are created on the fly, as actual locations replace labels in translation.
Interpreters translates and runs a single line/statement of code at a time. An interpreter will report an error when it translates a line that contains an error, and will then stop interpretation and indicate the position of the error. Each time the program is run the interpreter must be present. The program will run slower due to the translation taking up time and some lines being translated many times, for example if they are in a loop. Interpreters are often used in program development so that bugs and errors can be found without compiling the program for each test.
- Whole program not written...
- so may not compile
- Testing needs to be done...
- diagnostics will be more complete
- Individual segments can be run...
- allowing errors to be isolated
- Running will be necessary after very minor changes.
- continual compilation of whole code is very wasteful/time consuming (1 per max 5)
In assembly code, the OPCODE is represented by a mnemonic and the OPERAND is a denary or hex number. An assembler converts a low level program into machine code prior to its execution. It reserves storage for instructions and data, and replaced mnemonic opcodes with machine codes. Symbolic addresses are replaced with numeric addresses, and it creates a symbol table to match labels and addresses. It will also check the syntax and give error diagnostics.
- Takes each assembly instruction
- Checks for syntax errors
- Looks up value of mnemonic from opcode table
- Gives memory addresses labels
- Converts to machine code
- assembly (language) 
- binary notation/executable form
- set of all instructions available
- (instructions operate on) bytes of data dependent on architecture/processor design 
- reserves storage for instructions & data
- replaces mnemonic opcodes by machine codes
- replaces symbolic addresses by numeric addresses
- creates symbol table ...
- ... to match labels & addresses
- checks syntax/gives error diagnostics 
Compilers translate whole high level programs as a unit and create an executable program. This protects the program from malicious use or modification. The compiled program is architecture specific, and during compilation the compiler may report many errors in the source code, some of which may be spurious. During compilation the program is optimised, which will improve its speed and reduce its size. Once the executable is created, the compiler is no longer required.
How a Compiler Works
There are several stages of compilation, as outlined below:
1. Lexical Analysis
- All the comments and whitespace are removed from the program.
- High level code is turned into a series of tokens, using reserved words that the computer is able to pick out.
- A symbol table is created and used to keep track of variables and subroutines.
2. Syntax Analysis
- Checks code is written in a valid syntax
- Compiles a list of errors for user where code does not follow the languages rules
- It produces an abstract syntax tree, which represents the program.
- Semantic analysis is carried out, this is where the compiler checks for logical errors:
- Type mismatch, e.g. attempting to assign a string literal to an integer
- Undeclared variables or accessing an out of scope variable
- Multiple declaration of a single variable in the same scope
- Accessing an array with an out of bounds integer literal
3. Code Generation
- Here, code from the abstract syntax tree is converted into object code.
- Any unnecessary code is removed.
- It looks for any more efficient alternatives to instructions or groups of instructions and replaces them.
Linkers, Loaders and Libraries
Libraries contain pre-written code which can be accessed and run by programs. They allow developers to use pre-written and pre-tested code, that is often designed to handle complex tasks such as graphics or cryptography, which often require a certain level of expert knowledge.They are accessed and used through an Application Programming Interface (API).
Library routines are examples of these pieces or pre-written code.They are pre-compiled and error free, and as such are ready to use, reducing work and time required when programming. They can be used multiple times, and many have been written in a different source language. It allows the programmer to make use of other peoples expertise, meaning you won't end up 'reinventing the wheel' unnecessarily.
The purpose of a linker is to include the code used from any libraries into the final program. They can be either static or dynamic; static linkers incorporate the code directly into the executable, which can dramatically increase its size. Dynamic linkers link to the code only when it is run, as it is stored on the programs computer, thus reducing the size of the executable.
Loaders are a part of the operating system responsible for loading a program and its dependencies (such as dynamically linked libraries) into memory. It handles the addresses when the program is run.
- Used to combine already compiled procedures...
- to produce an executable file
- Deals with external references from the main program to other (pre-compiled) modules
- Copies object code/executable code into...
- primary memory ready for execution
- Deals with addressing anomalies/re-locatable addresses
(1 per -, max 4)