This is the stage of TRANSLATION where the program is converted into instructions that the computer can understand.
There will be no errors in the code due to incorrect use of the high level language by the programmer.
Once LEXICAL and SYNTAX analysis have occurred, a table listing all the variables will have been setup:
Noe the memory addresses for the variable are calculated and stored in the SYMBOL table - it happens as the code genarator comes across the first instance of the variable in the program.
INTERMEDIATE code is generated first which is then INTERPRETED immediately or translated into the machine code. The machine code is outputted as an EXECUTABLE file (*.exe in windows, *.app in MacOS and *.bin other *NIX flavours).
Two ways are used to can be used to represent what happens when the high-level language is converted to machine code.
The compiler will optimize the code based on whether speed of execution or size of program is the most important factor. If there is no obvious benefit to the program of either than it will compromise between the two:
Care must be taken - what would happen if value b changed between the evaluation of r2 and r4?
Infact further optimization of the code above could lead to the removal of r4 completely and the line 7 would become
r5 := r2 + 6
Additionally, ALGEBRAIC TRANSFORMATIONS would optimize code :
a := b * 1 >>>> a := b and a := b + 0 >>>> a := b
Certain pieces of code have been written by programmers in the past, for instance the basic input and output routines for the C++ language. It would be silly if every programmer had to re-write the basic screen/printer output routines or the mouse/keyboard input capture routines. LIBRARIES of this code already exist and if the program contains the right instruction, the compiler will find the correct library and insert the correct library subroutines into the program upon compilation.
Import is used in this snippet of JAVA code to tell the compiler to add the basic io (input/output) function to the program that follows.
C++ example,
include standard input/output, maths, graphics, etc.,
import java.io.*;
public class Program
{
A Graphics Illustration Program
#include<stdio.h>
#include<iostream.h>
#include<dos.h>
#include<process.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
//void render(float,float,float, float,float,float, float,float,float,
float,float,float);
void initialize(void);
void firstpage(void);