Professional Documents
Culture Documents
Languages (3 Units)
• Definition
• Int a = 20;
• Int b = 40;
• Char ans = ‘Y’;
• C = a + b;
Sizes of fundamental Types are:
• A declaration specifies the interpretation and
attributes of a set of identifiers.
• A definition of an identifier is a declaration for
that identifier that:
– for an object [variable or constant], causes storage to
be reserved for that object;
– for a function, includes the function body;
– for an enumeration constant, is the (only)declaration
of the identifier;
– for a typedef name, is the first (or only)declaration of
the identifier."
Declaration Models
• Names, variables
• Binding
• Scope
–-Visibility
• Constants. Variable initialization
Names
• A name is a handle on an entity in a
program. We refer to something by a
name if we want to create, use, change,
destroy it.
T[i*2+1] = y;
• •This address depends on the current value of i.
Undefined variables
• In some programming languages, an implicit
declaration is provided the first time such a
variable is encountered at compile time.
• In other languages, such a usage is considered
to be an error, which may resulting in a
diagnostic message.
• Some languages have started out with the
implicit declaration behavior, but as they
matured they provided an option to disable it
(e.g. Perl's "use strict", Visual Basic's use
"Option Explicit").
How to Declare Variables in Java
• To reference a variable in a Java
program, you must first declare it. To
declare a variable, see this,
• main P() {
int X;
void A() {
char Y;
void B() {
float Z;
SB}
SA }
void C() {
int Z;
SC }
SP}
Call graphs
• Show which program units can call other units
• A loop "to itself" indicates possible recursion
• main P() {
int X;
void A() {
char Y;
void B() {
float Z;
SB}
SA }
void C() {
int Z;
SC }
SP}
Visibility, or the referencing environment
• Read U.V as "variable V declared in unit U".
• main P() {
int X;
void A() {
char Y;
void B() {
float Z;
SB}
SA }
void C() {
int Z;
SC }
SP}
Hole-in-scope (hiding):
• the same name is used in an enclosing block
and a nested block
• The visible variables in SP: P.X, P.Y
• The visible variables in SA: P.A.X, P.Y, P.A.Z
• The visible variables in SB: P.X, P.B.Y, P.B.Z
• That is, P.X is visible everywhere in P except in SA, where
P.A.X hides it and itself becomes visible.
• P.Y is visible everywhere in P except in SB, where P.B.Y
hides it and itself becomes visible.
• There is no hole in the scope of P.A.Z or P.B.Z because
they have disjoint areas of visibility
Types of scoping
• •So far we saw static scoping (lexical scoping). It
allows us to determine the use of every variable
in a program statically, without executing it.
– x = float(n) * 3.14;