Defn: compiler - is a translator that translates a source language into a target language.
P#1: Give an example of a compiler and the associated source and target languages.
At the highest level, we can think of compilation consisting of two parts:
source program | V lexical analyzer | V syntactic analyzer | V semantic analyzer | V intermediate code generator | V code generator | V target programWe will discuss some simple code optimization although it is beyond the scope of this course to get into sophistocated code optimization. The source program in this course will be a subset of C and the target program will be for the Interpreter discussed in class.
Our compiler will need auxiliary data structures and functions to handle symbol table and error handling information.
Consider the translation process as it is applied to the following C statement:
taxes = salary * 0.30 + 500;
This translates as follows:
taxes = salary * 0.30 + 500; | V lexical analyzer | V id1 = id2 * 0.30 + 500; | V syntactic analyzer | V = id1 + * 500 id2 0.30 | V semantic analyzer | V = id1 + * (float) 500 id2 0.30 | V intermediate code generator | V mov temp1,0.30 mov ax,id2 mul temp1 add ax,(float)500 mov id1,ax | V MASM 6.11 | V target program (.EXE)P#2: Explain as best you can all of the things the compiler has to do with the following C program.
#include <stdio.h> #if SYS == RH5.1 #define LIB "rh51.h" #elif SYS == RH6.0 #define LIB "rh60.h" #else #define LIB "rh62.h" #endif #include LIB #define MAX(x,y) ((x) > (y) ? (x) : (y)) main () { int i = 3, j = 7; printf ("%d",MAX(i,j)); }