You are on page 1of 7

PPL ASSIGNMENT -1

ANVITH PENDEKATLA
20MCME17

1)
Binding Time:
It is the time at which (entities) components of the program such as variables,
operators, control structures are associated with their respective
attributes/characteristics (For example, in the case of variables, the
characteristics are name, size, legal values, location etc)

There are 4 types of Binding Times:


- Language Definition Time
- Language Implementation Time
- Compile Time
- Runtime

Language Implementation Binding Time:


Arithmetic Operations heavily depend on the underlying architecture of
the particular machine the person is using. (16-bit architecture, 32-bit,
64-bit). Therefore, when the architecture changes, the implementation
of the arithmetic operation changes too. Language Implementation
Binding Time gives the user the freedom to make use of the
programming language in their own environment without having to
follow rules set by the programming language. It is the fixation of
implementation constants such as numeric precision, run-time memory
sizes, max identifier name length, number and types of built-in
exceptions and many more.

Importance of Language Implementation Binding Time:


As explained in the above paragraph, the implementation of the programming
language depends on the environment on which the machine is running. The
compiler is written in such a way that any machine in its own environment can
implement the programming language.
For Example, considering C-language, in a 16-bit machine, the size of int is 2
bytes. But in a 32-bit machine, the size of int is 4 bytes. Therefore, there is a
PPL ASSIGNMENT -1
ANVITH PENDEKATLA
20MCME17
huge difference in the storage allocation method for a variable. For the very
same reason, all the computations (arithmetic) will differ. Hence, the compiler
has to know the exact size of the integer variable. Language implementation
time allows us to make use of the language in our own machine-environment.
Hence, it is very necessary to write Language Implementation Binding Time.
It also takes care of:
- Run-time exceptions (Arithmetic Overflow)
- Coupling of I/O operations to the OS file implementation
- Precision of bits (primitive data types)

Compile Time vs Language Implementation Binding Time:


Language Implementation Binding Time occurs at the time of design of the
compiler since each compiler might have to aim at a different environment of a
machine using the Language Implementation Binding Time. Whereas Compile
Time occurs during the compilation of the program itself. Each time when a
program is compiled, Compile Time occurs.
For example, in C, let us consider struct.
- The legal values of the fields of the struct are checked at Compile
Time.

- The memory allocation for all the fields of the struct can be a
continuous chunk in the memory or scattered in different locations.
This can be done in Language Implementation Binding Time.

Let us now consider int a; (in C):


Language implementation time bindings:
- Size of the variable a (Storage allocation) depending on the
environment of the machine

- Runtime exceptions like arithmetic overflow involved in operations of


the variable a
PPL ASSIGNMENT -1
ANVITH PENDEKATLA
20MCME17

Language Implementation Time Bindings in other languages (FORTRAN):


- The size of an integer variable is determined at language
implementation time (Similar to C)

- Floating point representation is determined at language


implementation time

2)
(Please refer to the file “q2.c” to access the short programs. It contains the below-
mentioned EXAMPLES in the short program, describing each operator.)

Left-to-Right Operators:
i) Basic Arithmetic Operations such as Remainder(%), Quotient in
particular follow left-to-right associativity :

In EXAMPLE-1 of q2.c file, we have considered 3 numbers "a" , "b"


and “c”. To prove that the order left-to-right is effective I executed
a%b/c without any brackets. Since same precedence operators
together, it is executed left to right and the answer is (a%b)/c, thus
supporting the fact that they are left-to-right operators .

ii) Relational Operators such as greater than(>), less than(<),equal


to(==), not equal to(!=):

These set of operators compare the left operand with the right one.
They are left-to-right evaluated operators.
In EXAMPLE-2 in q2.c, we have x>y<z. Since it is left-to-right, the
result is going to be (x>y)<z. x=10, y=20, z=30.
x>y is false. Therefore, it returns 0. Now 0<30 is correct. Hence, x>y<z
is true in the given example.
PPL ASSIGNMENT -1
ANVITH PENDEKATLA
20MCME17
iii) Comma - as operator:
It evaluates each of its operands in the left to right order
and returns the value of the last (rightmost) operand.
Therefore, the order in which the operands are is very
important. (Refer EXAMPLE-3) Discards the results of all the
operands from left-to-right except the last one.

Right-to-Left Operators:
i) Unary Operators (+,-,++,--,!,&):

