Compiler Design Unit 1 !!
|1. Compiler Design Syllabus
|2. Write short notes on Compiler elaborating its importance and Types ?
Compiler is a translator program that translates a program written in (HLL) the source program and translate it into an equivalent program in (MLL) the target program. As an important part of a compiler is error showing to the programmer.
1. Cross Compiler that runs on a machine ‘A’ and produces a code for another machine ‘B’. It is capable of creating code for a platform other than the one on which the compiler is running.
2. Source-to-source Compiler or trans compiler or transpiler is a compiler that translates source code written in one programming language into source code of another programming language.
|3. Write Short Notes on Language processing systems in Compiler .
High Level Language – If a program contains #define or #include directives such as #include or #define it is called HLL. They are closer to humans but far from machines. These (#) tags are called pre-processor directives. They direct the pre-processor about what to do.
Pre-Processor – The pre-processor removes all the #include directives by including the files called file inclusion and all the #define directives using macro expansion. It performs file inclusion, augmentation, macro-processing etc.
Assembly Language – Its neither in binary form nor high level. It is an intermediate state that is a combination of machine instructions and some other useful data needed for execution.
Assembler – For every platform (Hardware + OS) we will have a assembler. They are not universal since for each platform we have one. The output of assembler is called object file. Its translates assembly language to machine code.
Interpreter – An interpreter converts high level language into low level machine language, just like a compiler. But they are different in the way they read the input. The Compiler in one go reads the inputs, does the processing and executes the source code whereas the interpreter does the same line by line. Compiler scans the entire program and translates it as a whole into machine code whereas an interpreter translates the program one statement at a time. Interpreted programs are usually slower with respect to compiled ones.
Relocatable Machine Code – It can be loaded at any point and can be run. The address within the program will be in such a way that it will cooperate for the program movement.
Loader/Linker – It converts the relocatable code into absolute code and tries to run the program resulting in a running program or an error message (or sometimes both can happen). Linker loads a variety of object files into a single file to make it executable. Then loader loads it in memory and executes it.
|4. Write short notes on phases of a Compiler .
There are two major phases of compilation, which in turn have many parts. Each of them take input from the output of the previous level and work in a coordinated way.
Analysis Phase – An intermediate representation is created from the give source code :
Intermediate Code Generator
Lexical analyzer divides the program into “tokens”, Syntax analyzer recognizes “sentences” in the program using syntax of language and Semantic analyzer checks static semantics of each construct. Intermediate Code Generator generates “abstract” code.
Synthesis Phase – Equivalent target program is created from the intermediate representation. It has two parts :
Code Optimizer optimizes the abstract code, and final Code Generator translates abstract intermediate code into specific machine instructions.