CBSE CS and IP

CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

Language Processors in Python



PYTHON LANGUAGE PROCESSORS


Today, we will tell you to class 11 and class 12 subjects computer science and informatics practices topic a "language processor" in the basics of Python. There are two types of languages in terms of computers. One which is near to the computer is called Low-Level Language and One that is near to human is called High-Level Language
  • High-level language (HLL) - When a programmer writes a program, he uses High-level language.
    Examples of High-Level Language:- C, C++, Java, Python etc.
  • Low-level language (LLL) - Computer understands the program in 0 and 1 binary code called machine language. A High-Level language can not be directly understood by a computer.
    Examples of Low-Level Language:- Machine Language, Assembly Language.
Since Computer understands Machine Language, hence there is a need to convert High-Level Language (Ex:- Python) to Low-Level Language (Ex:- Machine Language). For this purpose, Language Processors are used. 

Language Processors are programs that convert the High-level language (source code) into Low-Level Language (machine code). Language Processors are also called Language Translators

Before going further, you must know the following terms:
  • Language Translator -: A program that transforms a high-level computer language to Machine Language is called a computer Language Translator. 
  • Source Code -: A Source code is a high-level language that is understandable by us, humansThe computer language in which the original Program is written is called Source Language.
  • Object Code -:  An Object Code is a Low-Level Language that is understandable by Computer. The Object Code is also Called Byte Code or Binary Code because it is in binary (0/1) form.
  • Machine Code -: Machine Code is also in binary (0/1) form and is a Low-Level Language. But is different from Object code. It is machine-specific. Linker produces executable machine code on a particular machine using Object Code.
  • Assembly Language-: It is a Low-Level Language. But, it is different from the Object Code or Machine Code. It has the instruct actions in the form of coding, which is converted to Machine language before execution.
    Example of Assembly Language code to add two numbers:-
    mov reg1 , 3
    mov reg2 , 4
    add reg1 , reg2 , reg3

Types of Language Processor / Language Translator

There are three different types of Language Processors or Language Translators:
  1. Assembler
  2. Compiler
  3. Interpreter
Let us now discuss each one by one.

1. What is Assembler?

An Assembler converts "assembly language"  into "Machine language". Assembly language Program has its own syntaxes and can be written by Computer Programmers.

2. What is a Compiler?

A compiler is a translator that converts "source code" (High-Level Language) into "Machine Language" (Low-Level Language) all at once. If there is an error in the Source Code, Nothing will execute.

A compiler is a group of one or more computer programs that transform programs written in the higher-level language into another language (Assembly or Machine Language). The compiler is used in a high-level programming language such as C, C++, java, etc.

C, C++,  java, etc. are High-Level Programming Language, these also need to be translated into machine language so that the computer can understand them. 

Decompiler -:

As the name suggests it is opposite to Compiler. Computer Programs that produce a high-level language program by collocating a low-level computer language program are called Decompiler. 

3. What is an Interpreter?

The interpreter is used for converting a "high-level language" code into "Machine Language" code line by line. If an error occurs in any line, it stops there and does not proceed until that error is corrected. 

An interpreter is a computer program that is used to run instructions written in a programming language code line by line. It translates program line by line at a time. The interpreter is used with programming languages like Python, Ruby, javascript, etc.


Difference Between Compiler & Interpreter




CompilerInterpreter
It converts high-level language code to machine code in one session.It converts high-level language to machine language.
The compiler translates the entire program.The interpreter reads line by line program,
It takes time because it has to translate high-level code into low-level code.It works as a compiler for translating programming code to machine code, but it reads the code line by line and immediately executes it.
The compiler needs more memory than an interpreter.The interpreter needs less memory than the compiler.
It is initially slower than an Interpreter.It is initially faster than a compiler.
Compilers take a large amount of time to analyze the source code.An interpreter analyses the source code in less amount of time.
The overall execution time of the compiler is faster than interpreters.Overall execution time is comparatively slower than interpreters.
Translate the program as a whole-time into machine code.Translate program one statement at a time.
No intermediate object code is generated.Generates an intermediate object code.
If there is an error in the program then it shows in last.If there is an error in any line, first it corrects that error then moves ahead. It Is converting and executing the program line by line.
Debugging in a Compiler is not easy.Debugging in Interpreter is easy.
It is used in a programming language like Python, Javascript, Ruby, etc. It is used in a programming language like C, C++, Java, etc.
Compiled code run fasterInterpreted code run slower.


How does a Compiler & Interpreter work?

Compiler and Interpreter both convert High-Level Language to Low-Level Language. Then you will have questions then what is the difference between interpreter and compiler.

The main difference between compiler and interpreter is that compiler converts High-level language (Source Code) to Low-Level Language (Object Code) at once and the Interpreter converts High-level language (Source Code) to Low-Level Language (Object Code) Line by Line.

The compiler takes the full source code and makes the Binary Code or Object Code at once if there is an error in the program then none of the lines will execute.

In the case of the Interpreter, it takes the source code line by line and converts it into Object code then executes it. For example, if  I have 1000 lines of code and line number 501 is having some syntax error, then all the statements till line number 500 will be executed and the program will give an error at line number 501.

Python Modes

Here we are going to learn about two basic modes of Python:-
  1. Interactive Mode
  2. Script Mode

Interactive Mode -:

  1. Interactive mode is used for running a single line or single block of code.
  2. Interactive mode runs very quickly and gives the output instantly.
  3. Editing the written code is a tough task in interactive mode.

Script Mode  -:

  1. Script mode is used to work with lengthy codes or multiple blocks of code.
  2. Script mode takes more time to compile and run.
  3. Script mode gives flexible editing options.

How to run Python in Interactive Mode

To run Python in interactive mode follow the given steps:
  • Step 1 - Go to Start and search "Python"

    Interactive Mode in Python


  • Step 2 - It will show the installed python black command prompt window. Open it

    Python command prompt window


  • Step 3 - You can now start working on it.

How to run Python in Script Mode

To execute the python program in Script Mode follow the following steps:
  • Step 1 - Go to Start and Search "Python"

    Python Script Mode

  • Step 2- Here you will find IDLE Python with your installed Python version.

    Python script mode.png

  • Step 3 - Now under this IDLE (Integrated Development Environment), you will find the option file. Using this you can create a Python Script (program) and save it with the ".py" extension.

    Python script mode

  • Step 4 - In the same window, there is Option Run. After writing the Full Python Program you can run your program by clicking this menu button. 


No comments:

Post a Comment