Contents Introduction Names Variables The Concept of Binding Type Checking Strong Typing Type Equivalence Scope Scope and Lifetime Referencing Environments Named Constants Introduction



Download 396.24 Kb.
Page1/16
Date18.02.2022
Size396.24 Kb.
#58269
  1   2   3   4   5   6   7   8   9   ...   16
13516098

Names, Bindings, Type Checking, and Scopes

Contents

  • Introduction
  • Names
  • Variables
  • The Concept of Binding
  • Type Checking
  • Strong Typing
  • Type Equivalence
  • Scope
  • Scope and Lifetime
  • Referencing Environments
  • Named Constants

Introduction

  • Imperative programming languages are abstractions of von Neumann computer architecture
    • Memory: stores both instruction and data
    • Processor: provides operations modifying the contents of the memory.
  • Variables are the abstraction of memory cells
  • Variables are characterized by attributes
    • To design a type, must consider scope, lifetime, type checking, initialization, and type compatibility

Meaning: number of characters in the string.

Types of length:

(1) limited such as (a) COBOL: maximum 30

(b) FORTRAN 90 : maximum 31

(2) Unlimited such as Ada, C#, and JAVA

Names

A Name is a string of characters used to indentify some entity in a program.



Length

Case Sensitivity

Relation with special character and reserved words

Length

(Ex. variables, formal paramètres, methodes, etc.)

Names

Length

Case Sensitivity

Relation with special character and reserved words

  • Meaning: distinguish between capital letters and small letters.
  • Types: some languages are

  • (1) case sensitive such as C, and Java

    2) not case sensitive such as Ada, and Pascal.


    • Disadvantage of case sensitivity:
        • readability (names that look alike are different)

Reserved Word (RW)
  • Example: RW in Java: if, for, while, return,…..
  • Disadvantage: if the language contains large number of RW then

  • many collisions occur.

    (e.g., COBOL has 300 reserved words!)



    Special Characters(SC)
  • Meaning: Other than letters and digits.
  • Example: In some languages, we use the SC in the name.

  • (1) PHP: all variable names must begin with $.

    (2) Perl: all variable names begin with special characters, which

    specify the variable’s type.


Names

Length

Case Sensitivity

Relation with special character and reserved words

Keywords(KW)
  • Meaning: A keyword is a word that is special only in certain contexts,
  • Example: In Fortran,
        • Real VarName (Real is a data type followed with a name,

        • therefore Real is a keyword).
        • Real = 3.4 (Real is a variable).

Names

Length

Case Sensitivity

Relation with special character and reserved words

Variables



Name
  • Meaning: A variable is a named location in memory that is used to hold a value that can be modified by the program.
  • Attributes:

Address

Value

Type

Lifetime

Scope
  • Name : not all variables have them.

Download 396.24 Kb.

Share with your friends:
  1   2   3   4   5   6   7   8   9   ...   16




The database is protected by copyright ©ininet.org 2024
send message

    Main page