Professional Documents
Culture Documents
What are the reasons for studying the concepts of programming languages
Reasons for Studying Concepts of Programming Languages
The more languages you gain knowledge of, the better understanding
of
Readability
Ex-Java:
count++
++count
Although the last two statements have slightly different meaning from
each other and from the others, all four have the same meaning when
used as stand-alone expressions.
Orthogonality:
The grammar above only derives assignment statements. It has id and expr
as expression. id is variable A, B, or C. Expression is only addition,
multiplication and parentheses. For the statement
A=B*(A+C)
It is generated by the leftmost derivation as:
<assign> => <id> = <expr>
=> A = <expr>
=> A = <id> * <expr>
=> A = B * <expr>
=> A = B * (<expr>)
=> A = B * (<id> + <expr>)
=> A = B * (A + <expr>)
=> A = B * (A + <id>)
=> A = B * (A + C)
Parse Tree
Parse tree is a representation of syntactical grammars in hierarchical
structure form. Every internal mode of a parse tree is labeled with a
nonterminal symbol; every leaf is labeled with a terminal symbol. Every
sub-tree of a parse tree describes one instance of an abstraction in the
sentence.
If we take above statement, A = B * ( A + C ), below is its parse tree:
<assign>
<id>
=
<expr>
A
<id>
*
<expr>
B
(
<expr>
)
<id>
+
<expr>
A
<id>
C
Ambiguity
Ambiguity happens in parse tree if there are two or more distinct parse tree.
Let say we have below statement:
A=B+C*A
and below grammar for assignment statement:
<assign> ƒ <id> = <expr>
<id> ƒ A | B | C
<expr> ƒ <expr> + <expr>
<expr> * <expr>
(<expr>)
<id>
Therefore, the grammar will produce two distinct parse trees which it cannot
be determined by compiler.
Operator Precedence
The problem in ambiguous grammar can be solved by having separate rule
for addition and multiplication. When they are separated, they are
maintained in higher to lower ordering, respectively in the parse tree. Below
is the new grammar:
<assign> ƒ <id> = <expr>
<id> ƒ A | B | C
<expr> ƒ <expr> + <term>
<term>
<term> ƒ <term> * <factor>
<factor>
<factor> ƒ (<expr>)
<id>
If we use above grammar for A = B + C * A, we get below derivation which
is left most derivation:
<assign> => <id> = <expr>
=> A = <expr>
=> A = <expr> + <term>
=> A = <term> + <term>
=> A = <factor> + <term>
=> A = <id> + <term>
=> A = B + <term>
=> A = B + <term> * <factor>
=> A = B + <factor> * <factor>
=> A = B + <id> * <factor>
=> A = B + C * <factor>
=> A = B + C * <id>
=> A = B + C * A
static binding
When type of the object is determined at compiled time(by the compiler), it is
known as static binding.
If there is any private, final or static method in a class, there is static binding.
Example of static binding
1. class Dog{
2. private void eat(){System.out.println("dog is eating...");}
3.
4. public static void main(String args[]){
5. Dog d1=new Dog();
6. d1.eat();
7. }
8. }
Dynamic binding
When type of the object is determined at run-time, it is known as dynamic binding.
Example of dynamic binding
1. class Animal{
2. void eat(){System.out.println("animal is eating...");}
3. }
4.
5. class Dog extends Animal{
6. void eat(){System.out.println("dog is eating...");}
7.
8. public static void main(String args[]){
9. Animal a=new Dog();
a.eat();
}
}
3. b. Write a note on variables and explain different types of variables
A variable is any property, a characteristic, a number, or a quantity that
increases or decreases over time or can take on different values (as opposed to
constants, such as n, that do not vary) in different situations.
Types of Variable
1. Qualitative Variables.
2. Quantitative Variables.
3. Discrete Variable.
4. Continuous Variable.
5. Dependent Variables.
6. Independent Variables.
7. Background Variable.
8. Moderating Variable.
9. Extraneous Variable.
10.Intervening Variable.
11.Suppressor Variable.
Qualitative Variables
The value of the variable ‘religion’ (Muslim, Hindu, ..,etc.) differs qualitatively; no
ordering of religion is implied. Qualitative variables are sometimes referred to
as categorical variables.
For example, the variable sex has two distinct categories: ‘male’ and ‘female.’
Since the values of this variable are expressed in categories, we refer to this as a
categorical variable.
Similarly, place of residence may be categorized as being urban and rural and thus
is a categorical variable.
Quantitative Variables
The age can take on different values because a person can be 20 years old, 35 years
old, and so on. Likewise, family size is a quantitative variable, because a family
might be comprised of one, two, three members, and so on.
A quantitative variable is one for which the resulting observations are numeric and
thus possesses a natural ordering or ranking.
For example, a household could have three or five children, but not 4.52 children.
Other variables, such as ‘time required to complete an MCQ test’ and ‘waiting
time in a queue in front of a bank counter,’ are examples of a continuous variable.
The time required in the above examples is a continuous variable, which could be,
for example, 1.65 minutes, or it could be 1.6584795214 minutes.
In many research settings, there are two specific classes of variables that need to be
distinguished from one another, independent variable and dependent variable.
Many research studies are aimed at unrevealing and understanding the causes of
underlying phenomena or problems with the ultimate goal of establishing a causal
relationship between them.
In each of the above queries, we have two variables: one independent and one
dependent. In the first example, ‘low intake of food’ is believed to have caused the
‘problem of underweight.’
Similarly, smoking, dividend, and advertisement all are independent variables, and
lung cancer, job satisfaction, and sales are dependent variables.
In general, an independent variable is manipulated by the experimenter or
researcher, and its effects on the dependent variable are measured.
Background Variable
These variables are often related to many independent variables so that they
influence the problem indirectly. Hence they are called background variables.
If the background variables are important to the study, they should be measured.
However, we should try to keep the number of background variables as few as
possible in the interest of the economy.
Moderating Variable
Suppose you are studying the impact of field-based and classroom-based training
on the work performance of the health and family planning workers, you consider
the type of training as the independent variable.
If you are focusing on the relationship between the age of the trainees and work
performance, you might use ‘type of training’ as a moderating variable.
Extraneous Variable
Most studies concern the identification of a single independent variable and the
measurement of its effect on the dependent variable.
But still, several variables might conceivably affect our hypothesized independent-
dependent variable relationship, thereby distorting the study. These variables are
referred to as extraneous variables.
Extraneous variables are not necessarily part of the study. They exert a
confounding effect on the dependent-independent relationship and thus need to be
eliminated or controlled for.
For this purpose, one can construct two crosstables: one for illiterate mothers and
the other for literate mothers. If we find a similar association between work status
and duration of breastfeeding in both the groups of mothers, then we conclude that
the educational level of mothers is not a confounding variable.
Intervening Variable
For example, variables X and Y may be highly correlated, but only because X
causes the third variable, Z, which in turn causes Y. In this case, Z is
the intervening variable.
Thus, motive, job satisfaction, responsibility, behavior, justice are some of the
examples of intervening variables.
Suppressor Variable
In many cases, we have good reasons to believe that the variables of interest have a
relationship within themselves, but our data fail to establish any such relationship.
Some hidden factors may be suppressing the true relationship between the two
original variables.
Thus, for example, low age may pull education up but income down. In contrast, a
high age may pull income up but education down, effectively canceling out the
relationship between education and income unless age is controlled for.
A key advantage of strong data typing is that it enforces a rigorous set of rules to
ensure a certain consistency of results. Further, a compiler can quickly detect an
object being sent a message to which it will not respond, preventing runtime errors.
Other benefits include no runtime penalties for determining types, accelerated
development by detecting errors earlier and better-optimized code from the
compiler.