1.8 COMPILATION PROCESS (COMPILERS, INTERPRETERS), LINKING AND LOADING, SYNTAX AND SEMANTIC ERRORS, TESTING A PROGRAM

Compilation process (compilers, interpreters)

What is a Compiler?

·       A compiler is a computer program which converts source code written in a high-level language into object code i.e. Low-level machine language. The compiler also makes the object code efficient in terms of execution time and memory space. 

What is the compiling process?

·       Compilation process does the basic translation mechanisms and error detection. Here comes the role of Compilers and Interpreters. Compiler process goes through lexical, syntax, and semantic analysis at the front end, and code generation and optimization at the back-end.

·       Compiler is not a single module, it has multiple modules like Preprocessor, Compiler, Assembler and Linker/loader.

·       Preprocessor: The preprocessor gives input for the Compiler. When we write any c program it generates an intermediate file and gives as input to the compiler.

·       Compiler: It takes an intermediate file from a preprocessor and generates an assembly code.

·       Assembler: It translates assembly language code into machine readable language. The output result of assembler is known as an object file or object code.in memory.

·       Linker/Loader:  When we write our program, we use some library functions. The linker will link those functions to object code and generate an executable file. Loader takes an executable file into the memory and runs them.

·       Interpreter: An interpreter is like Compiler which translates high-level language into low-level machine language. The main difference between both is that the interpreter reads and transforms code line by line. Compiler reads the entire code at once and creates the machine code.

Compiler and Interpreter Comparison

Comparison points

Compiler

Interpreter

Input

It takes entire program at a time

It takes single line at a time of program

Output

It generates intermediate object code

It does not generate intermediate object code

Working mechanism

The compilation is done before execution

Compilation and execution are done simultaneously

Speed

Comparatively faster

Slower

Memory

Required more memory due to object code generation

Required less memory because it does not generate object code

Error

It displays all errors after the compilation so comparatively difficult to detect the errors

It displays each error of each line one by one so easy to correct the errors

Applicable to which programming

C,C++,C#,

PHP,Perl,Python,Ruby, JavaScript

 

Syntax and Semantics

·       Syntax of a particular language is its grammar or structure of the program. They are the rules for what kind of keywords, variables, symbols and control structures etc. you write in the program. Compiler or Interpreter detects syntax errors.

·       Semantics on the other hand refers to the meaning of a sentence. This is nothing but the logic of the program. Even if the program is correct in syntax but logic is incorrect then output will be wrong.

Errors in C program: Following are some examples of types of errors in C programming.

Syntax error

Semantic error

Run time error

Missing parenthesis/missing semicolon

Not a meaningful statement

Divide by zero

Use of non declarative variables

Unwanted result

Open the file which is not created

Testing a program:

·       When you develop the program the first step is analysis, then design then coding and then Testing comes. Testing is an important phase in which errors are detected and corrected. By passing the different values to the program we have to check if we are getting correct output or not. We can test it manually or with a software tool.

0 Comments:

Post a Comment