All the unary operators are evaluated right-to-left. Few of them are:
Unary minus, Unary plus, Increment, Decrement, not etc. In the
EXAMPLE-4, few of the unary operators have been used.
d=-++c is the expression. Since right-to-left, first ++c is calculated and
now d = -(++c)

ii) Reassignment Operators (+=, -=, *=, /=):

All the reassignment operators are evaluated right-to-left.


(Refer EXAMPLE-5 to see how it works)
x+=y+=z. First, y+=z is calculated and y = 20+30 = 50. Now x +=y is
calculated and x = 10 + 50 = 60. Hence, (x+=(y+=z)).

iii) Typecasting operation:

Here, we change a variable belonging to one data type to another


one. It is evaluated right to left.
The data type on the left side will get changed to that existing
on the right side.

(Refer EXAMPLE-6)
Generally, int divided by int gives another int (quotient).
PPL ASSIGNMENT -1
ANVITH PENDEKATLA
20MCME17
But to get the average value in decimals, we have typecasted it into
double data type. (right-to-left associativity)

3)
Comma: In C, Comma can be used both as an operator and a separator
depending on the context.

a) Comma as Separator:
It is generally used to declare multiple variables in a single line or pass
multiple arguments to a function and many more. Here the order of the sub-
expressions in the statement is not required. As the name suggests, it simply
separates them and executes them.

b) Comma as Operator:
It evaluates each of its operands in the left to right order and
returns the value of the last (rightmost) operand. (Discards the results of all
the operands except the last one). With the help of Comma operator, we can
assign multiple number of values to a variable. Since it is an operator, we also
have to consider its precedence. The comma operator has the lowest
precedence of all the C operators.

(Please refer to the file “q3.c” to access the short programs. It contains the below-
mentioned EXAMPLES in the short program, describing each example.)

Example-1:
It makes use of Comma purely as a Separator only. In the first line, all the 3
variables x,y,z are declared in the same line with the help of Comma-as a
PPL ASSIGNMENT -1
ANVITH PENDEKATLA
20MCME17
separator. Comma_ is used as a separator in the remaining lines as well
(initialization and printing)

Example-2:
Here comma is used as an Operator. While a is being initialized, we can notice
that multiple values have been assigned to it alone. All the values are
discarded except the last one. It returns the value 1.
(However, we can notice that none of the initial values fed to a are matched
with its data type. (int) It is not illegal because finally we are giving an integer
data type as input and not any other data type. Therefore, it remains
consistent)

Example-3:
Comma is used as both Operator and a Separator in this example. For
declaration in the 1st line, it is used as a separator. While initializing the
variable r, it is used as an operator. Here in this example since the variables
p,q,r are not initialized to any number (Uninitialized Memory), p and q are
initialized to 0 and r gets an unpredictable garbage value to it and it is totally
legal.

4)
In the early 1980s and 1990s as well, Pascal and C was head-to-head in the
competition. They were considered to be perfect rivals and the debate of
which language is superior was used to be there always. Many computer
scientists believed that Pascal is a better language than C. However, after a
certain period of time, C had started to overtake Pascal and finally found its
success in the competition.
The major reason for this is UNIX. C is the base of UNIX and in 80s, 90s UNIX
was in high demand. Therefore, the demand for C was very much there. Not
only UNIX, other operating systems such as Windows was also mainly written
PPL ASSIGNMENT -1
ANVITH PENDEKATLA
20MCME17
in C, thereby causing a very high demand and requirement for this particular
language. Therefore, the commercial use of C made it thrive in the market for
so long and made it a very popular language. Apart from such operating
systems, C was also used in compilers, drivers and many more important areas.
This made many programmers learn C just to keep up with the trend. The same
need/demand was Pascal was however not there during that time.
Programmers were not as motivated to learn and use Pascal to develop their
applications.
The other main reason is the simplicity of C Language. When compared to
Pascal, C was very easy and fun to learn. The syntax of c is very crisp. Pascal’s
syntax on the other hand was verbose and lengthy/complex.
The compilers of Pascal were complicated too. C compilers are simple and
contact!
Pointer arithmetic was not allowed in many versions of Pascal unlike C.

References :
https://softwareengineering.stackexchange.com/questions/114846/why-has-c-prevailed-over-pascal
https://www.quora.com/What-is-the-difference-between-C-and-Pascal

You might also like