Programming Languages and Translators Ashima Wadhwa Assistant Professor

  • Slides: 24
Download presentation
Programming Languages and Translators Ashima Wadhwa Assistant Professor (gi. BS)

Programming Languages and Translators Ashima Wadhwa Assistant Professor (gi. BS)

LANGUAGE GENERATIONS Generation Classification 1 st 2 nd 3 rd 4 th 5 th

LANGUAGE GENERATIONS Generation Classification 1 st 2 nd 3 rd 4 th 5 th 6 th Machine languages Assembly languages Procedural languages Application languages (4 GLs) AI techniques, inference languages Neural networks , others….

Programming Languages • A computer program resides in primary memory where it is represented

Programming Languages • A computer program resides in primary memory where it is represented as a set of machine instructions which in turn are represented as sequences of binary digits. • At any point in time the computer is said to be in a particular state. • A central feature of the state is the instruction pointer which points to the next machine instruction to be executed. • The execution sequence of a group of machine instructions is known as the flow of control.

EVOLUTION To write a program for a computer, we must use a computer language.

EVOLUTION To write a program for a computer, we must use a computer language. A computer language is a set of predefined words that are combined into a program according to predefined rules (syntax). Over the years, computer languages have evolved from machine language to high-level languages.

Machine languages In the earliest days of computers, the only programming languages available were

Machine languages In the earliest days of computers, the only programming languages available were machine languages. Each computer had its own machine language, which was made of streams of 0 s and 1 s.

A machine’s own language • For understanding how computers work, we need familiarity with

A machine’s own language • For understanding how computers work, we need familiarity with the computer’s own language (called “machine language”) • It’s LOW-LEVEL language (very detailed) • It is specific to a machine’s “architecture” • It is a language “spoken” using voltages • Humans represent it with zeros and ones

Example of machinelanguage Here’s what a program-fragment looks like: 10100001 10111100 10010011 000001000 00000011

Example of machinelanguage Here’s what a program-fragment looks like: 10100001 10111100 10010011 000001000 00000011 00000101 11000000 10010011 000001000 10100011 11000000 10010100 00001000 It means: z = x + y;

Assembly languages The next evolution in programming came with the idea of replacing binary

Assembly languages The next evolution in programming came with the idea of replacing binary code for instruction and addresses with symbols or mnemonics. Because they used symbols, these languages were first known as symbolic languages. The set of these mnemonic languages were later referred to as assembly languages.

Hence assembly language • There are two key ideas: -- mnemonic opcodes: we use

Hence assembly language • There are two key ideas: -- mnemonic opcodes: we use abbreviations of English language words to denote operations -- symbolic addresses: we invent “meaningful” names for memory storage locations we need • These make machine-language understandable to humans – if they know their machine’s design • Let’s see our example-program, rewritten using actual “assembly language” for Intel’s Pentium

High-level languages Although assembly languages greatly improved programming efficiency, they still required programmers to

High-level languages Although assembly languages greatly improved programming efficiency, they still required programmers to concentrate on the hardware they were using. Working with symbolic languages was also very tedious, because each machine instruction had to be individually coded. The desire to improve programmer efficiency and to change the focus from the computer to the problem being solved led to the development of high-level languages. Over the years, various languages, most notably BASIC, COBOL, Pascal, Ada, C, C++ and Java, were developed.

High-Level Language • Most programming nowdays is done using socalled “high-level” languages (such as

High-Level Language • Most programming nowdays is done using socalled “high-level” languages (such as FORTRAN, BASIC, COBOL, PASCAL, C, C++, JAVA, SCHEME, Lisp, ADA, etc. ) • These languages deliberately “hide” from a programmer many details concerning HOW his problem actually will be solved by the underlying computing machinery

The BASIC language • Some languages allow programmers to forget about the computer completely!

The BASIC language • Some languages allow programmers to forget about the computer completely! • The language can express a computing problem with a few words of English, plus formulas familiar from high-school algebra • EXAMPLE PROBLEM: Compute 4 plus 5

The example in BASIC 1 2 3 4 5 LET X = 4 LET

The example in BASIC 1 2 3 4 5 LET X = 4 LET Y = 5 LET Z = X + Y PRINT X, “+”, Y, “=“, Z END Output: 4+5=9

The object-oriented paradigm deals with active objects instead of passive objects. We encounter many

The object-oriented paradigm deals with active objects instead of passive objects. We encounter many active objects in our daily life: a vehicle, an automatic door, a dishwasher and so on. The action to be performed on these objects are included in the object: the objects need only to receive the appropriate stimulus from outside to perform one of the actions. A file in an object-oriented paradigm can be packed with all the procedures—called methods in the objectoriented paradigm—to be performed by the file: printing, copying, deleting and so on. The program in this paradigm just sends the corresponding request to the object.

Some object-oriented languages q C++ q Java

Some object-oriented languages q C++ q Java

TRANSLATION Programs today are normally written in one of the highlevel languages. To run

TRANSLATION Programs today are normally written in one of the highlevel languages. To run the program on a computer, the program needs to be translated into the machine language of the computer on which it will run. The program in a high-level language is called the source program. The translated program in machine language is called the object program. Two methods are used for translation: compilation and interpretation.

Translation process Compilation and interpretation differ in that the first translates the whole source

Translation process Compilation and interpretation differ in that the first translates the whole source code before executing it, while the second translates and executes the source code a line at a time. Source code translation process

Translation process • lexical analysis is the process of converting a sequence of characters

Translation process • lexical analysis is the process of converting a sequence of characters into a sequence of tokens, i. e. meaningful character strings. • syntax of a computer language is the set of rules that defines the combinations of symbols that are considered to be a correctly structured document or fragment in that language.

ASSEMBLER • To convert the assembly language into machine code. • Translate mnemonic operation

ASSEMBLER • To convert the assembly language into machine code. • Translate mnemonic operation codes to their machine language equivalents. • Assigning machine addresses to symbolic labels.

Working of Assembler • Programmer write a program using a sequence of assemble instructions.

Working of Assembler • Programmer write a program using a sequence of assemble instructions. • This sequence of assembler instructions, known as the source code/source program, then specified to the assembler program when that program is started. • It translates a source code into machine language. • The output of the assembler program is called the object code or object program.

Compilers • Translates high-level language into low-level instructions • High-level language: Source code •

Compilers • Translates high-level language into low-level instructions • High-level language: Source code • Machine-level: Object code • Changes, including bug fixes, require recompiling

Interpreters • Translates source code instructions into machine language and executes it one statement

Interpreters • Translates source code instructions into machine language and executes it one statement at a time • Disadvantages – Longer to execute, particularly bad for loops – Uses more memory • Advantage – Faster testing and code modification • Examples of interpreted languages – Java, BASIC, LISP

Queries?

Queries?