Skip to main content

Introduction To Compiler Design, What is Compiler, Preprocessor, Assembler, Interpreter, Advantages of Compiler, Loader and Link-Editor

Introduction To The Compiler Design


What is Compiler?

-A compiler is a special program that translates the source code of a programming language into 
machine code, bytecode, or another programming language. The source code is usually written in 
a high-level human-readable language, such as Java or C++.
The computer is an intelligent combination of software and hardware. Hardware is simply a piece 
of mechanical equipment and its functions are being compiled by the relevant software. The 
hardware considers instructions as electronic charge, which is equivalent to the binary language in 
software programming. The binary language has only 0s and 1s. To enlighten, the hardware code 
has to be written in binary format, which is just a series of 0s and 1s. Writing such code would be an 
inconvenient and complicated task for computer programmers, so we write programs in a high-level language, which is convenient for us to comprehend and memorize. These programs are then 
fed into a series of devices and operating system (OS) components to obtain the desired code that 
can be used by the machine. This is known as a language processing system.


Introduction To The Compiler Design
(Image Source - Google Images)


Preprocessor

-The preprocessor includes all header files and also evaluates whether a macro(A macro is a piece 
of code that is given a name. Whenever the name is used, it is replaced by the contents of the 
macro by an interpreter or compiler. The purpose of macros is either to automate the frequency 
used for sequences or to enable more powerful abstraction) is included. It takes source code as 
input and produces modified source code as output. The preprocessor is also known as a macro 
evaluator, processing is optional that is if any language that does not support #include and macros 
processing is not required.


Compiler

- Compiler is a translator program that translates a program written in (HLL) the
source program and translates it to an equivalent program in (MLL) the target program. An 
important part of a compiler is the error that is displayed to the programmer.
The execution of a program written in the HLL programming language basically consists of two 
parts. the source program must first be compiled into an object program. The result object 
program is then loaded into an executed memory.


Assembler

- Programmers found it difficult to write or read programs in machine language.
They begin to use a mnemonic (symbols) for each machine instruction, which they would later use 
translate into machine language.
Such a mnemonic machine language is now called assembly language.
Programs known as assemblers were written to automate the translation of assembly language into machine language.
The input to an assembly program is called a source program, and the output is a machine language 
translation (object program).


Interpreter

-An interpreter is a program that appears to execute a source program as if it 
were machine language


Languages such as BASIC, SNOBOL, and LISP can be translated using interpreters. JAVA also uses 
an interpreter. The process of interpretation can be carried out in the following phases.
  1. Lexical analysis
  2. Syntax analysis
  3. Semantic analysis
  4. Direct Execution


Advantages

- Modification of the user program can be easily performed and implemented as execution proceeds.
The object type denoting multiple can change dynamically.
Debugging a program and finding errors is a simplified task for a program used for interpretation.
The language interpreter makes it machine independent.

Disadvantages

-The Program execution is slower.
Memory consumption is more.



Loader and Link-Editor

- Once the assembler processes an object program, that program must be placed in memory and 
executed. The assembler could put the object program directly into memory and transfer control to it.
Thus causing the program to be executed in machine language. This would waste the kernel by leaving 
the assembler in memory while the user program was running. Also, the programmer would have to re-translate his program with each execution, thus wasting translation time. To overcome these problems 
of wasted translation time and memory. System programmers developed another component called a 
loader "A loader is a program that places programs in memory and prepares them for execution."
It would be more efficient if the subroutines could be translated into object form, and the loader 
could be "relocated" directly behind the user program. The task of adjusting programs so that 
they are not placed in arbitrary central locations is called relocation. Relocation chargers 
perform four functions.


Comments

Popular posts from this blog

Windows Key Shortcuts

List of common keyboard shortcuts that can be used with the Windows key: (Image by - Sharma Guides | Subham232330) 1. Windows Key + D: Show the Desktop 2. Windows Key + E: Open File Explorer 3. Windows Key + I: Open Settings 4. Windows Key + L: Lock the computer 5. Windows Key + R: Open the Run Dialog 6. Windows Key + S: Open the search bar 7. Windows Key + Tab: Open Task View 8. Windows Key + Ctrl + D: Create a new virtual desktop 9. Windows Key + Ctrl + Left or Right arrow: Switch between virtual desktops 10. Windows Key + M: Minimize all windows 11. Windows Key + Shift + M: Undo minimize all windows 12. Windows Key + Up Arrow: Maximize the current window 13. Windows Key + Down Arrow: Minimize the current window 14. Windows Key + Right Arrow: Snap the current window to the right 15. Windows Key + Left Arrow: Snap the current window to the left 16. Windows Key + P: Project to a second screen 17. Windows Key + Home: Minimize all but the active window 18. Windows Key + ...

four methods overload these methods

Write a program in java which has the following classes and methods:  Class : OverloadDemo Methods : test() Declare four methods with the same name “test()” and overload these methods class OverloadDemo{  public void test(){  System.out.println("It's a test method for null.");  }  public void test(int n){  System.out.println("It's a test method for displaying the int value "+n);  }  public void test(double d){  System.out.println("It's a test method for displaying the double value "+d);  }  public void test(String s){  System.out.println("It's a test method for displaying the String "+s);  }  }  class overClass{  public static void main(String[] args) {  OverloadDemo old = new OverloadDemo();  old.test();  old.test(12);  old.test(25.35);  old.test("Subham");  }  } OUTPUT: It's a test method for null. It's a test method for displaying the int value 12 It's a test method for ...

Normalization Types in DBMS

Normalization Types in DBMS First Normal Form (1NF) A relation will be 1NF if it contains an atomic value.  It states that an attribute of a table cannot hold multiple values. It must hold only single-valued attribute. First normal form disallows the multi-valued attribute, composite attribute, and their combinations. Example: Relation EMPLOYEE is not in 1NF because of multi-valued attribute EMP_PHONE. EMPLOYEE table: EMP_ID EMP_NAME EMP_PHONE EMP_STATE 14 John 7272826385, 9064738238 UP 20 Harry 8574783832 Bihar 12 Sam 7390372389, 8589830302 Punjab The decomposition of the EMPLOYEE table into 1NF has been shown below: EMP_ID EMP_NAME EMP_PHONE EMP_STATE 14 John 7272826385 UP 14 John 9064738238 UP 20 Harry 8574783832 Bihar 12 Sam 7390372389 Punjab 12 Sam 8589830302 Punjab Second Normal Form (2NF) In the 2NF, relational must be in 1NF.  In the second normal form, all non-key attributes are fully functional dependent on the primary key  Example: Let's assume, a school can ...