Programming Language and Compiler Design Session
Programming Language and Compiler Design Session
Compiler Design
L.Ramkumar
What Is A Programming Language?
A tool for instructing machines
A means of communicating between
programmers
A vehicle for expressing high-level designs
A notation for algorithms
A way of expressing relationships between
concepts
A tool for experimentation
A means for controlling computerized
devices
Levels
Gross distinction between
programming language
Based on readability
Based on independence
Based on purpose (specific … general)
Levels
Machine level language
Assembly level language
High-level language (3GL)
Sometimes 4GL - fourth generation
language
Machine Level
00000010101111001010
00000010101111001000
00000011001110101000
Programs in machine language are
usually unintelligible at the lowest level,
the most detailed level, since they
consists only of 0’s and 1’s
Assembly Language
Assembly language is a variant of
machine language in which names
and symbols take the place of the
actual codes for machine operations,
values, and storage locations, making
individual instructions more readable.
Individual instructions in assembly
language are readable, but limitations
of the underlying machine can lead to
convoluted programs.
Basic Concepts of a RAM machine
Memory: addresses, contents
Program: instructions
Input/output: (files)
Program –
A random access machine
Input
1. M[0] :=0
2. Read (M[1])
3. If M[1] ≥ 0 then goto 5
4. Goto 7
5. M[3] := M[0] – M[1]
Control 6. If M[3] ≥ 0 then goto 16
7. Writeln (M[1])
8. Read (M[2])
9. M[3] := M[2] – M[1]
10. If M[3] ≥ 0 then goto 12
11. Goto 14
12. M[3] := M[1] – M[2]
13. If M[3] ≥ 0 then goto 8
Output
14. M[1] := M[2] – M[0]
15. Goto 3
16. halt
0 1
Memory
High Level
Readable familiar notations
Machine independence
Availability of program libraries
Consistency check (check data types
Example : Originally written in assembly
language, the unix operating system kernel
was rewritten in the programming language C
in 1973. Ritche [1978] recounts the resulting
benefits
likes(sam,Food) :-
indian(Food),
mild(Food).
likes(sam,Food) :-
chinese(Food).
likes(sam,Food) :-
italian(Food).
likes(sam,chips).
indian(curry).
indian(dahl).
indian(tandoori).
indian(kurma).
mild(dahl).
mild(tandoori).
mild(kurma).
chinese(chow_mein).
chinese(chop_suey).
chinese(sweet_and_sour).
italian(pizza).
italian(spaghetti).
Choice of Language
The choice of programming language
depends in part on the programming
to be done, and in part on external
factors, such as availability, support
and training
Language Implementation
Compiler - source code it translated
into machine code (all at once)
Source code is portable – compiled code
is NOT portable
Interpreter - machine is brought up
to the language (one statement at a
time
Source code is portable; executable on
any computer (that has an interpreter
for that language)
Mixed mode:
Compiled to an intermediate code (p-
code)
P-code is then interpreted
Machine Machine
Loader codes
code (exe)
Source code language is brought down
to the machine language of that
specific computer
Interpreted Code
Each instruction is interpreted by
machine interpreter
Does not produce object code